mod_c2s, mod_s2s: Close incoming connections if there are no features to offer on incomplete streams (fixes #285)
--- a/plugins/mod_c2s.lua Thu Sep 24 20:02:57 2015 +0200
+++ b/plugins/mod_c2s.lua Thu Sep 24 20:05:23 2015 +0200
@@ -83,7 +83,12 @@
local features = st.stanza("stream:features");
hosts[session.host].events.fire_event("stream-features", { origin = session, features = features });
- send(features);
+ if features.tags[1] or session.full_jid then
+ send(features);
+ else
+ (session.log or log)("warn", "No features to offer");
+ session:close{ condition = "undefined-condition", text = "No features to proceed with" };
+ end
end
function stream_callbacks.streamclosed(session)
--- a/plugins/mod_s2s/mod_s2s.lua Thu Sep 24 20:02:57 2015 +0200
+++ b/plugins/mod_s2s/mod_s2s.lua Thu Sep 24 20:05:23 2015 +0200
@@ -351,8 +351,13 @@
(session.log or log)("warn", "No 'to' on stream header from %s means we can't offer any features", from or session.ip or "unknown host");
end
- log("debug", "Sending stream features: %s", tostring(features));
- session.sends2s(features);
+ if ( session.type == "s2sin" or session.type == "s2sout" ) or features.tags[1] then
+ log("debug", "Sending stream features: %s", tostring(features));
+ session.sends2s(features);
+ else
+ (session.log or log)("warn", "No features to offer, giving up");
+ session:close({ condition = "undefined-condition", text = "No features to offer" });
+ end
end
elseif session.direction == "outgoing" then
session.notopen = nil;