Comparison

mod_external_services/mod_external_services.lua @ 4665:f0ffa8cf3ce6

mod_external_services: Validate required attributes on credentials requests
author Kim Alvefur <zash@zash.se>
date Sun, 29 Aug 2021 23:26:19 +0200
parent 4075:4841cf3fded5
child 4666:dbc7ba3cc27c
comparison
equal deleted inserted replaced
4664:524a9103fb45 4665:f0ffa8cf3ce6
166 local function handle_credentials(event) 166 local function handle_credentials(event)
167 local origin, stanza = event.origin, event.stanza; 167 local origin, stanza = event.origin, event.stanza;
168 local action = stanza.tags[1]; 168 local action = stanza.tags[1];
169 169
170 if origin.type ~= "c2s" then 170 if origin.type ~= "c2s" then
171 origin.send(st.error_reply(stanza, "auth", "forbidden")); 171 origin.send(st.error_reply(stanza, "auth", "forbidden", "The 'port' and 'type' attributes are required."));
172 return true; 172 return true;
173 end 173 end
174 174
175 local reply = st.reply(stanza):tag("credentials", { xmlns = action.attr.xmlns }); 175 local reply = st.reply(stanza):tag("credentials", { xmlns = action.attr.xmlns });
176 local extras = module:get_host_items("external_service"); 176 local extras = module:get_host_items("external_service");
179 return item.restricted; 179 return item.restricted;
180 end) 180 end)
181 181
182 local requested_credentials = {}; 182 local requested_credentials = {};
183 for service in action:childtags("service") do 183 for service in action:childtags("service") do
184 if not service.attr.type or not service.attr.host then
185 origin.send(st.error_reply(stanza, "modify", "bad-request"));
186 return true;
187 end
188
184 table.insert(requested_credentials, { 189 table.insert(requested_credentials, {
185 type = service.attr.type; 190 type = service.attr.type;
186 host = service.attr.host; 191 host = service.attr.host;
187 port = tonumber(service.attr.port); 192 port = tonumber(service.attr.port);
188 }); 193 });