Repository navigation
Add rotatable proxy tokens and a proxy-only key for internal API routes #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Brooooooklyn
merged 12 commits into
security/1a-quick-fixes
from
security/1b-proxy-token-v2
Oct 8, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d1eae71
Add the generation-based proxy token module
Brooooooklyn 520546a
Accept v2 proxy tokens alongside the legacy token
Brooooooklyn 8f0d25c
Send the issued proxy token generation to tenant Workers
Brooooooklyn ecff301
Sign proxy-to-API metadata calls with a proxy-only key
Brooooooklyn fedb65d
Issue proxy tokens from the accept floor
Brooooooklyn 4757cec
Retry cron fires and queue relays with a fallback token
Brooooooklyn 3af9d92
Skip unknown cleanup jobs instead of deleting them
Brooooooklyn 4532d3e
Document proxy token generations for maintainers
Brooooooklyn 2729af3
Cover floor 2 in proxy token state table and rewrap proxy README
Brooooooklyn bc360f0
Bound the proxy's read of a tenant 403 before retrying
Brooooooklyn acb2624
Drop the version marker from proxy tokens and keys
Brooooooklyn a1431cc
Send one proxy token and never replay a rejected request
Brooooooklyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import type { Context } from 'hono'; | ||
| import type { ApiEnv } from './env.ts'; | ||
| import { isProjectId } from './id.ts'; | ||
| import { | ||
| PROXY_INTERNAL_AUTH_HEADER, | ||
| PROXY_TOKEN_KV_CACHE_TTL_SECONDS, | ||
| type ProxyInternalRoute, | ||
| ProxyTokenStateError, | ||
| readProxyTokenState, | ||
| verifyProxyInternalAuth, | ||
| verifyProxyToken, | ||
| } from './proxy-token.ts'; | ||
|
|
||
| /** | ||
| * Checks a tenant project token forwarded by the proxy against the project's | ||
| * accept floor. A floor that cannot be read or is malformed is | ||
| * `'unavailable'`, never accepted. | ||
| */ | ||
| export async function checkTenantProxyToken( | ||
| env: Pick<ApiEnv['Bindings'], 'ROUTING' | 'JWT_SECRET'>, | ||
| projectId: string, | ||
| token: string, | ||
| ): Promise<'ok' | 'invalid' | 'unavailable'> { | ||
| try { | ||
| const valid = await verifyProxyToken({ | ||
| jwtSecret: env.JWT_SECRET, | ||
| projectId, | ||
| token, | ||
| readState: () => | ||
| readProxyTokenState(env.ROUTING, projectId, { | ||
| cacheTtl: PROXY_TOKEN_KV_CACHE_TTL_SECONDS, | ||
| }), | ||
| }); | ||
| return valid ? 'ok' : 'invalid'; | ||
| } catch (error) { | ||
| if (error instanceof ProxyTokenStateError) { | ||
| console.error('[proxy-token] state unavailable', { projectId, error }); | ||
| return 'unavailable'; | ||
| } | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Authenticates the proxy on an internal metadata route. The proxy signs | ||
| * `x-void-proxy-internal` with its own key, bound to the route and project. | ||
| * A request without that header is checked like a tenant project token in | ||
| * `x-void-internal`, so a token below the project's accept floor is refused | ||
| * here as it is at the proxy. | ||
| * | ||
| * Returns null when the call may proceed, else the error response. | ||
| */ | ||
| export async function requireProxyInternalAuth( | ||
| context: Context<ApiEnv>, | ||
| route: ProxyInternalRoute, | ||
| projectId: string, | ||
| ): Promise<Response | null> { | ||
| const proxyAuth = context.req.header(PROXY_INTERNAL_AUTH_HEADER); | ||
| const token = context.req.header('x-void-internal'); | ||
| if (!proxyAuth && !token) { | ||
| return context.json({ error: 'missing internal auth' }, 401); | ||
| } | ||
| if (!isProjectId(projectId)) { | ||
| return context.json({ error: 'invalid internal auth' }, 403); | ||
| } | ||
| if (proxyAuth) { | ||
| return (await verifyProxyInternalAuth(context.env.JWT_SECRET, route, projectId, proxyAuth)) | ||
| ? null | ||
| : context.json({ error: 'invalid internal auth' }, 403); | ||
| } | ||
| const tokenCheck = await checkTenantProxyToken(context.env, projectId, token ?? ''); | ||
| if (tokenCheck === 'unavailable') { | ||
| return context.json({ error: 'project token state unavailable' }, 503); | ||
| } | ||
| if (tokenCheck === 'invalid') { | ||
| return context.json({ error: 'invalid internal auth' }, 403); | ||
| } | ||
| return null; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.