| Domain-Driven Design (DDD) :👈 | 👉:Dry Run in Program |
Redirect URIs and Open Redirect Attacks |
Redirect URIs and Open Redirect Attacks
1. Redirect URIs
A Redirect URI is the exact URL in your application where an authorization server (e.g., OAuth 2.0 / OpenID Connect provider) sends the user after authentication or consent. It is a critical part of OAuth flows because it is where authorization codes or tokens are delivered.
Why It Matters
- Ensures the authorization response is sent to the correct application endpoint.
- Prevents attackers from intercepting tokens by redirecting them to malicious sites.
- OAuth/OIDC providers require preāregistration of allowed redirect URIs.
Example in OAuth
- User clicks āLogin with Googleā on
https://myapp.com. - Google authenticates the user.
-
Google redirects the user to the registered redirect URI:
https://myapp.com/auth/callback?code=AUTH_CODE
- The app exchanges the
AUTH_CODEfor an access token.
Security Best Practices
- Allow only exact, preāregistered redirect URIs (no wildcards).
- Use HTTPS to prevent token leakage.
- Do not allow userācontrolled parameters to alter the redirect target.
Safe Redirect Flow Diagram
2. Open Redirect Attacks
An Open Redirect occurs when an application takes a userāsupplied URL and redirects to it without proper validation. Attackers can exploit this to send users to malicious sites while making the link appear to come from a trusted domain.
How It Works
-
Legitimate site has a redirect endpoint:
https://trusted.com/redirect?url=https://trusted.com/home
-
Attacker changes the parameter:
https://trusted.com/redirect?url=https://evil.com/login
- Victim clicks the link, sees the trusted domain, and is redirected to the attackerās site.
- Attacker can phish credentials, deliver malware, or steal tokens.
Example in Login Flows
Many apps use a returnUrl or next parameter to send users back after login:
https://trusted.com/login?returnUrl=/dashboard
If not validated, an attacker could set:
https://trusted.com/login?returnUrl=https://evil.com/fake-login
Risks
- Phishing: Users trust the initial domain in the link.
- Token Theft: In OAuth, can steal authorization codes or tokens.
- Privilege Escalation: May bypass access controls if redirects lead to privileged pages.
Prevention Strategies
- Whitelist redirects to known, trusted URLs.
- Use relative paths (
/path) instead of full URLs for internal redirects. - Validate hostnames to ensure they match your domain.
- In ASP.NET Core, use
Url.IsLocalUrl()before redirecting. - Avoid userācontrolled redirects where possible.
Open Redirect Exploit Flow Diagram
3. Key Differences
| Aspect | Redirect URI | Open Redirect Attack |
|---|---|---|
| Purpose | Legitimate OAuth/OIDC callback endpoint | Exploit to send users to malicious sites |
| Control | Preāregistered, exact match | Userācontrolled parameter |
| Risk | Token leakage if misconfigured | Phishing, token theft, malware delivery |
| Prevention | Strict registration & HTTPS | Whitelisting, validation, relative paths |
| Domain-Driven Design (DDD) :👈 | 👉:Dry Run in Program |
Comments and Discussion