(janitor/dedupe): consolidate HMAC-signed link/state token helpers - #5869
Open
kilo-code-bot[bot] wants to merge 1 commit into
Open
(janitor/dedupe): consolidate HMAC-signed link/state token helpers#5869kilo-code-bot[bot] wants to merge 1 commit into
kilo-code-bot[bot] wants to merge 1 commit into
Conversation
Six modules in apps/web each reimplemented the same HMAC-signed, time-limited token format (base64url JSON payload with iat + nonce, HMAC-SHA256 signature, timing-safe compare, TTL enforcement). Extract the shared sign/verify primitive into lib/signed-token.ts and have each caller keep only its own payload shape validation.
Contributor
Author
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (7 files)
Reviewed by grok-4.6 · Input: 60.2K · Output: 12.4K · Cached: 297.3K Review guidance: REVIEW.md from base branch |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Six modules in
apps/webeach re-implemented the same signed, time-limited URL token/state format:lib/integrations/oauth-state.tslib/bot/linear-link-token.tslib/bot/github-link-token.tslib/bot/linear-link-state.tslib/bot/github-link-state.tslib/device-auth/device-auth-viewer-token.tsAll of them shared an identical wire format (
base64url(JSON({ ...payload, iat, nonce })) . HMAC-SHA256(secret)) and identical verification (split on., timing-safe compare, base64url decode, TTL checkout, nonce presence check). Copies had already begun to drift (e.g.github-link-stateaccepts emptyuserIdwhilelinear-link-staterequires non-empty).Change
Extracted the shared primitive into
lib/signed-token.ts:createSignedToken(payload)— injectsiat+nonce, serializes, signs.verifySignedToken(token, { ttlSeconds, parse })— verifies signature (timing-safe), enforces TTL + nonce, then delegates to each caller's payload-shape validation.Each caller now retains only its own payload shape (zod schema or manual type checks) and TTL constant. Public exports (
createOAuthState,verifyOAuthState,OAUTH_STATE_TTL_SECONDS,Verified*types, etc.) are unchanged, and the wire format is byte-compatible so tokens minted before this change still verify.Net: 7 files, +190 / −361.
Out of scope
lib/bot-identity.tsuses the same wire format but its verify is async and interleaves a Redis context lookup, so it is intentionally left untouched to avoid forcing an awkward async abstraction.Verification
oxlintclean on all changed files.tsgo --noEmit(web typecheck) clean.oxfmtformatting applied.kinddiscriminator) passes.Unit tests (
jest) could not be run in this environment because the Jest global setup requires a live PostgreSQL instance.