diff options
author | Kim Alvefur <zash@zash.se> | 2016-03-03 16:05:34 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2016-03-03 16:05:34 +0100 |
commit | 3140ed3d626e976639ef5f38efb9790008834d9c (patch) | |
tree | 0e5182283ab5973a6cab6ea5667024cdd2f8a80a /plugins/mod_http_files.lua | |
parent | 89d089700746356babbe0af4251a95d9bf23b65e (diff) | |
parent | ae72fdd667dcc0fed977c1d0f20cc052390b6f1d (diff) | |
download | prosody-3140ed3d626e976639ef5f38efb9790008834d9c.tar.gz prosody-3140ed3d626e976639ef5f38efb9790008834d9c.zip |
Merge 0.9->0.10
Diffstat (limited to 'plugins/mod_http_files.lua')
-rw-r--r-- | plugins/mod_http_files.lua | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/plugins/mod_http_files.lua b/plugins/mod_http_files.lua index 0c542714..3b602495 100644 --- a/plugins/mod_http_files.lua +++ b/plugins/mod_http_files.lua @@ -56,6 +56,7 @@ end local urldecode = require "util.http".urldecode; function sanitize_path(path) + if not path then return end local out = {}; local c = 0; @@ -74,6 +75,9 @@ function sanitize_path(path) out[c] = component; end end + if path:sub(-1,-1) == "/" then + out[c+1] = ""; + end return "/"..table.concat(out, "/"); end @@ -88,12 +92,13 @@ function serve(opts) local directory_index = opts.directory_index; local function serve_file(event, path) local request, response = event.request, event.response; - path = sanitize_path(path); - if not path then + local sanitized_path = sanitize_path(path); + if path and not sanitized_path then return 400; end + path = sanitized_path; local orig_path = sanitize_path(request.path); - local full_path = base_path .. (path and "/"..path or ""):gsub("/", path_sep); + local full_path = base_path .. (path or ""):gsub("/", path_sep); local attr = stat(full_path:match("^.*[^\\/]")); -- Strip trailing path separator because Windows if not attr then return 404; |