Skip to content

fix: re-authenticate smart HTTP redirects#2686

Merged
Sebastian Thiel (Byron) merged 3 commits into
mainfrom
try-redirect-re-auth
Jul 2, 2026
Merged

fix: re-authenticate smart HTTP redirects#2686
Sebastian Thiel (Byron) merged 3 commits into
mainfrom
try-redirect-re-auth

Conversation

@Byron

@Byron Sebastian Thiel (Byron) commented Jul 1, 2026

Copy link
Copy Markdown
Member

Tasks

This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.

  • refackiew
  • gix clone https://tangled.org/me.webbeef.org/beaver now works

Everything below this line was generated by Codex GPT-5.

Created by Codex on behalf of Byron. Byron will review before this is ready to merge.

Fixes #2685.

Summary

This updates smart HTTP redirect handling so accepted initial redirects become visible to the transport/authentication layer instead of staying hidden inside the HTTP backend. After a redirect, the HTTP transport updates its canonical URL, clears credentials unless the old and new authorities are safe for reuse, and lets the existing handshake authentication retry obtain credentials for the redirected URL.

Git baseline: http.c in /Users/byron/dev/github.com/git/git derives redirected bases from the requested tail in update_url_from_redirect() and re-keys credentials from the effective URL in http_request_recoverable().

Changes

  • Added Http::redirected_base_url() with a default None implementation.
  • Shared curl and reqwest redirected base state with their outer backend objects.
  • Split redirect base reconciliation from auth reuse safety.
  • Allowed safe cross-authority redirects with matching requested tails while still rejecting unsafe downgrades such as https to http.
  • Updated HTTP transport URL/identity state after redirected handshake success, relevant handshake errors, and POST setup.
  • Disabled backend auto-follow when configured extra headers or reqwest request hooks could be replayed to a redirected authority.
  • Rebuilt configured credential helper cascades per Action::Get URL, keeping immediate store/erase paired with that same URL.
  • Strengthened the GHSA-style redirect regression so the redirected POST must actually hit the redirected host without original Basic auth.

Validation

  • cargo test -p gix-transport --features "http-client-curl http-client-insecure-credentials maybe-async/is_sync" --test blocking-transport-http-only relative_redirected_handshake_updates_url_before_returning -- --nocapture
  • cargo fmt --all --check
  • cargo test -p gix-transport --features "http-client-curl http-client-insecure-credentials maybe-async/is_sync" --test blocking-transport-http-only
  • cargo test -p gix-transport --features "http-client-reqwest http-client-insecure-credentials maybe-async/is_sync" --test blocking-transport-http-reqwest
  • cargo test -p gix-transport --features "http-client-curl maybe-async/is_sync" redirect::tests
  • cargo test -p gix --features credentials repository::config::config_snapshot::credential_helpers
  • cargo test -p gix-transport --tests
  • cargo check -p gix-transport --no-default-features --features "blocking-client http-client-reqwest maybe-async/is_sync"
  • cargo check -p gix-transport --no-default-features --features "blocking-client http-client-curl http-client-insecure-credentials maybe-async/is_sync"
  • codex review --commit 67e7af7f8a293d5c80f8132a8d0473129e5c6062

Manual Tangled network clone check was not run.

@Byron
Sebastian Thiel (Byron) force-pushed the try-redirect-re-auth branch 7 times, most recently from ec82e66 to 334c2e7 Compare July 2, 2026 08:24
@Byron
Sebastian Thiel (Byron) marked this pull request as ready for review July 2, 2026 08:24

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 334c2e75b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread gix-transport/src/client/blocking_io/http/curl/remote.rs
Sebastian Thiel (Byron) and others added 3 commits July 2, 2026 16:58
Issue #2685 reports that cloning a repository behind a Tangled initial
smart-HTTP redirect fails because gix rejects cross-authority redirected
bases. Git allows this class of initial redirect, but updates the effective
base URL and re-keys credential state to that redirected base before retrying
authentication or issuing follow-up RPCs.

Git baseline: git/git/http.c update_url_from_redirect() derives the redirected
base from the requested tail, and http_request_recoverable() then calls
credential_from_url() for the new base.

The regression coverage now requires a cross-host redirected handshake to be
followed, requires the follow-up POST to target the redirected host, verifies
the original Basic identity is cleared, and verifies a redirected 401 updates
TransportWithoutIO::to_url() before the authentication retry path observes it.
Redirect helper unit tests cover cross-authority base reconciliation, auth reuse
safety, and https-to-http rejection.

The fix exposes redirected backend base URLs through the Http trait, shares
curl/reqwest worker redirect state with their outer backend objects, lets base
reconciliation accept safe cross-authority redirects with matching tails, keeps
identity reuse limited to same authority or same-host http-to-https upgrades,
updates the HTTP transport URL and identity from the effective base, relaxes
reqwest redirect policy accordingly, and rebuilds configured credential helper
cascades from each Get action URL.

Validation:
- cargo test -p gix-transport --features "http-client-curl http-client-insecure-credentials maybe-async/is_sync" --test blocking-transport-http-only redirected_
- cargo test -p gix-transport --features "http-client-curl maybe-async/is_sync" redirect::tests
- cargo test -p gix-transport --features "http-client-reqwest http-client-insecure-credentials maybe-async/is_sync" --test blocking-transport-http-reqwest
- cargo test -p gix --features credentials repository::config::config_snapshot::credential_helpers
- cargo test -p gix-transport --features "http-client-curl http-client-insecure-credentials maybe-async/is_sync" --test blocking-transport-http-only
- cargo test -p gix-transport --tests
- git diff --check
Co-authored-by: Sebastian Thiel <[email protected]>
It extracts the URL from the input action, which is relevant in case
of redirects which changes the initial url.

Co-authored-by: Sebastian Thiel <[email protected]>
@Byron
Sebastian Thiel (Byron) merged commit d8aeaac into main Jul 2, 2026
30 of 31 checks passed
@Byron

Copy link
Copy Markdown
Member Author

After 43m I have force-merged this PR as the ARM runner seems to have failed silently again. It really looks like it has issues: https://github.com/GitoxideLabs/gitoxide/actions/runs/28578072792/job/84731323802?pr=2686.

What do you think Eliah Kagan (@EliahKagan), is it time to disable or neutralize it?

@Byron
Sebastian Thiel (Byron) deleted the try-redirect-re-auth branch July 2, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gix clone https://tangled.org/... fails due to redirect but works fine with git

2 participants