Skip to content

Commit

Permalink
Fix resolv IP regex patch for case when comapred strings are not the …
Browse files Browse the repository at this point in the history
…same object (#66)

* Fix resolv IP regex patch for case when comapred strings are not the same object

* Test should fail before the change

---------

Co-authored-by: Vadim Masakovski <vadim.masakovski@monterosa.co.uk>
Co-authored-by: Arkadiy Tetelman <arkadiyt@gmail.com>
Co-authored-by: Arkadiy Tetelman <arkadiyt@users.noreply.github.com>
  • Loading branch information
4 people committed Sep 1, 2023
1 parent 30681a6 commit 58aa964
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ssrf_filter/patch/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Resolv
class PatchedRegexp < Regexp
def ===(other)
if ::Thread.current.key?(::SsrfFilter::FIBER_ADDRESS_KEY) &&
other.object_id.equal?(::Thread.current[::SsrfFilter::FIBER_ADDRESS_KEY].object_id)
other.eql?(::Thread.current[::SsrfFilter::FIBER_ADDRESS_KEY])
false
else
super(other)
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/patch/resolv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,14 @@
expect(described_class.new(Resolv::IPv4::Regex) === ipaddress2).to be true
# rubocop:enable Style/CaseEquality
end

it 'forces the ip regex to not match the same supplied address' do
ip_address = '1.2.3.4'
same_ip_address = '1.2.3.4'.clone
SsrfFilter.send(:with_forced_hostname, nil, ip_address) do
expect(described_class.new(Resolv::IPv4::Regex) === same_ip_address).to be false
end
expect(described_class.new(Resolv::IPv4::Regex) === same_ip_address).to be true
end
end
end

0 comments on commit 58aa964

Please sign in to comment.