# HG changeset patch # User Kim Alvefur # Date 1492108181 -7200 # Node ID d0948bd96a7bab854b991c61df236902bf6743e3 # Parent 3fd50495c89df948b98645d3028ae12e22a306f5 mod_http_upload: Add support for limiting file types to upload diff -r 3fd50495c89d -r d0948bd96a7b mod_http_upload/README.markdown --- a/mod_http_upload/README.markdown Thu Apr 13 20:26:24 2017 +0200 +++ b/mod_http_upload/README.markdown Thu Apr 13 20:29:41 2017 +0200 @@ -55,6 +55,14 @@ http_upload_quota = 1234 -- bytes ``` +### File types + +Accepted file types can be limited by MIME type: + +``` lua +http_upload_allowed_file_types = { "image/*", "text/plain" } +``` + Path ---- diff -r 3fd50495c89d -r d0948bd96a7b mod_http_upload/mod_http_upload.lua --- a/mod_http_upload/mod_http_upload.lua Thu Apr 13 20:26:24 2017 +0200 +++ b/mod_http_upload/mod_http_upload.lua Thu Apr 13 20:29:41 2017 +0200 @@ -31,6 +31,7 @@ local file_size_limit = module:get_option_number(module.name .. "_file_size_limit", 1024 * 1024); -- 1 MB local quota = module:get_option_number(module.name .. "_quota"); local max_age = module:get_option_number(module.name .. "_expire_after"); +local allowed_file_types = module:get_option_set(module.name .. "_allowed_file_types"); --- sanity local parser_body_limit = module:context("*"):get_option_number("http_max_content_size", 10*1024*1024); @@ -140,6 +141,13 @@ end end + if allowed_file_types then + if not (allowed_file_types:contains(mimetype) or allowed_file_types:contains(mimetype:gsub("/.*", "/*"))) then + origin.send(st.error_reply(stanza, "cancel", "not-allowed", "File type not allowed")); + return true; + end + end + local reply = st.reply(stanza); reply:tag("slot", { xmlns = xmlns });