Repository navigation
fix(bitbucket): send redirect_uri on the authorize hop - #139
Merged
jhd3197 merged 1 commit intoSep 8, 2026
Merged
Conversation
generate_bitbucket_authorize_url() takes a redirect_uri and leaves it out of the query string, so Bitbucket returns the user to whatever callback is registered on the OAuth consumer rather than the one the panel asked for. complete_bitbucket_callback() then posts that same redirect_uri to the token endpoint, so the two halves of one flow name different callbacks. Both sibling generators in the same file send it (generate_github_authorize_url line 207, generate_gitlab_authorize_url line 446), as does generate_auth_url in sso_service.py; Bitbucket was the only one that dropped it. GET /source-connections/bitbucket/authorize already rejects a request without redirect_uri, so the value was always present and always discarded. Adds the parameter, plus a regression test parametrised over all three providers so the next one added is held to the same contract.
jhd3197
added a commit
that referenced
this pull request
Sep 8, 2026
jhd3197
added a commit
that referenced
this pull request
Sep 8, 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.
Description
SourceConnectionService.generate_bitbucket_authorize_urlaccepts aredirect_uriand never puts it in the authorize URL, so Bitbucket returns the operator to whatever callback is registered on the OAuth consumer instead of the panel origin the connect flow started from.The cause is the params dict at
backend/app/services/source_connection_service.py:613, which built the query string fromclient_id,response_typeandstateonly. The two siblings in the same file both send the caller's value:generate_github_authorize_urlat line 189 (line 207) andgenerate_gitlab_authorize_urlat line 436 (line 446), and so doesgenerate_auth_urlinbackend/app/services/sso_service.py:104(line 134). Bitbucket was the only one of the four authorize-URL builders in the backend that dropped it.Nothing else in the flow treats the value as optional.
GET /source-connections/bitbucket/authorizeanswers 400 without it (backend/app/api/source_connections.py:319), andcomplete_bitbucket_callbackposts that sameredirect_urito Bitbucket's token endpoint (backend/app/services/source_connection_service.py:649), so the authorize hop and the token hop currently name different callbacks. The panel derives the value fromwindow.location.origin(frontend/src/components/settings/connections/ConnectionsHub.jsx:108), so the callback it asks for is the origin the operator actually reached the panel at.The fix adds
'redirect_uri': redirect_urito the params dict so the Bitbucket authorize hop asks for the callback its own token exchange later claims.Related Issues
None.
Type of Change
How Has This Been Tested?
backend/tests/test_source_connection_oauth.pyis a new parametrised test asserting that every provider's authorize URL carries the caller'sredirect_uri, itsclient_idand its returnedstate. It is parametrised rather than written three times so a fourth provider is held to the same contract.Run against an unmodified
devcheckout it isolates the bug to Bitbucket:python -m pytest tests/test_source_connection_oauth.py -vgives1 failed, 2 passed, with the GitHub and GitLab cases green and the Bitbucket case failing onKeyError: 'redirect_uri'.With the fix, on macOS with Python 3.11.15 and
backend/requirements.txtpluspytest/pytest-split:python -m pytest tests/test_source_connection_oauth.py tests/test_github_app_manifest.py -qgives 11 passed.python -m pytest tests --splits 4 --group 4 -q, the Backend CI shard that collects the new test, gives 1370 passed, 50 skipped.python -m pytest tests --splits 4 --group 3 -qgives 1176 passed, 1 failed, 35 skipped. The failure istests/test_probe_honesty_metrics.py::test_one_failed_section_does_not_blank_the_others, which fails identically on an unmodifieddevcheckout on this machine because the CPU probe is unavailable here.python -m pytest tests/test_api_surface_inventory.py tests/test_route_authz_static.py tests/test_auth_decorator_boundaries.py tests/test_api_controller_boundaries.py tests/test_api_error_shape.py tests/test_redaction_one_door.py -qgives 28 passed.python tests/check_test_count.pyreportscollected=5095 baseline=5089, above the floor.python -m py_compile app/services/source_connection_service.py tests/test_source_connection_oauth.pypasses.No route was added or removed, so
docs/API_SURFACE.mdis unchanged.Checklist