Skip to content

(janitor/dedupe): consolidate OAuth callback state hash and code validation - #7968

Merged
kilo-code-bot[bot] merged 1 commit into
mainfrom
janitor/dedupe/oauth-callback-safety
Oct 19, 2026
Merged

kilo-code-bot[bot] merged 1 commit into
mainfrom
janitor/dedupe/oauth-callback-safety

Conversation

@kilo-code-bot

@kilo-code-bot kilo-code-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

What

Four OAuth callback handlers duplicated two small, security-relevant helpers:

  • OAuth state hash for observability — createHash('sha256').update(state).digest('hex').slice(0, 8) (the raw signed state embeds the owner, user id and nonce, so it must never be logged). Copied in gitlab-callback.ts, bitbucket-callback.ts, google/callback/route.ts, and github/user-connect/callback/route.ts.
  • OAuth authorization-code validation (RFC 6749 code alphabet + 2048-char cap). Implemented three times: validOAuthCode (bitbucket, github) and sanitizeOAuthCode (google).

This PR extracts both into a single owner, apps/web/src/lib/integrations/oauth/callback-safety.ts, and rewires the four callers. No behavior change: the hash formula and the code-validation regex/length are byte-for-byte identical to before.

Classification

Shared behavior (state hash) + shared data pipeline (code validation): one domain concept declared in multiple files that must change together.

Notes / adjacent findings (not changed)

  • provider_oauth_attempts.ts keeps its own full SHA-256 of the state for DB equality matching. That is intentionally different from the truncated observability hash, so it is left alone (documented in the new module).
  • discord, dolthub, linear, and slack callbacks still log the raw state value to Sentry in their catch blocks. That is a potential leak of the signed state token and worth a separate security follow-up; it is out of scope for this dedupe PR.

Verification

  • pnpm --filter web run typecheck — passes (exit 0).
  • oxlint on the five touched files — 0 warnings, 0 errors.
  • oxfmt on the five touched files — clean.
  • Unit tests for the two affected callback routes could not run in this environment because the Jest global setup requires a reachable PostgreSQL (cleanupDbForTest in web-shared/src/lib/drizzle.ts); no Postgres/Redis is available here.

…dation

Four OAuth callbacks (gitlab, bitbucket, google, github user-connect) each
computed an 8-char SHA-256 truncation of the signed OAuth state for safe
Sentry logging, and three of them re-implemented the same RFC 6749
authorization-code validation. Consolidate both into one owner so a change
to the observability hash or code alphabet applies everywhere.
@kilo-code-bot kilo-code-bot Bot added the janitor Automated dead-code/duplication cleanup label Oct 19, 2026
@kilo-code-bot
kilo-code-bot Bot enabled auto-merge October 19, 2026 07:20
@kilo-code-bot

kilo-code-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Behavior-preserving dedupe of OAuth callback helpers across 5 files; verified equivalence of the state-hash and authorization-code validation logic at every call site.

Files Reviewed (5 files)
  • apps/web/src/lib/integrations/oauth/callback-safety.ts
  • apps/web/src/lib/integrations/oauth/platforms/bitbucket-callback.ts
  • apps/web/src/lib/integrations/oauth/platforms/gitlab-callback.ts
  • apps/web/src/app/api/integrations/google/callback/route.ts
  • apps/web/src/app/api/integrations/github/user-connect/callback/route.ts

Reviewed by deepseek-v4.1-flash · Input: 49.1K · Output: 5.9K · Cached: 321.4K

Review guidance: REVIEW.md from base branch main

@kilo-code-bot

kilo-code-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Meta Janitor: Safety review passed; requesting approval.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meta-janitor safety approval for 214e0d8. Signal: #7968 (comment). GitHub auto-merge remains responsible for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

janitor Automated dead-code/duplication cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants