fix(git-token-service): restore Bitbucket code-review API access - #6130
Merged
Conversation
…apability The bb CLI calls https://api.bitbucket.org while the Bitbucket session capability validator only allowed the git origin https://bitbucket.org, so every REST API redemption failed with upstream_origin_not_allowed and reviews collapsed to provider_unavailable. Classify the redeemed upstream as a git or API surface, validate the API path under /2.0/repositories/<workspace>/<repo>, and return Bearer auth for the API surface while keeping Basic x-token-auth for git.
…oded slashes The %2f/%5c and traversal guard ran against the whole request URL, including the query string. bb pr current carries the branch name in the q= filter, so a branch containing a slash arrived as %2F and the redeem rejected it as invalid_upstream_url, surfacing as bb: provider_unavailable. A query string cannot change how the path resolves against the repository prefix, so scan only the pre-query portion. Path-level rejections are unchanged.
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryReviewed the Bitbucket capability origin allowlist, git/API surface classification, Bearer redemption, and pre-query path guard changes plus the added tests; the origin checks, repository-prefix matching, and traversal/encoded-slash handling are correct and consistent with the current GitLab capability handling. Files Reviewed (2 files)
Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |
marius-kilocode
approved these changes
Sep 14, 2026
This was referenced Sep 14, 2026
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
Restores managed Bitbucket code-review sessions, which were running and reporting Completed while posting no PR comments.
Root cause (verified in production). In contained sessions
BITBUCKET_TOKENis an opaque capability (kbb1.…), and everybbrequest is intercepted and redeemed by the Worker. ThebbCLI calls the Bitbucket Cloud REST API athttps://api.bitbucket.org, butvalidateBitbucketCapabilityUpstreamonly accepted the git originhttps://bitbucket.org. Every API read/write was rejected withupstream_origin_not_allowed, the interceptor returned502, and the CLI collapsed that intobb: provider_unavailable. Git clone/fetch tobitbucket.orgstill worked, so the workspace cloned and the review then did nothing.cloudflare-logpush,cloud-agent-next):Managed Bitbucket outbound redemption rejected,failureStage=redemption-policy,reason=upstream_origin_not_allowed, hundreds/day over the 30-day window (121 on 2026-09-14). Forwarded =target=bitbucket(git); rejected =target=other(api.bitbucket.org), same container.ses_f61349404fffAm3oxDuyaWElZg:bb pr view/diff/comments listall returnedprovider_unavailable. 4/4 recent Bitbucket sessions sampled failed the same way.Fix — two commits:
aba2d6117— classify the redeemed upstream as a git or API surface. The API surface requires originhttps://api.bitbucket.organd a path under/2.0/repositories/<workspace>/<repo>matching the capability's canonical repository name (exact segment boundary), and returnsBearer <token>; git keepsBasic x-token-auth:<token>.cloud-agent-nextneeds no change:forwardRedeemedRequestdeletesAuthorizationand appliesresult.headers.94098700e— the%2f|%5c/traversal guard ran against the whole URL including the query string.bb pr currentcarries the branch name inq=, so a slash branch arrived as%2Fand was rejected asinvalid_upstream_url. A query string cannot change how the path resolves against the repository prefix, so the guard now scans only the pre-query portion. Path-level rejections are unchanged.Verification
Automated, run from the worktree:
pnpm --filter cloudflare-git-token-service test— 24 files, 646 passed.Bearersuccess and APIrepository_mismatchcases failed withupstream_origin_not_allowed; the query-%2Ftest failed withinvalid_upstream_url) and pass with the fix.Bearer+ sub-resource; repo/workspace/segment-prefix mismatch →repository_mismatch;http, credentials-in-URL, hash, traversal,%2f,%2e%2e→invalid_upstream_url; unapproved origin; git smart-HTTP stillBasic; encoded slash allowed in the API query string.typecheckexit 0;lint0 warnings / 0 errors;oxfmt --list-differentclean;git diff --checkclean.No manual/end-to-end run: this is an auth path inside the deployed
git-token-service, so there is no manual path short of deploying. It only takes effect once deployed.Visual Changes
N/A
Reviewer Notes
bbendpoints. It is bounded to that repository and the capability's scope; an endpoint allowlist is a hardening follow-up, not required for the fix.%2f-in-query path (bb pr current/pr create) is latent today: no skill or prompt currently calls those commands, so it is not part of the reported outage.bbcollapsing a 5xx and a network failure into the sameprovider_unavailablestring made this slower to localise; a diagnosability follow-up, deliberately out of scope.