view-cross-site-scripting
Input a view prints unescaped or writes into a script.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule view-cross-site-scripting - Level
- warning
- Reads
- Every file
- Fix
- None: the safe form depends on where the value is written
Why
An ERB, HAML, or Slim view prints a value from a request with <%==, !=, ==, raw, or html_safe, writes one into a script element, where HTML escaping does not stop it from ending a JavaScript string, or runs a script that writes the page's address into it, so whoever sends the request or the link can put scripts in the page. Let the view escape what it prints, and pass a value to a script as JSON with json_escape or a data attribute.
The fix, as Ur suggests it: let the view escape it, or pass it as JSON.
For agents
Never print input unescaped in a view or write it into a script; escape it, or pass it as JSON.
Example
Gemfile.lockGEM
remote: https://rubygems.org/
specs:
rails (8.1.0)
PLATFORMS
ruby
DEPENDENCIES
rails
app/views/search/index.html.erb<h1>Search</h1>
<p>Results for <%== params[:q] %></p>
$ ur scan --rule view-cross-site-scripting
warning[view-cross-site-scripting]: `params`, a request parameter, reaches `raw`
--> ./app/views/search/index.html.erb:2:21 view
= step 1: ./app/views/search/index.html.erb:2:21 `params`, a request parameter,
= hint: let the view escape it, or pass it as JSON
= see: Securing Rails Applications, 7.3 Cross-Site Scripting (XSS), Rails Guides (2025-10-01), https://guides.rubyonrails.org/security.html#cross-site-scripting-xss
scanned 1 file (no framework recognized)
view-cross-site-scripting: 1 high, 0 medium
1 finding and 0 of medium confidence
Example
Gemfile.lockGEM
remote: https://rubygems.org/
specs:
rails (8.1.0)
PLATFORMS
ruby
DEPENDENCIES
rails
app/controllers/search_controller.rbclass SearchController < ApplicationController
def show
@query = params[:q]
end
end
app/views/search/show.html.erb<h1>Search</h1>
<p>Results for <%= raw @query %></p>
$ ur scan --rule view-cross-site-scripting
warning[view-cross-site-scripting]: `params`, a request parameter, reaches `raw` through `@query`
--> ./app/views/search/show.html.erb:2:20 view
= step 1: ./app/controllers/search_controller.rb:3:14 `params`, a request parameter,
= step 2: ./app/controllers/search_controller.rb:2:3-4 given to the view `search/show`
= hint: let the view escape it, or pass it as JSON
= see: Securing Rails Applications, 7.3 Cross-Site Scripting (XSS), Rails Guides (2025-10-01), https://guides.rubyonrails.org/security.html#cross-site-scripting-xss
scanned 2 files (no framework recognized)
view-cross-site-scripting: 1 high, 0 medium
1 finding and 0 of medium confidence
Example
Gemfile.lockGEM
remote: https://rubygems.org/
specs:
rails (8.1.0)
PLATFORMS
ruby
DEPENDENCIES
rails
app/controllers/search_controller.rbclass SearchController < ApplicationController
def show
@query = params[:q]
end
end
app/views/search/show.html.haml%h1 Search
%p
Results for
!= @query
$ ur scan --rule view-cross-site-scripting
warning[view-cross-site-scripting]: `params`, a request parameter, reaches `raw` through `@query`
--> ./app/views/search/show.html.haml:4:6 view
= step 1: ./app/controllers/search_controller.rb:3:14 `params`, a request parameter,
= step 2: ./app/controllers/search_controller.rb:2:3-4 given to the view `search/show`
= hint: let the view escape it, or pass it as JSON
= see: Securing Rails Applications, 7.3 Cross-Site Scripting (XSS), Rails Guides (2025-10-01), https://guides.rubyonrails.org/security.html#cross-site-scripting-xss
scanned 2 files (no framework recognized)
view-cross-site-scripting: 1 high, 0 medium
1 finding and 0 of medium confidence
Example
Gemfile.lockGEM
remote: https://rubygems.org/
specs:
rails (8.1.0)
PLATFORMS
ruby
DEPENDENCIES
rails
app/controllers/search_controller.rbclass SearchController < ApplicationController
def show
@query = params[:q]
end
end
app/views/search/show.html.slimh1 Search
p
| Results for
== @query
$ ur scan --rule view-cross-site-scripting
warning[view-cross-site-scripting]: `params`, a request parameter, reaches `raw` through `@query`
--> ./app/views/search/show.html.slim:4:6 view
= step 1: ./app/controllers/search_controller.rb:3:14 `params`, a request parameter,
= step 2: ./app/controllers/search_controller.rb:2:3-4 given to the view `search/show`
= hint: let the view escape it, or pass it as JSON
= see: Securing Rails Applications, 7.3 Cross-Site Scripting (XSS), Rails Guides (2025-10-01), https://guides.rubyonrails.org/security.html#cross-site-scripting-xss
scanned 2 files (no framework recognized)
view-cross-site-scripting: 1 high, 0 medium
1 finding and 0 of medium confidence
Source
Securing Rails Applications, 7.3 Cross-Site Scripting (XSS), Rails Guides (2025-10-01).