Mercurial > prosody-modules
comparison mod_pastebin/mod_pastebin.lua @ 3139:03cda95ae97a
mod_pastebin: Prevent header table form being mutated
default_headers was mutated, probably by mod_http_errors and ended up
with multiple content-type entries, which led to issues in browsers
which would sometimes treat the paste as html
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 23 Jun 2018 16:37:15 +0200 |
parents | c88f91626e07 |
children | 11087a72990b |
comparison
equal
deleted
inserted
replaced
3138:9817e45a79e6 | 3139:03cda95ae97a |
---|---|
49 | 49 |
50 local trigger_string = module:get_option_string("pastebin_trigger"); | 50 local trigger_string = module:get_option_string("pastebin_trigger"); |
51 trigger_string = (trigger_string and trigger_string .. " "); | 51 trigger_string = (trigger_string and trigger_string .. " "); |
52 | 52 |
53 local pastes = {}; | 53 local pastes = {}; |
54 local default_headers = { ["Content-Type"] = "text/plain; charset=utf-8" }; | |
55 | 54 |
56 local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im"; | 55 local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im"; |
57 local xmlns_xhtml = "http://www.w3.org/1999/xhtml"; | 56 local xmlns_xhtml = "http://www.w3.org/1999/xhtml"; |
58 | 57 |
59 function pastebin_text(text) | 58 function pastebin_text(text) |
65 end | 64 end |
66 return base_url..uuid; | 65 return base_url..uuid; |
67 end | 66 end |
68 | 67 |
69 function handle_request(event, pasteid) | 68 function handle_request(event, pasteid) |
70 if not pasteid or not pastes[pasteid] then | 69 event.response.headers.content_type = "text/plain; charset=utf-8"; |
71 event.response.headers = default_headers; | 70 |
72 return event.response:send("Invalid paste id, perhaps it expired?"); | 71 if not pasteid then |
72 return "Invalid paste id, perhaps it expired?"; | |
73 end | 73 end |
74 | 74 |
75 --module:log("debug", "Received request, replying: %s", pastes[pasteid].text); | 75 --module:log("debug", "Received request, replying: %s", pastes[pasteid].text); |
76 | 76 local paste = pastes[pasteid]; |
77 return pastes[pasteid]; | 77 |
78 if not paste then | |
79 return "Invalid paste id, perhaps it expired?"; | |
80 end | |
81 | |
82 return paste.body; | |
78 end | 83 end |
79 | 84 |
80 local function replace_tag(s, replacement) | 85 local function replace_tag(s, replacement) |
81 local once = false; | 86 local once = false; |
82 s:maptags(function (tag) | 87 s:maptags(function (tag) |