Changeset

4853:3804332c204e

mod_tcpproxy: Reject missing or non-number block-size, as per XEP-0047
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 07 Jan 2022 19:55:03 +0100
parents 4852:810b0e17d3aa
children 4854:ee2463fbf794
files mod_tcpproxy/README.markdown mod_tcpproxy/mod_tcpproxy.lua
diffstat 2 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mod_tcpproxy/README.markdown	Thu Jan 06 17:45:15 2022 +0100
+++ b/mod_tcpproxy/README.markdown	Fri Jan 07 19:55:03 2022 +0100
@@ -39,16 +39,17 @@
 ``` {.xml}
 <iq type="set" id="newconn1" to="tcp.example.com">
   <open xmlns='http://jabber.org/protocol/ibb'
-        sid='connection1'
-        stanza='message'
+        sid='connection1'
+        block-size='4096'
+        stanza='message'
         xmlns:tcp='http://prosody.im/protocol/tcpproxy'
         tcp:host='example.com'
         tcp:port='80' />
 </iq>
 ```
 
-The stanza attribute (currently) MUST be 'message', and a block-size, if
-given, is (currently) ignored.
+The stanza attribute (currently) MUST be 'message', and block-size is
+(currently) ignored.
 
 In response to this stanza you will receive a result upon connection
 success, or an error if the connection failed. You can then send to the
@@ -67,6 +68,6 @@
 ====
 
 -   ACLs (restrict to certain JIDs, and/or certain target hosts/ports)
--   Honour block-size (undecided)
+-   Honour block-size
 -   Support iq stanzas for data transmission
 -   Signal to start SSL/TLS on a connection
--- a/mod_tcpproxy/mod_tcpproxy.lua	Thu Jan 06 17:45:15 2022 +0100
+++ b/mod_tcpproxy/mod_tcpproxy.lua	Fri Jan 07 19:55:03 2022 +0100
@@ -44,13 +44,16 @@
 	if ibb_tag.name == "open" then
 		-- Starting a new stream
 		local to_host, to_port = ibb_tag.attr[host_attr], ibb_tag.attr[port_attr];
-		local jid, sid = stanza.attr.from, ibb_tag.attr.sid;
+		local jid, sid, block_size = stanza.attr.from, ibb_tag.attr.sid, ibb_tag.attr["block-size"];
 		if not (to_host and to_port) then
 			origin.send(st.error_reply(stanza, "modify", "bad-request", "No host/port specified"));
 			return true;
 		elseif not sid or sid == "" then
 			origin.send(st.error_reply(stanza, "modify", "bad-request", "No sid specified"));
 			return true;
+		elseif not block_size or not tonumber(block_size) then
+			origin.send(st.error_reply(stanza, "modify", "bad-request", "Bad block-size attribute"));
+			return true;
 		elseif ibb_tag.attr.stanza ~= "message" then
 			origin.send(st.error_reply(stanza, "modify", "bad-request", "Only 'message' stanza transport is supported"));
 			return true;