Skip to content

Restrict redirect hosts in login flow#202

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/restrict-redirect-hosts-login-flow
Draft

Restrict redirect hosts in login flow#202
Copilot wants to merge 3 commits intomainfrom
copilot/restrict-redirect-hosts-login-flow

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 16, 2026

The redirect parameter in the auth callback was never validated, allowing redirects to arbitrary external hosts (open redirect).

Changes

Config

  • Added AllowedRedirectHosts []string to config.Auth, sourced from AUTH_ALLOWED_REDIRECT_HOSTS (comma-separated hostnames)

Auth Controller

  • AuthCallback now reads the request body, validates redirect before delegating to the provider, then restores the body for the provider to consume
  • New validateRedirect method enforces:
    • Relative paths (/foo) → always allowed
    • Protocol-relative URLs (//evil.com) → always rejected
    • Absolute URLs → allowed only if hostname is in AllowedRedirectHosts; when the list is empty, all absolute redirects are rejected
// AUTH_ALLOWED_REDIRECT_HOSTS=app.example.com,staging.example.com
type Auth struct {
    AllowedRedirectHosts []string `env:"ALLOWED_REDIRECT_HOSTS" envSeparator:","`
    // ...
}

Tests

  • TestValidateRedirect — unit tests covering relative, protocol-relative, allowed, and disallowed URL cases
  • TestAuthCallbackRejectsDisallowedRedirect — handler-level tests confirming disallowed absolute redirects return HTTP 400 while valid ones proceed to auth
Original prompt

This section details on the original issue you should resolve

<issue_title>Restrict redirect hosts in login flow</issue_title>
<issue_description>The redirect url right now is not validated against a list of restricted host names. A configuration has to be introduced restricting the hosts the user could be redirected to.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
Copilot AI changed the title [WIP] Add configuration to restrict redirect hosts in login flow Restrict redirect hosts in login flow Mar 16, 2026
Copilot AI requested a review from jeroenrinzema March 16, 2026 11:50

import (
"bytes"
"encoding/json"
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.

please use internal/http/json instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in c86e4df — replaced encoding/json with internal/http/json.

Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
Copilot AI requested a review from jeroenrinzema March 16, 2026 12:13
@jeroenrinzema jeroenrinzema force-pushed the main branch 2 times, most recently from f1f4c61 to 734e288 Compare March 22, 2026 10:01
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.

Restrict redirect hosts in login flow

2 participants