Skip to content

Commit

Permalink
Handle invalid referer for embedded page service
Browse files Browse the repository at this point in the history
  • Loading branch information
webit-winkler committed Jul 11, 2022
1 parent 2f55072 commit 6291e3c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/services/embedded_page_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ def enterprise_slug
end

def current_referer
return if @request.referer.blank?

uri = URI(@request.referer)
return if uri.host.blank?
uri = URI.parse(@request.referer)
return unless uri.is_a?(URI::HTTP) && uri.host.present?

uri.host.downcase
rescue URI::InvalidURIError
false
end

def current_referer_without_www
Expand Down
2 changes: 1 addition & 1 deletion spec/services/embedded_page_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
context "when the request's referer is malformed" do
let(:request) {
ActionController::TestRequest.new(
{ 'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'hello' }, nil, nil
{ 'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'hello# 32' }, nil, nil
)
}
before do
Expand Down

0 comments on commit 6291e3c

Please sign in to comment.