Mercurial > prosody-hg
annotate plugins/mod_http_altconnect.lua @ 14150:2a66728d9e29 13.0 13.0.5
mod_proxy65: Consistently apply authorization checks
The module checked for authorization when a client asked for the address:port
of the proxy service. It did not check for authorization when processing a
request to activate a bytestream. This meant that any unauthenticated party
able to guess the IP/port and XMPP domain of a proxy65 service (generally low
difficulty) would be able to use the proxy to relay traffic between two
connections.
This factors out the permission check, and applies it to every request type.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 29 Apr 2026 11:40:43 +0100 |
| parents | 569fae28a2f3 |
| children |
| rev | line source |
|---|---|
|
13718
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- mod_http_altconnect |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- XEP-0156: Discovering Alternative XMPP Connection Methods |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 module:depends"http"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local mm = require "prosody.core.modulemanager"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local json = require"prosody.util.json"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local st = require"prosody.util.stanza"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local array = require"prosody.util.array"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local advertise_bosh = module:get_option_boolean("advertise_bosh", true); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local advertise_websocket = module:get_option_boolean("advertise_websocket", true); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local function get_supported() |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local uris = array(); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 if advertise_bosh and (mm.is_loaded(module.host, "bosh") or mm.is_loaded("*", "bosh")) then |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 uris:push({ rel = "urn:xmpp:alt-connections:xbosh", href = module:http_url("bosh", "/http-bind") }); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 if advertise_websocket and (mm.is_loaded(module.host, "websocket") or mm.is_loaded("*", "websocket")) then |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 uris:push({ rel = "urn:xmpp:alt-connections:websocket", href = module:http_url("websocket", "xmpp-websocket"):gsub("^http", "ws") }); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 end |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 return uris; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 end |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local function GET_xml(event) |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 local response = event.response; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 local xrd = st.stanza("XRD", { xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0' }); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local uris = get_supported(); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 for _, method in ipairs(uris) do |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 xrd:tag("Link", method):up(); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 response.headers.content_type = "application/xrd+xml" |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 response.headers.access_control_allow_origin = "*"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 return '<?xml version="1.0" encoding="UTF-8"?>' .. tostring(xrd); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 end |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local function GET_json(event) |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local response = event.response; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 local jrd = { links = get_supported() }; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 response.headers.content_type = "application/json" |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 response.headers.access_control_allow_origin = "*"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 return json.encode(jrd); |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 module:provides("http", { |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 default_path = "/.well-known"; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 route = { |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 ["GET /host-meta"] = GET_xml; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 ["GET /host-meta.json"] = GET_json; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 }; |
|
569fae28a2f3
mod_http_altconnect: Imported from prosody-modules 6d5a19bdd718 w/changes
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 }); |
