Skip to content

Commit

Permalink
fix(ruby): only consider inline disposition as xss for send_data (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
didroe authored Apr 2, 2024
1 parent 43741ab commit 0a40950
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
14 changes: 13 additions & 1 deletion rules/ruby/rails/render_using_user_input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@ patterns:
- variable: USER_INPUT
detection: ruby_shared_common_html_user_input
scope: result
- pattern: send_data($<USER_INPUT>$<...>)
- pattern: |
send_data($<USER_INPUT>, disposition: $<DISPOSITION>)
filters:
- variable: USER_INPUT
detection: ruby_shared_common_html_user_input
scope: result
- not:
variable: DISPOSITION
detection: ruby_rails_render_using_user_input_attachment
scope: cursor
auxiliary:
- id: ruby_rails_render_using_user_input_attachment
patterns:
- pattern: $<VALUE>
filters:
- variable: VALUE
string_regex: \Aattachment\z
severity: high
metadata:
description: "Unsanitized user input in raw HTML strings (XSS)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
render html: sanitize(params[:oops])
render inline: "<h1>#{strip_tags(params[:oops])}</h1>"

send_data "ok", type: content_type
send_data params[:user_input], type: content_type
send_data params[:user_input], type: content_type, disposition: "attachment"
4 changes: 3 additions & 1 deletion tests/ruby/rails/render_using_user_input/testdata/unsafe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
render inline: "<h1>#{params[:oops]}</h1>"

# bearer:expected ruby_rails_render_using_user_input
send_data params[:oops], type: content_type
send_data params[:user_input], type: content_type, disposition: "inline"
# bearer:expected ruby_rails_render_using_user_input
send_data params[:user_input], type: content_type, disposition: unknown

0 comments on commit 0a40950

Please sign in to comment.