Software /
code /
prosody
Annotate
plugins/mod_stanza_debug.lua @ 12181:783056b4e448 0.11 0.11.12
util.xml: Do not allow doctypes, comments or processing instructions
Yes. This is as bad as it sounds. CVE pending.
In Prosody itself, this only affects mod_websocket, which uses util.xml
to parse the <open/> frame, thus allowing unauthenticated remote DoS
using Billion Laughs. However, third-party modules using util.xml may
also be affected by this.
This commit installs handlers which disallow the use of doctype
declarations and processing instructions without any escape hatch. It,
by default, also introduces such a handler for comments, however, there
is a way to enable comments nontheless.
This is because util.xml is used to parse human-facing data, where
comments are generally a desirable feature, and also because comments
are generally harmless.
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Mon, 10 Jan 2022 18:23:54 +0100 |
parent | 8348:c3de5b454ec4 |
child | 10111:0f335815244f |
rev | line source |
---|---|
8348
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 module:set_global(); |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local tostring = tostring; |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local filters = require "util.filters"; |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local function log_send(t, session) |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 if t and t ~= "" and t ~= " " then |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 session.log("debug", "SEND: %s", tostring(t)); |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 end |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 return t; |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 end |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 local function log_recv(t, session) |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 if t and t ~= "" and t ~= " " then |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 session.log("debug", "RECV: %s", tostring(t)); |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 end |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 return t; |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 end |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local function init_raw_logging(session) |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 filters.add_filter(session, "stanzas/in", log_recv, -10000); |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 filters.add_filter(session, "stanzas/out", log_send, 10000); |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 end |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 filters.add_filter_hook(init_raw_logging); |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 function module.unload() |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 filters.remove_filter_hook(init_raw_logging); |
c3de5b454ec4
mod_stanza_debug: Logs full stanzas sent and received for debugging purposes
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end |