Public: anyone can read this; the crew can change it.

The JWKS answers with Cache-Control and keeps the previous signing key listed while a rotation settles #16062

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This change only adds a test. The behaviour was already in place, so I changed no source. What already held: GET /oauth/jwks is served from src/http/oauth.ts (the route) and src/core/oidc.ts (the key set).

Notes

shipped production is serving it deploy 3fede26

opened this

This change only adds a test. The behaviour was already in place, so I changed no source.

  • What already held: GET /oauth/jwks is served from src/http/oauth.ts (the route) and src/core/oidc.ts (the key set). It answers with cache-control: public, max-age=300. After a rotation it lists the new key and the previous one, and a second rotation drops the oldest. The file named in the issue, src/http/jwks.ts, is the client that fetches another forge's keys, so it needed no change.
  • What I added: test/jwks-rotation.test.ts starts the app and reads /oauth/jwks over HTTP. It checks:
    • the cache-control: public, max-age=… header;
    • exactly one key before a rotation;
    • after a rotation, the new key then the previous one, in that order;
    • every listed key has public members only, with no d and nothing outside the allowed set;
    • a token signed by the previous key still verifies after the rotation, and fails once it has expired;
    • a second rotation drops the first key.
  • What I left out: the test would not fail if the change were removed, because there is no change. The public keys also carry ext and key_ops; I allowed those and left them alone because they are harmless.
  • Checks: the new test passes, tsc --noEmit is clean, and scripts/gate.ts --fix changed nothing. I ran only this test file, not the full suite.

To try it, run bun test test/jwks-rotation.test.ts.

🤖 Generated with Claude Code

Closes #16054

1 earlier comment · 1 event
commented

This change only adds a test. The behaviour was already in place, so I changed no source.

  • What already held: GET /oauth/jwks is served from src/http/oauth.ts (the route) and src/core/oidc.ts (the key set). It answers with cache-control: public, max-age=300. After a rotation it lists the new key and the previous one, and a second rotation drops the oldest. The file named in the issue, src/http/jwks.ts, is the client that fetches another forge's keys, so it needed no change.
  • What I added: test/jwks-rotation.test.ts starts the app and reads /oauth/jwks over HTTP. It checks:
    • the cache-control: public, max-age=… header;
    • exactly one key before a rotation;
    • after a rotation, the new key then the previous one, in that order;
    • every listed key has public members only, with no d and nothing outside the allowed set;
    • a token signed by the previous key still verifies after the rotation, and fails once it has expired;
    • a second rotation drops the first key.
  • What I left out: the test would not fail if the change were removed, because there is no change. The public keys also carry ext and key_ops; I allowed those and left them alone because they are harmless.
  • Checks: the new test passes, tsc --noEmit is clean, and scripts/gate.ts --fix changed nothing. I ran only this test file, not the full suite.

To try it, run bun test test/jwks-rotation.test.ts.

🤖 Generated with Claude Code

Approved

Test-only pull. I checked the source: src/http/oauth.ts:80 already sets public, max-age=300 on the JWKS, and rotateKeys keeps the new and previous key. The test is correct and pins that behaviour over real HTTP. It also checks that private members are absent and that a second rotation retires the oldest key. The preview answered 503 when I fetched it, and since this pull changes no source it adds nothing to see there. Two things I would do next: (1) assert the exact max-age value, so a silent change to the TTL is noticed; (2) add the issue-closing mutation check, which means temporarily reverting the overlap in oidc.ts to show the test goes red. Box 4 is only half met: nothing in the change makes the test fail, because the behaviour was already there.

commented

Left #16054 open: 1 unticked item remain (bun test passes; a new test fails without the change.).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs