Skip to content

fix(auth): authenticate after same-host HTTPS upgrades - #1663

Merged
TerryHowe merged 1 commit into
oras-project:mainfrom
ykakade:fix/1245-same-host-https-auth
Oct 22, 2026
Merged

TerryHowe merged 1 commit into
oras-project:mainfrom
ykakade:fix/1245-same-host-https-auth

Conversation

@ykakade

@ykakade ykakade commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #1245

auth.Client can authenticate after a same-host HTTP-to-HTTPS redirect on the standard ports (80 to 443). It retries the HTTPS endpoint directly and preserves the redirected method and body.

The origin check rejected the HTTPS challenge because the scheme changed. The retry also started from the original HTTP URL.

The exception checks every redirect hop. Host, nonstandard port, and repository changes still block authentication, as do HTTPS downgrades. Redirects still strip Authorization. Bearer realm validation uses the HTTPS URL.

Credentials obtained after an upgrade are not cached. The cache keys omit the scheme, so caching them could send them over HTTP on a later request. This costs another authentication exchange for each upgrade.

Before / after

The regression tests use local HTTP and TLS servers with test credentials. The same tests run against main through a Go source overlay, then against this branch.

Before:

--- FAIL: TestClient_Do_HTTPSUpgrade/Basic/GET
    Client.Do() status = 401, want 200
    HTTP calls = 2, authenticated HTTPS calls = 0, want 2 each
--- FAIL: TestClient_Do_HTTPSUpgrade/Bearer/GET
    Client.Do() status = 401, want 200
    token calls = 0, want 2

After:

$ go test -race ./registry/remote/auth -run HTTPSUpgrade -count=1
ok  github.com/oras-project/oras-go/v3/registry/remote/auth

Checklist

  • Retry Basic and Bearer authentication at the upgraded HTTPS endpoint
  • Test POST redirects, repeated requests with a shared cache, and redirect boundaries
  • Reject an HTTP bearer realm after the HTTPS upgrade
  • Document the port restriction and cache behavior on Client.Do
  • Run make test with race detection and coverage on Go 1.27.2
  • Run go vet ./...

Retry the upgraded HTTPS endpoint after its authentication challenge.
Check every redirect hop and keep upgraded credentials out of the cache
so later HTTP requests do not reuse them.

Fixes oras-project#1245

Signed-off-by: Yash2017 <[email protected]>

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.67%. Comparing base (b301ef8) to head (e90bc42).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1663      +/-   ##
==========================================
+ Coverage   92.65%   92.67%   +0.02%     
==========================================
  Files         112      112              
  Lines        9307     9335      +28     
==========================================
+ Hits         8623     8651      +28     
  Misses        674      674              
  Partials       10       10              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe
TerryHowe marked this pull request as ready for review October 22, 2026 10:15
@TerryHowe
TerryHowe merged commit 9f14282 into oras-project:main Oct 22, 2026
12 checks passed
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.

Re-support same-host http-to-https redirect

2 participants