Diff

plugins/mod_http_file_share.lua @ 11311:9edda2026e57

mod_http_file_share: Add basic access control Partly lifted from mod_external_services
author Kim Alvefur <zash@zash.se>
date Tue, 26 Jan 2021 14:39:11 +0100
parent 11310:d1a0f2e918c0
child 11312:aade4a6179a3
line wrap: on
line diff
--- a/plugins/mod_http_file_share.lua	Tue Jan 26 14:27:51 2021 +0100
+++ b/plugins/mod_http_file_share.lua	Tue Jan 26 14:39:11 2021 +0100
@@ -28,12 +28,18 @@
 local secret = module:get_option_string(module.name.."_secret", require"util.id".long());
 local external_base_url = module:get_option_string(module.name .. "_base_url");
 
+local access = module:get_option_set(module.name .. "_access", {});
+
 if not external_base_url then
 	module:depends("http");
 end
 
 function may_upload(uploader, filename, filesize, filetype) -- > boolean, error
-	-- TODO authz
+	local uploader_host = jid.host(uploader);
+	if not ((access:empty() and prosody.hosts[uploader_host]) or access:contains(uploader) or access:contains(uploader_host)) then
+		return false;
+	end
+
 	return true;
 end