Skip to content

Commit 270fec1

Browse files
Merge pull request #15 from gerardo-navarro/gerardo-navarro-remove-saml-relay-state-validation
Restore SLO logout response redirect handling
2 parents fcb111f + 77547ae commit 270fec1

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

lib/omniauth/strategies/saml.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,9 @@ def slo_relay_state
170170
relay_state = request.params["RelayState"]
171171

172172
return relay_state if valid_slo_relay_state?(relay_state)
173-
174-
default_relay_state = default_slo_relay_state
175-
176-
if default_relay_state.nil?
177-
raise OmniAuth::Strategies::SAML::ValidationError.new("Invalid RelayState")
178-
end
179-
180-
default_relay_state
181-
else
182-
default_slo_relay_state
183173
end
174+
175+
default_slo_relay_state
184176
end
185177

186178
def valid_slo_relay_state?(relay_state)

spec/omniauth/strategies/saml_spec.rb

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,11 @@ def post_xml(xml = :example_response, opts = {})
303303
context "when relay state is an absolute https URL" do
304304
let(:relay_state) { "https://example.com/" }
305305

306-
it "raises an invalid relay state error" do
307-
expect { post_slo_response }.
308-
to raise_error(OmniAuth::Strategies::SAML::ValidationError, "Invalid RelayState")
306+
it "redirects without a location header" do
307+
post_slo_response
308+
309+
expect(last_response).to be_redirect
310+
expect(last_response.headers.fetch("Location")).to be_nil
309311
end
310312
end
311313

@@ -335,7 +337,12 @@ def post_xml(xml = :example_response, opts = {})
335337
context "when response relay state is invalid" do
336338
let(:relay_state) { "javascript:alert(1)" }
337339

338-
it { expect { post_slo_response }.to raise_error(OmniAuth::Strategies::SAML::ValidationError, "Invalid RelayState") }
340+
it "redirects without a location header" do
341+
post_slo_response
342+
343+
expect(last_response).to be_redirect
344+
expect(last_response.headers.fetch("Location")).to be_nil
345+
end
339346
end
340347
end
341348
end
@@ -452,9 +459,12 @@ def post_xml(xml = :example_response, opts = {})
452459
}
453460
end
454461

455-
it "raises an error" do
456-
expect { subject }.
457-
to raise_error(OmniAuth::Strategies::SAML::ValidationError, "Invalid RelayState")
462+
it "redirects without including a RelayState parameter" do
463+
subject
464+
465+
expect(last_response).to be_redirect
466+
expect(last_response.location).to match %r{https://idp\.sso\.example\.com/signoff/29490}
467+
expect(last_response.location).not_to match(/RelayState=/)
458468
end
459469
end
460470
end
@@ -634,7 +644,13 @@ def test_default_relay_state(static_default_relay_state = nil, &block_default_re
634644
let(:params) { { RelayState: "//example.com" } }
635645
subject { post "/auth/saml/spslo", params }
636646

637-
it { expect { subject }.to raise_error(OmniAuth::Strategies::SAML::ValidationError, "Invalid RelayState") }
647+
it "redirects without including a RelayState parameter" do
648+
subject
649+
650+
expect(last_response).to be_redirect
651+
expect(last_response.location).to match %r{https://idp\.sso\.example\.com/signoff/29490}
652+
expect(last_response.location).not_to match(/RelayState=/)
653+
end
638654
end
639655

640656
it "should give not implemented without an idp_slo_service_url" do

0 commit comments

Comments
 (0)