Skip to content

Refuse a cross-origin redirect of the OAuth2 user info request - #350

Merged
umputun merged 2 commits into
masterfrom
oauth2-info-redirect-guard
Nov 28, 2026
Merged

umputun merged 2 commits into
masterfrom
oauth2-info-redirect-guard

Conversation

@umputun

@umputun umputun commented Nov 28, 2026

Copy link
Copy Markdown
Member

follow-up to #349. The oauth2 transport adds the user's access token to every redirect hop, so a user info URL that answered with a redirect could send the token across origins. That path predates #349, which only covered the avatar fetch.

  • the user info request now uses a copy of the oauth2 client whose redirect policy runs the client's own CheckRedirect first and keeps its errors. With that passed, it stops at a hop off the scheme, host and port of InfoURL, and, when the client has no policy, before the eleventh request. A refusal by this guard answers the login with 503 and logs only the redirect status, so a signed Location stays out of the log
  • same-origin redirects are still followed with the token, and the avatar client keeps its own redirect policy
  • README gets a behaviour change note for custom providers: a cross-origin info redirect, http:// to https:// on the same host included, now fails the login. To follow a same-origin redirect on an internationalized host, write the host in its xn-- form in InfoURL and in any absolute redirect target
  • drops the unreachable Transport nil check in avatarClient and the comments in the avatar tests

v1 and v2 carry the same change.

The oauth2 transport adds the access token to every redirect hop, so a user
info URL answering with a redirect to another host sent the token there. The
info request now uses a copy of the client whose redirect policy runs any
existing CheckRedirect first, keeps the default 10-hop cap when there is none,
and stops at a hop off the scheme, host and port of InfoURL. The login then
fails with 503 and logs only the redirect status, so a signed Location stays
out of the log. The avatar client keeps its own redirect policy.

Also drops the unreachable Transport nil check in avatarClient and the
comments in the avatar tests.
With no client redirect policy, the 10-hop cap returned a plain error
before the origin check. Go's HTTP client wraps that error with the raw
Location of the refused hop, and the login handler logs it, so a signed
URL on the hop past the cap reached the log. The cap now stops with the
last redirect response, like the origin refusal, and the login answers
503 with only the status in the log.

The README note on the refused redirects becomes a versioned behaviour
change block, with the HTTP-to-HTTPS case and the xn-- form for redirect
targets.
@coveralls

coveralls commented Nov 28, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 46100781025

Coverage decreased (-0.2%) to 88.598%

Details

  • Coverage decreased (-0.2%) from the base build.
  • Patch coverage: 19 of 19 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4201
Covered Lines: 3722
Line Coverage: 88.6%
Coverage Strength: 20.3 hits per line

💛 - Coveralls

@umputun
umputun merged commit fdc5239 into master Nov 28, 2026
7 of 9 checks passed
@umputun
umputun deleted the oauth2-info-redirect-guard branch November 28, 2026 03:06
umputun added a commit that referenced this pull request Nov 28, 2026
…Telegram GetUpdates error path (#351)

* Report coverage to Coveralls from the v2 workflow only

When both workflows ran, they uploaded separate v1 and v2 profiles to
the same Coveralls repo. A PR could then be compared with a master
build for the other module: #350 showed -0.2% while its v1 coverage went
up. The v1 workflow now keeps its coverage profile but no longer
uploads it, and drops the statuses permission only goveralls used.

* Test that Telegram keeps polling after a GetUpdates error

Coverage of the GetUpdates error path depended on poll timing in the
confirmed-request test, so the same commit reported different coverage
from run to run. A test with a GetUpdates that always fails now takes
the log-and-continue branch of the Run poll loop on every run and checks
that polling goes on after the error.

* Add backlog items for two Telegram Run defects

Run keeps its running mark after a BotInfo error, which blocks a later
ProcessUpdate, and an init timeout in setupHandler skips cancel and
join, which can leave Run running. Both surfaced in the review of this
branch and predate it.
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.

2 participants