Repository navigation
(janitor/dedupe): consolidate bounded stream body reads in git-token-service - #7239
Open
kilo-code-bot[bot] wants to merge 1 commit into
Open
kilo-code-bot[bot] wants to merge 1 commit into
kilo-code-bot[bot] wants to merge 1 commit into
Conversation
Five near-identical implementations of the bounded JSON-body read (enforce a byte cap, validate Uint8Array chunks, cancel on overflow, strict UTF-8 decode) had drifted across bitbucket-api, bitbucket-code-review-service, gitlab-oauth-credential-refresher, gitlab-runtime-token-resolver, and the request entrypoint. Consolidate the size-limit and chunk-validation logic into a single lib/bounded-read module, leaving each caller's error mapping intact.
Contributor
Author
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (6 files)
Verified the consolidated Reviewed by deepseek-v4.1-flash · Input: 67.3K · Output: 16.9K · Cached: 600.7K Review guidance: REVIEW.md from base branch |
This branch has not been deployed
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
Five near-identical bounded JSON-body readers in
services/git-token-serviceeach re-implemented the same security-critical logic: enforce a byte cap while reading, validate that every chunk is aUint8Array, cancel the stream and fail closed when the cap is exceeded, and strict UTF-8 decode beforeJSON.parse.src/index.ts—readBoundedInternalJsonRequestsrc/bitbucket-api.ts—readBoundedJsonsrc/bitbucket-code-review-service.ts—readBoundedJsonsrc/gitlab-oauth-credential-refresher.ts—readBoundedJsonsrc/gitlab-runtime-token-resolver.ts—readBoundedProjectIdentityThese copies had already drifted (differing
reader.cancel()error handling, differingUint8Arraychunk guards, differing byte-cap constants and decode paths), so a fix to one would not reliably propagate to the others.Change
Introduce
src/lib/bounded-read.tswith:readBoundedJsonBody(stream, maxBytes)— bounded read + strict UTF-8 decode +JSON.parseResponseTooLargeError— the single signal callers use to distinguish overflow from other failuresEach caller becomes a thin adapter that keeps its own error type (
BitbucketApiError,BitbucketCodeReviewProviderError,Error, or anullreturn) and pre-flightContent-Length/Content-Typechecks. No runtime behavior changes: overflow still fails closed, invalid chunks still reject, and AbortSignal timeouts inbitbucket-apistill map torequest_timed_out.Net: 157 lines deleted, 22 added across callers plus one 51-line module.
Verification
pnpm --filter cloudflare-git-token-service typecheck— cleanpnpm -w exec oxlint ...on changed files — 0 errorspnpm --filter cloudflare-git-token-service test— 24 files, 662 tests passed