Skip to content

Commit

Permalink
Don't allow URLs that contain non-normalized paths to be verified (#2…
Browse files Browse the repository at this point in the history
…0999)

* Don't allow URLs that contain non-normalized paths to be verified

This stops things like https://example.com/otheruser/../realuser where
"/otheruser" appears to be the verified URL, but the actual URL being
verified is "/realuser" due to the "/../".

Also fix a test to use 'https', so it is testing the right thing, now
that since #20304 https is required.

* missing do
  • Loading branch information
dgl committed Nov 20, 2022
1 parent 48e1366 commit 69378ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/models/account/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def verifiable?
parsed_url.user.nil? &&
parsed_url.password.nil? &&
parsed_url.host.present? &&
parsed_url.normalized_host == parsed_url.host
parsed_url.normalized_host == parsed_url.host &&
(parsed_url.path.empty? || parsed_url.path == parsed_url.normalized_path)
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
false
end
Expand Down
10 changes: 9 additions & 1 deletion spec/models/account/field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@
end

context 'for an IDN URL' do
let(:value) { 'http://twitter.com∕dougallj∕status∕1590357240443437057.ê.cc/twitter.html' }
let(:value) { 'https://twitter.com∕dougallj∕status∕1590357240443437057.ê.cc/twitter.html' }

it 'returns false' do
expect(subject.verifiable?).to be false
end
end

context 'for a URL with a non-normalized path' do
let(:value) { 'https://github.com/octocatxxxxxxxx/../mastodon' }

it 'returns false' do
expect(subject.verifiable?).to be false
Expand Down

0 comments on commit 69378ea

Please sign in to comment.