Skip to content

fix(auth): trust mpass identity headers only from the edge and verify the token - #58

Merged
UsamaSadiq merged 5 commits into
foss-sandboxfrom
fix/foss-776-proxy-header-trust
Nov 13, 2026
Merged

UsamaSadiq merged 5 commits into
foss-sandboxfrom
fix/foss-776-proxy-header-trust

Conversation

@UsamaSadiq

@UsamaSadiq UsamaSadiq commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Closes FOSS-776: plane-api now trusts mPass identity headers only on requests that came through Traefik, and verifies the forwarded token's signature before the corporate-ID check.
  • Rollout order: the bundle PR Pressingly/foss-server-bundle#276 and the env sub-tickets (FOSS-786 GKE and Northlight, FOSS-787 Moneta prod VM, FOSS-788 askii) must land before this image reaches an environment. Without MPASS_EDGE_SECRET the new image ignores every identity header and nobody can sign in through mPass.
  • Before: ProxyAuthMiddleware logged in whoever X-Auth-Request-Email named on any request reaching plane-api, including direct calls on the Docker backend network that skip Traefik. _check_corporate_id decoded the token with verify_signature: False, so a forged token passed too.
  • authentication/middleware/edge_trust.py (new): request_is_from_edge compares X-Mpass-Edge-Secret with MPASS_EDGE_SECRET using hmac.compare_digest. An empty or shorter-than-32 secret trusts nothing (fail closed, like ERPNext).
  • authentication/middleware/proxy_auth.py:
    • Identity headers are ignored unless the request is from the edge (_read_trusted_proxy_email returns an empty email), so a forged header can neither log anyone in nor trigger the user-switch logout.
    • _check_corporate_id is replaced by _corporate_rejection, which goes through the verifier below.
    • Startup ERROR when the edge secret is unusable, and when SMB_CORPORATE_ID is set but the verifier has no issuer or client id.
    • Log lines carry the mPass id, path and remote address, never emails or tokens.
  • authentication/middleware/mpass_token.py (new): MpassTokenVerifier.
    • Issuer allowlist: MPASS_COGNITO_ISSUER_URL (the bundle passes OIDC_BASE_URI, the issuer oauth2-proxy validates), falling back to COGNITO_AWS_REGION + COGNITO_USER_POOL_ID, plus the optional MPASS_TOKEN_ISSUER_URL for id_tokens re-signed by mpass-auth-proxy when email capture is on. CHANGE_ME_ values count as unset.
    • One cached PyJWKClient per issuer, 2s fetch timeout, 30s backoff per issuer after a failed fetch.
    • RS256 only; exp, iat, iss, token_use required; 60s leeway. Access tokens need client_id == MPASS_OIDC_CLIENT_ID, id_tokens need it in aud.
    • Every failure is a 403 with a reason code (bad_signature, untrusted_issuer, jwks_unavailable, wrong_organization, ...). A non-JSON JWKS body or a dropped connection is jwks_unavailable, not a 500.
    • With SMB_CORPORATE_ID unset no token is read and no JWKS is fetched, as before.
  • middleware/logger.py: x-mpass-edge-secret and x-auth-request-access-token are redacted in api_activity_logs. plane-mcp's /api/v1 calls go through Traefik and would otherwise store both.
  • settings/common.py: the new settings above.
  • Not affected: X-Api-Key callers (plane-mcp's /api/v1 leg, internal services), session cookies, god-mode and the bypass paths.
def _read_trusted_proxy_email(self, request):
    if request_is_from_edge(request, self.edge_secret):
        return self._read_proxy_email(request)
    ...
    return ""

Testing

  • pytest plane/tests/unit/middleware/test_logger.py plane/authentication/tests/ -o addopts="--strict-markers --nomigrations": 125 passed. ruff check and ruff format clean.
  • New tests cover: forged header without or with a wrong secret ignored, no user created, no email logged; forged header cannot end an existing session; edge request logs in; API key plus forged header authenticates as the key owner; valid Cognito access token and valid re-signed id_token log in; bad signature, expired, wrong issuer, wrong audience, refresh token, HS256, alg=none, malformed and missing token each give 403 with their reason; issuer resolution, CHANGE_ME_ handling, the startup ERROR, JWKS caching, backoff and fetch errors.
  • Devstack (fix files on the image the devstack runs, with the bundle branch):
    • Direct GET http://plane-api:8000/api/users/me/ and via plane-proxy:80 from another backend container with a forged X-Auth-Request-Email: 401 (was 200), no user created.
    • Browser SSO through Traefik logs in, /api/users/me/ returns 200; /god-mode/ and /api/instances/ return 200.
    • X-Api-Key call to /api/v1/users/me/ with a forged email header: 200 as the key owner.
    • With a dummy SMB_CORPORATE_ID, a fresh browser login was refused with reason=wrong_organization, which is only reached after the real token passed signature, issuer, expiry and audience checks against the live Cognito JWKS.
  • Still to verify on staging: a successful login with the real corporate ID, and a plane-mcp tool call with email capture on.

… the token

ProxyAuthMiddleware now ignores X-Auth-Request-* unless the request carries
MPASS_EDGE_SECRET in X-Mpass-Edge-Secret, which Traefik injects on the SSO
router. With SMB_CORPORATE_ID set, the forwarded token is verified against the
Cognito and mpass-auth-proxy JWKS (issuer, expiry, audience) instead of being
decoded unverified (FOSS-776).
…ty logs

Requests through Traefik carry X-Mpass-Edge-Secret and X-Auth-Request-Access-Token;
API-key calls (plane-mcp) would otherwise persist both in api_activity_logs (FOSS-776).
…s errors

Adds MPASS_COGNITO_ISSUER_URL (region and pool id are the fallback), ignores
CHANGE_ME_ placeholders, logs an error when the corporate gate has no issuer or
client id, maps non-JSON or reset JWKS fetches to a 403, and backs off 30s per
issuer after a failed fetch with a 2s timeout (FOSS-776).
@UsamaSadiq
UsamaSadiq merged commit 13d7268 into foss-sandbox Nov 13, 2026
2 checks passed
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