Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions oauth2/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,22 @@

// Note: redirect_uri is validated against client.RedirectURIs in handleAuthorizationGet
// BEFORE this function is called. External URIs are allowed if they're registered.
//
// As a defense-in-depth measure, ensure we only redirect to relative URLs or to the
// same host as the current request. This prevents open redirects if this helper is
// ever called with an unvalidated absolute URL.
if u.IsAbs() && u.Hostname() != "" {
// Extract hostname from r.Host (which may include a port).
requestHost := r.Host
if h, _, splitErr := strings.Cut(requestHost, ":"); splitErr == nil {

Check failure on line 754 in oauth2/handlers.go

View workflow job for this annotation

GitHub Actions / lint / lint

invalid operation: splitErr == nil (mismatched types bool and untyped nil) (typecheck)

Check failure on line 754 in oauth2/handlers.go

View workflow job for this annotation

GitHub Actions / ci / test (1.26.x, macos-latest)

invalid operation: splitErr == nil (mismatched types bool and untyped nil)

Check failure on line 754 in oauth2/handlers.go

View workflow job for this annotation

GitHub Actions / ci / test (1.26.x, ubuntu-latest)

invalid operation: splitErr == nil (mismatched types bool and untyped nil)

Check failure on line 754 in oauth2/handlers.go

View workflow job for this annotation

GitHub Actions / ci / test (1.25.x, ubuntu-latest)

invalid operation: splitErr == nil (mismatched types bool and untyped nil)

Check failure on line 754 in oauth2/handlers.go

View workflow job for this annotation

GitHub Actions / ci / test (1.25.x, macos-latest)

invalid operation: splitErr == nil (mismatched types bool and untyped nil)
requestHost = h
}

if !strings.EqualFold(u.Hostname(), requestHost) {
s.renderLoginError(w, description)
return
}
}

q := u.Query()
q.Set("error", errCode)
Expand Down
Loading