Skip to content

Commit 25a44ea

Browse files
committed
Improved inResponse validation on SAMLResponses and LogoutResponses
1 parent ce52a31 commit 25a44ea

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

lib/onelogin/ruby-saml/logoutresponse.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,11 @@ def valid_state?
180180
#
181181
def valid_in_response_to?
182182
return true unless options.has_key? :matches_request_id
183+
return true if options[:matches_request_id].nil?
184+
return true unless options[:matches_request_id] != in_response_to
183185

184-
unless options[:matches_request_id] == in_response_to
185-
return append_error("Response does not match the request ID, expected: <#{options[:matches_request_id]}>, but was: <#{in_response_to}>")
186-
end
187-
188-
true
186+
error_msg = "The InResponseTo of the Logout Response: #{in_response_to}, does not match the ID of the Logout Request sent by the SP: #{options[:matches_request_id]}"
187+
append_error(error_msg)
189188
end
190189

191190
# Validates the Issuer of the Logout Response

lib/onelogin/ruby-saml/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def validate_signed_elements
563563
#
564564
def validate_in_response_to
565565
return true unless options.has_key? :matches_request_id
566-
return true if options[:matches_request_id].nil? || options[:matches_request_id].empty?
566+
return true if options[:matches_request_id].nil?
567567
return true unless options[:matches_request_id] != in_response_to
568568

569569
error_msg = "The InResponseTo of the Response: #{in_response_to}, does not match the ID of the AuthNRequest sent by the SP: #{options[:matches_request_id]}"

test/logoutresponse_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class RubySamlTest < Minitest::Test
103103

104104
assert !logoutresponse.validate
105105
refute_equal expected_request_id, logoutresponse.in_response_to
106-
assert_includes logoutresponse.errors, "Response does not match the request ID, expected: <#{expected_request_id}>, but was: <#{logoutresponse.in_response_to}>"
106+
assert_includes logoutresponse.errors, "The InResponseTo of the Logout Response: #{logoutresponse.in_response_to}, does not match the ID of the Logout Request sent by the SP: #{expected_request_id}"
107107
end
108108

109109
it "invalidate logout response with wrong request status" do
@@ -177,7 +177,7 @@ class RubySamlTest < Minitest::Test
177177

178178
logoutresponse = OneLogin::RubySaml::Logoutresponse.new(valid_logout_response_document, settings, opts)
179179
assert_raises(OneLogin::RubySaml::ValidationError) { logoutresponse.validate }
180-
assert_includes logoutresponse.errors, "Response does not match the request ID, expected: <#{expected_request_id}>, but was: <#{logoutresponse.in_response_to}>"
180+
assert_includes logoutresponse.errors, "The InResponseTo of the Logout Response: #{logoutresponse.in_response_to}, does not match the ID of the Logout Request sent by the SP: #{expected_request_id}"
181181
end
182182

183183
it "raise validation error for wrong request status" do

0 commit comments

Comments
 (0)