Skip to content

Commit

Permalink
Fix CVE-2017-16792 - Stored XSS
Browse files Browse the repository at this point in the history
Reject Javascript Link
  • Loading branch information
sonots committed Nov 13, 2017
1 parent c173cb5 commit f8429a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/geminabox/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ def combined_gem_list
end

helpers do
def href(text)
escaped_text = Rack::Utils.escape_html(text)
if escaped_text.start_with?('http://') || escaped_text.start_with?('https://')
escaped_text
else
'#'
end
end

def h(text)
Rack::Utils.escape_html(text)
end
Expand Down
2 changes: 1 addition & 1 deletion views/gem.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<%= spec.description %>
<br/>
<span class="author"><%= spec.authors.map do |author|
"<a href='#{h(spec.homepage)}'>#{author}</a>"
"<a href='#{href(spec.homepage)}'>#{author}</a>"
end.join(', ') %></span>
<% end %>
</p>
Expand Down
2 changes: 1 addition & 1 deletion views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<%= spec.description %>
<br/>
<span class="author"><%= spec.authors.map do |author|
"<a href='#{h(spec.homepage)}'>#{author}</a>"
"<a href='#{href(spec.homepage)}'>#{author}</a>"
end.join(', ') %></span>
<% end %>
</p>
Expand Down

0 comments on commit f8429a9

Please sign in to comment.