Skip to content

Commit

Permalink
escape widget error message; prevent xss
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Gebhardt authored and kinow committed Jun 24, 2021
1 parent bdda94f commit d9816ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/dashing/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def protected!
# override with auth logic
end

def h(text)
Rack::Utils.escape_html(text)
end

def authenticated?(token)
return true unless settings.auth_token
token && Rack::Utils.secure_compare(settings.auth_token, token)
Expand Down Expand Up @@ -129,7 +133,7 @@ def authenticated?(token)
return Tilt[language].new(file).render if File.exist?(file)
end

"Drats! Unable to find a widget file named: #{params[:widget]} to render."
"Drats! Unable to find a widget file named: #{h(params[:widget])} to render."
end

Thin::Server.class_eval do
Expand Down
8 changes: 8 additions & 0 deletions test/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ def test_get_nonexistent_widget
end
end

def test_get_xss_widget
with_generated_project do
get '/views/nowidget-<h1>.html'
assert_equal 200, last_response.status
assert_equal last_response.body, 'Drats! Unable to find a widget file named: nowidget-&lt;h1&gt; to render.'
end
end

def with_generated_project
source_path = File.expand_path('../../templates', __FILE__)

Expand Down

0 comments on commit d9816ce

Please sign in to comment.