fix(nginx): exempt herdr-web-ui /api/auth and /api/devices/pair from authelia
test-runner / smoke (push) Canceled after 0s
test-runner / smoke (push) Canceled after 0s
The herdr-web-ui token entry form (POST /api/auth with JSON body
{"token": "..."}) and the 6-digit pairing flow (POST /api/devices/pair)
were returning 500 through the vhost instead of 204/401. nginx's
auth_request subrequest hits authelia first; authelia returns 401
because the visitor is not signed in yet (no authelia cookie);
error_page 401 =302 then tries to redirect the original POST, but
nginx's 302 rewrite only works cleanly for GET — the POST round
trips to a 500 ("auth request unexpected status" in the nginx
error log). Same root cause as the working vtimeline/tty vhosts,
where the form is GET-only and the redirect works.
Fix: add a regex location '~ ^/api/(auth|devices/pair|health)$'
that proxies these three paths to 127.0.0.1:7317 WITHOUT the
authelia auth_request. The Bun server's own auth.ts keeps the same
three paths open in requiresAuth() (server/auth.ts:79-85), so a
missing or wrong token is rejected there with 401 + JSON body —
the gate is enforced one layer down, just not by authelia.
Verified after the rebuild:
POST /api/auth (body=token) -> 204 + set-cookie herdr_web_token
POST /api/devices/pair (code=...) -> 401 invalid_code (not 500)
GET /api/health -> 200
Real-browser flow now: visitor opens herdr.zeroq.su -> authelia
login -> web UI shows pair/token form -> submit POST /api/auth
works -> HttpOnly cookie set -> app loads.
This commit is contained in:
1 parent
4d1426cab0
commit
61ad57a102
1 file changed
+24
@@ -246,6 +246,30 @@ in
|
|||||||
forceSSL = true;
|
forceSSL = true;
|
||||||
enableACME = true;
|
enableACME = true;
|
||||||
locations = {
|
locations = {
|
||||||
|
# /api/auth, /api/devices/pair and /api/health are herdr-web-ui's
|
||||||
|
# own gate: /api/auth is the form that sets the herdr_web_token
|
||||||
|
# cookie, /api/devices/pair is the 6-digit-code flow, /api/health
|
||||||
|
# is a plain status probe. All three must reach the Bun server
|
||||||
|
# without an upstream authelia check — the user is not signed in
|
||||||
|
# yet when they POST the token, and the POST would otherwise
|
||||||
|
# trigger `authelia` → 401 → `error_page 401 =302`, but the
|
||||||
|
# 302-rewrite only works for GET: a POST request through that
|
||||||
|
# chain returns 500 ("auth request unexpected status" in the
|
||||||
|
# nginx error log), and the client never reaches the Bun server.
|
||||||
|
# Exempting these three from the `authelia` subrequest lets the
|
||||||
|
# form post work. The Bun server's own auth.ts keeps /api/auth,
|
||||||
|
# /api/devices/pair and /api/health open in `requiresAuth()`
|
||||||
|
# (server/auth.ts:79-85) so a missing or wrong token is rejected
|
||||||
|
# there with 401 + JSON body, never silently served.
|
||||||
|
"~ ^/api/(auth|devices/pair|health)$" = {
|
||||||
|
proxyPass = "http://127.0.0.1:7317";
|
||||||
|
proxyWebsockets = true;
|
||||||
|
extraConfig = ''
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-Forwarded-Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Method $request_method;
|
||||||
|
'';
|
||||||
|
};
|
||||||
"/" = {
|
"/" = {
|
||||||
proxyPass = "http://127.0.0.1:7317";
|
proxyPass = "http://127.0.0.1:7317";
|
||||||
proxyWebsockets = true;
|
proxyWebsockets = true;
|
||||||
|
|||||||
Reference in new issue
Block a user