commit: refactor onion_to_dns to be smarter, use it more, and trap body rewrites in POST only

pull/57/head
Alec Muffett 2019-12-19 20:13:42 +00:00
rodzic 44d9ade4e5
commit eaa71711b9
2 zmienionych plików z 12 dodań i 14 usunięć

Wyświetl plik

@ -2,5 +2,6 @@
# eotk (c) 2017 Alec Muffett
cd %PROJECT_DIR% || exit 1
sh %PROJECT_DIR%/stop.sh
sleep 1
sh %PROJECT_DIR%/start.sh
exit 0

Wyświetl plik

@ -274,6 +274,9 @@ http {
return result
end
local o, num, errs = ngx.re.gsub(i, "(%LEFT_TLD_RE%)([a-z2-7]{16}(?:[a-z2-7]{40})?\\.onion)\\b", o_to_d_lookup, "io")
if errs == nil and num == 0 then
return i -- nothing was changed, so return the original
end
return o
end
@ -622,26 +625,20 @@ http {
# deonionify the request_uri for forwarding (both path and args)
set_by_lua_block $request_uri2 {
local old = ngx.var.request_uri or ""
-- onion_to_dns is potentially expensive at scale, so do a cheap test
local m, err = ngx.re.match(old, "(?:%LEFT_TLD_RE%)[a-z2-7]{16}(?:[a-z2-7]{40})?\\.onion\\b", "io")
if not m then -- nothing to attempt to rewrite, quick return
return old
end
return onion_to_dns(old)
return onion_to_dns(ngx.var.request_uri)
}
%%IF %DEONIONIFY_REQUESTS%
# deonionify_requests
# deonionify_requests (specifically, the body; path and args come as standard)
access_by_lua_block {
if ngx.req.get_method() == "POST" then
ngx.req.read_body()
local oldbody = ngx.req.get_body_data()
-- onion_to_dns is potentially expensive at scale, so do a cheap test
local m, err = ngx.re.match(oldbody, "(?:%LEFT_TLD_RE%)[a-z2-7]{16}(?:[a-z2-7]{40})?\\.onion\\b", "io")
if m then -- we may have work to do
local newbody = onion_to_dns(oldbody)
ngx.req.set_body_data(newbody)
local old = ngx.req.get_body_data()
local new = onion_to_dns(old)
if new != old -- hopefully fast, thank you lua
ngx.req.set_body_data(new)
end
end
}
%%ELSE
# no deonionify_requests