fix(auth): JS-encode redirect_to to prevent XSS in auth_callback - #1409
fix(auth): JS-encode redirect_to to prevent XSS in auth_callback#1409failsafesecurity 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>
|
Hi maintainers 👋 This vulnerability was found by FailSafe — a top agentic cybersecurity company specializing in automated deep security analysis of AI/ML and agentic codebases. We're reporting these initial findings as a social good contribution to help secure the open-source AI ecosystem. If you'd like us to perform a deeper, more comprehensive security scan of your project, we'd love to hear from you — reach out at joshua@getfailsafe.com. Thanks for maintaining this project! 🙏 |
|
Thanks for reviewing this security fix. Just a friendly ping — this PR has been open for a while. Happy to adjust the approach if you have any concerns. No rush, just want to make sure it stays on your radar. |
|
Friendly follow-up on this security PR. It has been open for a while without human reviewer feedback. Happy to rebase, trim the patch, or adjust the approach if that helps. Thanks for taking a look. |
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.