Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
public identity headers such as `X-User-Id`, `X-Organization-Id`,
`X-Group-Id`, `X-Group-Ids`, `X-User-Role`, or `X-Dev-Auth-Token`;
tests/mocks must exercise the signed-session path.
- JWT/session verification must reject unsupported critical headers (`crit`)
before trusting payload claims; do not rely only on library defaults for this
boundary.
- Private backend `/api/*` routers must be registered with the default
`get_auth_context` signed-session dependency; only explicitly documented
public endpoints such as `/` may omit it. Keep runtime feature/configuration
Expand Down
2 changes: 2 additions & 0 deletions backend/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def _verify_signed_session_payload(authorization: str | None) -> dict[str, Any]:
header = _json_object_from_base64url_segment(header_segment)
if header.get("alg") != SESSION_SIGNING_ALGORITHM:
raise _authentication_error()
if "crit" in header:
raise _authentication_error()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

secret = _session_secret_bytes()
signing_input = f"{header_segment}.{payload_segment}"
Expand Down
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ opentelemetry-instrumentation-fastapi==0.46b0
opentelemetry-exporter-otlp==1.25.0
setuptools==78.1.1
websockets==14.1
PyJWT==2.8.0
PyJWT==2.13.0
19 changes: 19 additions & 0 deletions backend/tests/test_auth_real.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,25 @@ async def test_signed_bearer_session_rejects_rs256_algorithm():
assert exc.value.status_code == 401


@pytest.mark.asyncio
async def test_signed_bearer_session_rejects_unknown_critical_header():
settings.AUTH_SESSION_HMAC_SECRET = SecretStr(TEST_SESSION_HMAC_SECRET)
token = _signed_session_token(
_valid_session_payload(),
header={
"alg": "HS256",
"typ": "JWT",
"crit": ["x-custom-policy"],
"x-custom-policy": "require-mfa",
},
)

with pytest.raises(HTTPException) as exc:
await get_auth_context(authorization=f"Bearer {token}")

assert exc.value.status_code == 401


@pytest.mark.asyncio
async def test_signed_bearer_session_rejects_wrong_secret():
settings.AUTH_SESSION_HMAC_SECRET = SecretStr(TEST_SESSION_HMAC_SECRET)
Expand Down
Loading