fix(auth): JS-encode redirect_to to prevent XSS in auth_callback#1409
Open
failsafesecurity wants to merge 1 commit into
Open
fix(auth): JS-encode redirect_to to prevent XSS in auth_callback#1409failsafesecurity wants to merge 1 commit into
failsafesecurity wants to merge 1 commit into
Conversation
…allback
The auth_callback endpoint reflects the user-supplied redirect_to query
parameter into window.location.replace('...') without JavaScript string
encoding. The startswith(APP_URL) validation does not prevent JS-special
characters like ' ; ) from breaking the string context.
Fix:
- Apply json.dumps() to dashboard_url before template rendering so
the value is a safe JS string literal with embedded quotes and
special characters escaped.
- Validate the invite parameter with a strict alphanumeric regex before
incorporating into the redirect URL.
- Remove outer single-quotes in the template since json.dumps includes them.
Signed-off-by: FailSafe Researcher <joshua@getfailsafe.com>
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.
Summary
This PR fixes a Reflected XSS vulnerability in the OAuth callback endpoint (
/auth/callback).Severity: HIGH
CWE: CWE-79 (Improper Neutralization of Input During Web Page Generation — Cross-site Scripting)
CVSS: 8.1 (AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N)
Vulnerability
The
/auth/callbackendpoint is a public OAuth redirect handler that:redirect_toquery parameterstartswith(APP_URL)— which does not prevent JavaScript-special characters<script>block via Jinja2 without JavaScript string encoding (autoescape is disabled)The template renders:
An attacker can bypass the
startswithcheck with a URL like:During an OAuth login flow,
location.hashcontains#access_token=...&refresh_token=..., enabling session token theft via this XSS.The
invitequery parameter is equally injectable (it's embedded into the redirect URL without validation before thestartswithcheck is applied).Fix
app/api/agentops/auth/views.py:json.dumps()toredirect_tobefore template rendering — this produces a JavaScript-safe quoted string literal with',", and other JS-special characters properly escapedinviteparameter with a strict alphanumeric regex before incorporating it into the redirect URLapp/api/agentops/auth/templates/auth_callback.html:window.location.replace('{{ dashboard_url }}')sincejson.dumpsalready includes the enclosing quotesTesting
Reported by FailSafe Security Research. Please contact security@agentops.ai for coordinated disclosure details.