Skip to content

Conversation

@dauglyon
Copy link
Collaborator

@dauglyon dauglyon commented Jan 9, 2026

Summary

  • Adds support for nextRequest to redirect to external URLs on whitelisted domains after login
  • Enables cross-subdomain redirects (e.g., from narrative.kbase.us to hub.berdl.kbase.us)
  • Maintains security by validating URLs against a configurable whitelist

How to Whitelist URLs for Redirect

1. Configure the whitelist in config.json

Add a redirect_whitelist array to any environment that needs external redirects:

{
  "environments": {
    "production": {
      "domain": "narrative.kbase.us",
      ...
      "redirect_whitelist": ["*.berdl.kbase.us"]
    }
  }
}

2. Wildcard patterns

  • *.berdl.kbase.us - Matches hub.berdl.kbase.us, hub.dev.berdl.kbase.us, etc.
  • *.kbase.us - Matches any *.kbase.us subdomain
  • hub.berdl.kbase.us - Matches exact domain only
  • TLD-only wildcards like *.com are rejected for security

3. Usage

Pass the full external URL as the nextRequest parameter:

/login?nextRequest=https://hub.berdl.kbase.us/somepath

After successful login, the user will be redirected to the external URL.

Security

  • Only HTTPS URLs are allowed
  • URLs not matching the whitelist are blocked with a toast notification
  • Blocked redirects fall back to /narratives
  • Wildcard patterns must have at least 2 domain parts after the wildcard

Test plan

  • Verify external redirect works with whitelisted domain
  • Verify non-whitelisted external URLs are blocked with toast
  • Verify internal nextRequest (JSON-encoded paths) still works
  • Verify HTTP URLs are blocked

@dauglyon dauglyon force-pushed the add-external-redirect-whitelist branch from 93198bf to 2caa2f6 Compare January 9, 2026 21:47
Allow nextRequest parameter to redirect to external URLs on whitelisted
domains after login. This enables cross-subdomain redirects (e.g., from
narrative.kbase.us to hub.berdl.kbase.us) while maintaining security.

Features:
- Configurable whitelist via redirect_whitelist in config.json
- Wildcard support (e.g., *.berdl.kbase.us)
- HTTPS-only enforcement
- TLD-only wildcards rejected for security (e.g., *.com blocked)
- Blocked redirects show toast and fall back to /narratives
@dauglyon dauglyon force-pushed the add-external-redirect-whitelist branch from 2caa2f6 to d778ff7 Compare January 9, 2026 21:55
@dauglyon dauglyon changed the title Add external URL redirect whitelist for nextRequest CDM-350 Add external URL redirect whitelist for nextRequest Jan 9, 2026
Handles case variations like HTTPS://, HTTP://, Https:// to prevent
potential issues with non-lowercase URL schemes.
Copy link
Member

@briehl briehl left a comment

Choose a reason for hiding this comment

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

I think there's a couple issues with possible hijacking.

@dauglyon dauglyon force-pushed the add-external-redirect-whitelist branch from a928690 to 8c5934d Compare January 15, 2026 18:25
@dauglyon dauglyon requested a review from briehl January 15, 2026 18:26
- Remove isValidWildcardPattern function (provided false sense of security)
- Trust whitelist as configured, only reject literal "*"
- Add default whitelist value (*.kbase.us) for local development
- Clarify .env header comment about config.json overwriting values
@dauglyon dauglyon force-pushed the add-external-redirect-whitelist branch from 8c5934d to 3bb3d54 Compare January 15, 2026 18:28
Copy link
Member

@briehl briehl left a comment

Choose a reason for hiding this comment

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

LGTM

@dauglyon dauglyon merged commit 680f6d9 into main Jan 15, 2026
2 checks passed
@dauglyon dauglyon deleted the add-external-redirect-whitelist branch January 15, 2026 22: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.

3 participants