Skip to content

Commit 1b465b9

Browse files
committed
fix: ambiguous path match in other phase
This closes #153
1 parent 2234db9 commit 1b465b9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/omniauth/strategies/saml.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def response_fingerprint
6969
end
7070

7171
def other_phase
72-
if current_path.start_with?(request_path)
72+
if request_path_pattern.match(current_path)
7373
@env['omniauth.strategy'] ||= self
7474
setup_phase
7575

@@ -120,6 +120,10 @@ def find_attribute_by(keys)
120120

121121
private
122122

123+
def request_path_pattern
124+
@request_path_pattern ||= %r{\A#{Regexp.quote(request_path)}(/|\z)}
125+
end
126+
123127
def on_subpath?(subpath)
124128
on_path?("#{request_path}/#{subpath}")
125129
end

spec/omniauth/strategies/saml_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ def test_default_relay_state(static_default_relay_state = nil, &block_default_re
435435
specify { expect(last_response.status).to eql 404 }
436436
end
437437

438+
context 'when hitting a route that contains a substring match for the strategy name' do
439+
before { get '/auth/saml2/metadata' }
440+
441+
it 'should not set the strategy' do
442+
expect(last_request.env['omniauth.strategy']).to be_nil
443+
expect(last_response.status).to eql 404
444+
end
445+
end
446+
438447
describe 'subclass behavior' do
439448
it 'registers subclasses in OmniAuth.strategies' do
440449
subclass = Class.new(described_class)

0 commit comments

Comments
 (0)