Skip to content

fix(nginx): forward the ingress request scheme to the backend - #74

Merged
KFilippopolitis merged 2 commits into
masterfrom
fix/forwarded-proto
Nov 9, 2026
Merged

KFilippopolitis merged 2 commits into
masterfrom
fix/forwarded-proto

Conversation

@KFilippopolitis

Copy link
Copy Markdown
Contributor

Summary

Implements the new forwarded-headers item from the laptop sign-in security review (needed by the backend's DPoP htu check, platform-backend PR #53, and W4 in the OWASP audit).

  • The /${PLATFORM_BACKEND_CONTEXT}/ location set Host, X-Real-IP and X-Forwarded-For but no X-Forwarded-Proto.

  • Copying the Jupyter locations' $scheme would be wrong in Kubernetes: TLS ends at the ingress, nginx sees http, and the backend's DPoP htu comparisons (https://…) would never match.

  • The template is included at http context, so the map sits above the server block:

    map $http_x_forwarded_proto $mip_forwarded_proto {
        default $http_x_forwarded_proto;
        ''      $scheme;
    }

    and the backend location sends X-Forwarded-Proto $mip_forwarded_proto.

  • No Dockerfile/entrypoint change needed (template-only; envsubst's restricted variable list leaves the map's $variables untouched — verified by simulating the container's envsubst invocation).

Relationship to other branches

fix/security-headers was checked first: its nginx changes are already content-identical to master, so no conflict.

Files changed

  • nginx.conf.template (+9 lines)

Tests/checks run

  • Simulated the container's envsubst step over the template: map directives and variables survive verbatim; rendered location block is correct.
  • Full nginx -t / deployed verification not run locally (no nginx binary; docker build left to CI). CI's image build covers template inclusion.

Risk

  • nginx deployment behavior change (human-review area per repo instructions): the backend now receives the ingress-provided scheme. If an ingress does not set X-Forwarded-Proto, the fallback is $scheme (http behind the ingress) — same as today's Jupyter locations.
  • A client-supplied X-Forwarded-Proto passes through when the ingress does not strip/set it; trusting the ingress is the design intent here.

Verification after deploy (from the review note)

With the image deployed, the backend log or a debug endpoint should show request.getRequestURL() starting with https://<portal>/services/.

The backend location sent no X-Forwarded-Proto. TLS ends at the ingress, so
$scheme (as the Jupyter locations use) would tell the backend 'http' and
DPoP htu checks against 'https://...' never match. Pass the ingress-provided
X-Forwarded-Proto through, falling back to $scheme when absent.
Review feedback on PR #74: pass-through copied whatever arrived, including
spoofed values or comma chains. A client 'https' claim is still honoured
(only the ingress can be trusted to rewrite the header), but HTTPS casing
and 'https,http' chains now normalise to https, and anything else falls
back to the container's own scheme.
@KFilippopolitis
KFilippopolitis merged commit c4bd8c9 into master Nov 9, 2026
16 checks passed
@KFilippopolitis
KFilippopolitis deleted the fix/forwarded-proto branch November 11, 2026 11:01
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