Skip to content

fix: nginx $http_authorization escaping in HOOKS_LOCATION_BLOCK#2

Open
daniel-rudaev wants to merge 1 commit intomainfrom
fix/nginx-authorization-header
Open

fix: nginx $http_authorization escaping in HOOKS_LOCATION_BLOCK#2
daniel-rudaev wants to merge 1 commit intomainfrom
fix/nginx-authorization-header

Conversation

@daniel-rudaev
Copy link
Copy Markdown

Summary

Fixes hooks endpoint returning 401 on every container restart.

Root cause

HOOKS_LOCATION_BLOCK is built as a double-quoted shell string. The original code used \\\$http_authorization, which stores \$http_authorization in 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 of HOOKS_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 valid Authorization: Bearer <token> header — because nginx passes the literal string $http_authorization to 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant