Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XSS False positive inside = javascript_tag #1886

Open
kwerle opened this issue Nov 25, 2024 · 1 comment
Open

XSS False positive inside = javascript_tag #1886

kwerle opened this issue Nov 25, 2024 · 1 comment

Comments

@kwerle
Copy link

kwerle commented Nov 25, 2024

It seems like anything inside a javascript_tag that starts with escape_javascript should be safe, right?
(note that we customize our javascript_tag method to add some content to it)
Methods and classes mostly anonymized.

== Brakeman Report ==

Application Path: /code
Rails Version: 7.0.8.5
Brakeman Version: 6.2.2
...

== Overview ==

...

== Warning Types ==

Cross-Site Scripting: 1

== Warnings ==

Confidence: Weak
Category: Cross-Site Scripting
Check: CrossSiteScripting
Message: Unescaped parameter value
Code: escape_javascript(RailsClass.new(RailsClass2.find(params[:some_param_id])).some_method((current_user and current_user.some_method).things.find(params[:some_id])).some_method)
File: app/views/explore/display_options/_some_partial.html.haml
Line: 30

Code sketch:

  = javascript_tag do
    :plain
      ...
      my_function('#{escape_javascript(some_object.some_method)}');
      ...
@presidentbeef
Copy link
Owner

It seems like anything inside a javascript_tag that starts with escape_javascript should be safe, right?

That would be nice, but no. I wrote a blog post about it a while back: https://blog.presidentbeef.com/blog/2020/05/12/why-escape-javascript-is-dangerous/

Last time I checked, the only safe use is the code you have here - within a JavaScript string. So this is a false positive.

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

No branches or pull requests

2 participants