fix(connect): add missing randomBytes import and rename parseGoogleState to parseOAuthState#211
Merged
ShantKhatri merged 2 commits intoMay 21, 2026
Conversation
randomBytes was used in generateState() without being imported from crypto, causing a ReferenceError crash on any GET /connect/github request. Also renamed parseGoogleState to parseOAuthState since the function is exclusively used in the GitHub connect flow — Google connect does not exist in this file. Closes Dev-Card#178
Signed-off-by: Prashantkumar Khatri <96608160+ShantKhatri@users.noreply.github.com>
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
Two bugs were present in
apps/backend/src/routes/connect.ts. First,generateState()called
randomBytesfrom Node'scryptomodule without ever importing it, meaning anyrequest to
GET /connect/githubwould throw aReferenceError: randomBytes is not definedat runtime and crash the entire GitHub connect flow. Second, the helperfunction responsible for decoding the OAuth state in the GitHub callback was named
parseGoogleStatedespite Google connect not existing anywhere in this file — amisleading name that could confuse any developer maintaining or extending this code.
Both issues are fixed in this PR with minimal, targeted changes.
Closes #178
Type of Change
What Changed
apps/backend/src/routes/connect.ts— addedimport { randomBytes } from 'crypto'at the top of the file so
generateState()no longer throws aReferenceErroratruntime on any
GET /connect/githubrequest.apps/backend/src/routes/connect.ts— renamedparseGoogleStatetoparseOAuthStateat both its declaration (line 158) and its single call site(line 64) inside the
/github/callbackhandler to accurately reflect its purpose.How to Test
GET /connect/githubwith a valid auth token — confirm itpreviously crashed with
ReferenceError: randomBytes is not defined.GET /connect/githubwith a valid auth token — confirm itredirects to GitHub's OAuth page without errors.
the state correctly and stores the token successfully.
parseGoogleState— confirm no references remain.Checklist
pnpm -r run lintpasses).pnpm -r run typecheck).pnpm -r run test).console.logor debug statements left in the code.Screenshots / Recordings
N/A — backend bug fix with no UI changes.
Additional Context
The rename from
parseGoogleStatetoparseOAuthStateis a non-breaking change —the function is private to this module (not exported) and has exactly one call site,
which is updated in the same commit. No other files reference this function. The
randomBytesimport is the more critical of the two fixes since it represents aguaranteed runtime crash on every connect attempt — the rename is a correctness and
maintainability fix on top of that.
Please add the appropriate labels so that I can get GSSoC points.