fix open redirect vulnerability in OAuth callback handler#265
Draft
semgrep-code-rootflo[bot] wants to merge 1 commit intodevelopfrom
Draft
fix open redirect vulnerability in OAuth callback handler#265semgrep-code-rootflo[bot] wants to merge 1 commit intodevelopfrom
semgrep-code-rootflo[bot] wants to merge 1 commit intodevelopfrom
Conversation
Add URL validation to prevent open redirect attacks in the OAuth callback flow. ## Changes - Added `validate_redirect_url()` function to `user_utils.py` that validates redirect URLs by: - Ensuring only `http`/`https` schemes are allowed - Requiring a valid host (netloc) - Blocking protocol-relative URL bypasses (e.g., `//evil.com`) - Blocking backslash-based bypasses (e.g., `/\evil.com`) - Blocking URLs with embedded credentials (e.g., `https://attacker@victim.com`) - Supporting optional domain allowlist validation - Updated `auth_plugin_controller.py` to validate `success_url` and `failure_url` before using them in `RedirectResponse` - Invalid URLs now fall back to `about:blank` instead of redirecting to potentially malicious domains ## Why The `client_redirect_success_url` and `client_redirect_failure_url` values from configuration were being used directly in `RedirectResponse` without validation. An attacker who could control these configuration values could redirect users to malicious domains, enabling phishing attacks or credential theft. The new validation ensures all redirect URLs are safe before use. ## Semgrep Finding Details The application builds a URL using user-controlled input which can lead to an open redirect vulnerability. An attacker can manipulate the URL and redirect users to an arbitrary domain. Open redirect vulnerabilities can lead to issues such as Cross-site scripting (XSS) or redirecting to a malicious domain for activities such as phishing to capture users' credentials. To prevent this vulnerability perform strict input validation of the domain against an allowlist of approved domains. Notify a user in your application that they are leaving the website. Display a domain where they are redirected to the user. A user can then either accept or deny the redirect to an untrusted site. @18578539 requested Semgrep Assistant generate this pull request to fix [a finding](https://semgrep.dev/orgs/rootflo_ai/findings/683091413) from the detection rule [python.fastapi.web.tainted-redirect-fastapi.tainted-redirect-fastapi](https://semgrep.dev/r/python.fastapi.web.tainted-redirect-fastapi.tainted-redirect-fastapi).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add URL validation to prevent open redirect attacks in the OAuth callback flow.
Changes
validate_redirect_url()function touser_utils.pythat validates redirect URLs by:http/httpsschemes are allowed//evil.com)/\evil.com)https://attacker@victim.com)auth_plugin_controller.pyto validatesuccess_urlandfailure_urlbefore using them inRedirectResponseabout:blankinstead of redirecting to potentially malicious domainsWhy
The
client_redirect_success_urlandclient_redirect_failure_urlvalues from configuration were being used directly inRedirectResponsewithout validation. An attacker who could control these configuration values could redirect users to malicious domains, enabling phishing attacks or credential theft. The new validation ensures all redirect URLs are safe before use.Semgrep Finding Details
The application builds a URL using user-controlled input which can lead to an open redirect vulnerability. An attacker can manipulate the URL and redirect users to an arbitrary domain. Open redirect vulnerabilities can lead to issues such as Cross-site scripting (XSS) or redirecting to a malicious domain for activities such as phishing to capture users' credentials. To prevent this vulnerability perform strict input validation of the domain against an allowlist of approved domains. Notify a user in your application that they are leaving the website. Display a domain where they are redirected to the user. A user can then either accept or deny the redirect to an untrusted site.
@18578539 requested Semgrep Assistant generate this pull request to fix a finding from the detection rule python.fastapi.web.tainted-redirect-fastapi.tainted-redirect-fastapi.