Skip to content

Commit 8345b5c

Browse files
Potential fix for pull request finding 'CodeQL / Reflected server-side cross-site scripting'
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 0c11eaa commit 8345b5c

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

app/controllers/thirdiron_controller.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'uri'
2+
13
class ThirdironController < ApplicationController
24
layout false
35

@@ -14,12 +16,24 @@ def browzine
1416
return unless ThirdIron.enabled? && params[:issn].present?
1517

1618
@browzine = Browzine.lookup(issn: params[:issn])
17-
@full_record_url = params[:full_record_url]
19+
@full_record_url = safe_full_record_url(params[:full_record_url])
1820
end
1921

2022
private
2123

2224
def expected_params?
2325
params[:type].present? && params[:identifier].present?
2426
end
27+
28+
def safe_full_record_url(url)
29+
return nil if url.blank?
30+
31+
parsed = URI.parse(url)
32+
return nil unless parsed.is_a?(URI::HTTP) || parsed.is_a?(URI::HTTPS)
33+
return nil if parsed.host.blank?
34+
35+
parsed.to_s
36+
rescue URI::InvalidURIError
37+
nil
38+
end
2539
end

app/views/thirdiron/browzine.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<% if ThirdIron.enabled? && @browzine.present? %>
2-
<%= link_to 'Full-text options', @full_record_url, class: 'button libkey-link', data: { matomo_seen: "Results, Full-text Options Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, Full-text Options Link Engaged, Link: {{getElementText}}", content_piece: 'Full-text options' } %>
2+
<% if @full_record_url.present? %>
3+
<%= link_to 'Full-text options', @full_record_url, class: 'button libkey-link', data: { matomo_seen: "Results, Full-text Options Link Seen, Tab: {{getActiveTabName}}", matomo_click: "Results, Full-text Options Link Engaged, Link: {{getElementText}}", content_piece: 'Full-text options' } %>
4+
<% end %>
35

46
<% if @browzine[:browzine_link].present? %>
57
<div class="libkey-actions">

0 commit comments

Comments
 (0)