Skip to content

Commit 368a360

Browse files
author
gene
committed
updated recipient check to be on by default
1 parent 70776d1 commit 368a360

File tree

2 files changed

+30
-33
lines changed

2 files changed

+30
-33
lines changed

lib/onelogin/ruby-saml/response.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ def initialize(response, options = {})
4242

4343
@errors = []
4444

45-
# skip recipient check by default for backwards compatibility
46-
unless options.key?(:skip_recipient_check)
47-
options[:skip_recipient_check] = true
48-
end
49-
5045
@options = options
5146
@soft = true
5247
unless options[:settings].nil?
@@ -743,7 +738,7 @@ def validate_subject_confirmation
743738
next if (attrs.include? "InResponseTo" and attrs['InResponseTo'] != in_response_to) ||
744739
(attrs.include? "NotOnOrAfter" and (parse_time(confirmation_data_node, "NotOnOrAfter") + allowed_clock_drift) <= now) ||
745740
(attrs.include? "NotBefore" and parse_time(confirmation_data_node, "NotBefore") > (now + allowed_clock_drift)) ||
746-
(attrs.include? "Recipient" and !options[:skip_recipient_check] and attrs['Recipient'] != settings.assertion_consumer_service_url)
741+
(attrs.include? "Recipient" and !options[:skip_recipient_check] and attrs['Recipient'] != settings&.assertion_consumer_service_url)
747742

748743
valid_subject_confirmation = true
749744
break

test/response_test.rb

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class RubySamlTest < Minitest::Test
1717
let(:response_wrapped) { OneLogin::RubySaml::Response.new(response_document_wrapped) }
1818
let(:response_multiple_attr_values) { OneLogin::RubySaml::Response.new(fixture(:response_with_multiple_attribute_values)) }
1919
let(:response_valid_signed) { OneLogin::RubySaml::Response.new(response_document_valid_signed) }
20-
let(:response_valid_signed_with_recipient) { OneLogin::RubySaml::Response.new(response_document_valid_signed, {:skip_recipient_check => false })}
20+
let(:response_valid_signed_without_recipient) { OneLogin::RubySaml::Response.new(response_document_valid_signed, {:skip_recipient_check => true })}
2121
let(:response_valid_signed_without_x509certificate) { OneLogin::RubySaml::Response.new(response_document_valid_signed_without_x509certificate) }
2222
let(:response_no_id) { OneLogin::RubySaml::Response.new(read_invalid_response("no_id.xml.base64")) }
2323
let(:response_no_version) { OneLogin::RubySaml::Response.new(read_invalid_response("no_saml2.xml.base64")) }
@@ -242,19 +242,19 @@ class RubySamlTest < Minitest::Test
242242
end
243243

244244
it "return true when the response is initialized with valid data" do
245-
response_valid_signed.stubs(:conditions).returns(nil)
246-
response_valid_signed.settings = settings
247-
response_valid_signed.settings.idp_cert_fingerprint = ruby_saml_cert_fingerprint
248-
assert response_valid_signed.is_valid?
249-
assert_empty response_valid_signed.errors
245+
response_valid_signed_without_recipient.stubs(:conditions).returns(nil)
246+
response_valid_signed_without_recipient.settings = settings
247+
response_valid_signed_without_recipient.settings.idp_cert_fingerprint = ruby_saml_cert_fingerprint
248+
assert response_valid_signed_without_recipient.is_valid?
249+
assert_empty response_valid_signed_without_recipient.errors
250250
end
251251

252252
it "return true when the response is initialized with valid data and using certificate instead of fingerprint" do
253-
response_valid_signed.stubs(:conditions).returns(nil)
254-
response_valid_signed.settings = settings
255-
response_valid_signed.settings.idp_cert = ruby_saml_cert_text
256-
assert response_valid_signed.is_valid?
257-
assert_empty response_valid_signed.errors
253+
response_valid_signed_without_recipient.stubs(:conditions).returns(nil)
254+
response_valid_signed_without_recipient.settings = settings
255+
response_valid_signed_without_recipient.settings.idp_cert = ruby_saml_cert_text
256+
assert response_valid_signed_without_recipient.is_valid?
257+
assert_empty response_valid_signed_without_recipient.errors
258258
end
259259

260260
it "return false when response is initialized with blank data" do
@@ -283,11 +283,11 @@ class RubySamlTest < Minitest::Test
283283
end
284284

285285
it "should be idempotent when the response is initialized with valid data" do
286-
response_valid_signed.stubs(:conditions).returns(nil)
287-
response_valid_signed.settings = settings
288-
response_valid_signed.settings.idp_cert_fingerprint = ruby_saml_cert_fingerprint
289-
assert response_valid_signed.is_valid?
290-
assert response_valid_signed.is_valid?
286+
response_valid_signed_without_recipient.stubs(:conditions).returns(nil)
287+
response_valid_signed_without_recipient.settings = settings
288+
response_valid_signed_without_recipient.settings.idp_cert_fingerprint = ruby_saml_cert_fingerprint
289+
assert response_valid_signed_without_recipient.is_valid?
290+
assert response_valid_signed_without_recipient.is_valid?
291291
end
292292

293293
it "not allow signature wrapping attack" do
@@ -383,6 +383,7 @@ class RubySamlTest < Minitest::Test
383383

384384
it "return true when a nil URI is given in the ds:Reference" do
385385
settings.idp_cert = ruby_saml_cert_text
386+
settings.assertion_consumer_service_url = "http://localhost:9001/v1/users/authorize/saml"
386387
response_without_reference_uri.settings = settings
387388
response_without_reference_uri.stubs(:conditions).returns(nil)
388389
response_without_reference_uri.is_valid?
@@ -678,25 +679,25 @@ class RubySamlTest < Minitest::Test
678679
end
679680

680681
it "return true when valid subject confirmation recipient" do
681-
response_valid_signed_with_recipient.settings = settings
682-
response_valid_signed_with_recipient.settings.assertion_consumer_service_url = 'recipient'
682+
response_valid_signed.settings = settings
683+
response_valid_signed.settings.assertion_consumer_service_url = 'recipient'
683684
assert response_valid_signed.send(:validate_subject_confirmation)
684685
assert_empty response_valid_signed.errors
685-
assert_empty response_valid_signed_with_recipient.errors
686+
assert_empty response_valid_signed.errors
686687
end
687688

688689
it "return false when invalid subject confirmation recipient" do
689-
response_valid_signed_with_recipient.settings = settings
690-
response_valid_signed_with_recipient.settings.assertion_consumer_service_url = 'not-the-recipient'
691-
assert !response_valid_signed_with_recipient.send(:validate_subject_confirmation)
692-
assert_includes response_valid_signed_with_recipient.errors, "A valid SubjectConfirmation was not found on this Response"
690+
response_valid_signed.settings = settings
691+
response_valid_signed.settings.assertion_consumer_service_url = 'not-the-recipient'
692+
assert !response_valid_signed.send(:validate_subject_confirmation)
693+
assert_includes response_valid_signed.errors, "A valid SubjectConfirmation was not found on this Response"
693694
end
694695

695696
it "return false when invalid subject confirmation recipient, but skipping the check(default)" do
696-
response_valid_signed.settings = settings
697-
response_valid_signed.settings.assertion_consumer_service_url = 'not-the-recipient'
698-
assert response_valid_signed.send(:validate_subject_confirmation)
699-
assert_empty response_valid_signed.errors
697+
response_valid_signed_without_recipient.settings = settings
698+
response_valid_signed_without_recipient.settings.assertion_consumer_service_url = 'not-the-recipient'
699+
assert response_valid_signed_without_recipient.send(:validate_subject_confirmation)
700+
assert_empty response_valid_signed_without_recipient.errors
700701
end
701702

702703
it "return true when the skip_subject_confirmation option is passed and the subject confirmation is valid" do
@@ -1146,6 +1147,7 @@ class RubySamlTest < Minitest::Test
11461147
document.sign_document(private_key, cert)
11471148

11481149
signed_response = OneLogin::RubySaml::Response.new(document.to_s)
1150+
settings.assertion_consumer_service_url = "http://recipient"
11491151
settings.idp_cert = ruby_saml_cert_text
11501152
signed_response.settings = settings
11511153
Timecop.freeze(Time.parse("2015-03-18T04:50:24Z")) do

0 commit comments

Comments
 (0)