fix: nginx $http_authorization escaping in HOOKS_LOCATION_BLOCK#2
Open
daniel-rudaev wants to merge 1 commit intomainfrom
Open
fix: nginx $http_authorization escaping in HOOKS_LOCATION_BLOCK#2daniel-rudaev wants to merge 1 commit intomainfrom
daniel-rudaev wants to merge 1 commit intomainfrom
Conversation
In entrypoint.sh, HOOKS_LOCATION_BLOCK is built as a double-quoted shell string. Using \\$var stores \ in the variable — when interpolated into the heredoc, nginx sees \ (escaped literal) instead of the variable $http_authorization, so the Authorization header from the upstream request is never forwarded to the gateway. Fix: use \ (single escape) so the variable stores bare $var, which the heredoc passes through correctly as a nginx variable reference. Same bug applied to $host, $remote_addr, $proxy_add_x_forwarded_for, and $scheme in the same block — all fixed. Symptom: hooks endpoint returns 401 after every container restart because nginx passes the literal string '$http_authorization' instead of the actual Authorization header value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes hooks endpoint returning 401 on every container restart.
Root cause
HOOKS_LOCATION_BLOCKis built as a double-quoted shell string. The original code used\\\$http_authorization, which stores\$http_authorizationin the variable. When this variable is later interpolated into the nginx heredoc, nginx sees\$http_authorization— an escaped literal, not the variable — so the Authorization header from the upstream request is never forwarded to the gateway.The main
location /block (line ~255) builds nginx config directly inside the heredoc and correctly uses\$http_authorization. The hooks block, being constructed as a shell variable first, needs a single escape (\$) to achieve the same result.Changes
scripts/entrypoint.sh— change\\\$→\$in all 5 affected lines ofHOOKS_LOCATION_BLOCK:proxy_set_header Authorization \$http_authorization;proxy_set_header Host \$host;proxy_set_header X-Real-IP \$remote_addr;proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto \$scheme;Symptom
After container restart, any external request to the hooks endpoint (
/hooks/*) returns 401 even with a validAuthorization: Bearer <token>header — because nginx passes the literal string$http_authorizationto the upstream gateway instead of the actual header value.This was confirmed in D1DX production on 2026-04-04 after the first container recreation post-hooks-setup.