Skip to content

Commit 70776d1

Browse files
author
gene
committed
disabling recipient check
1 parent 5722ad0 commit 70776d1

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,12 @@ def saml_settings
193193
end
194194
```
195195
196-
Some assertion validations can be skipped by passing parameters to `OneLogin::RubySaml::Response.new()`. For example, you can skip the `Conditions` validation or the `SubjectConfirmation` validations by initializing the response with different options:
196+
Some assertion validations can be skipped by passing parameters to `OneLogin::RubySaml::Response.new()`. For example, you can skip the `Conditions`, `Recipient`, or the `SubjectConfirmation` validations by initializing the response with different options:
197197
198198
```ruby
199199
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_conditions: true}) # skips conditions
200200
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_subject_confirmation: true}) # skips subject confirmation
201+
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], {skip_recipient_check: true}) # doens't skip subject confirmation, but skips the recipient check which is a sub check of the subject_confirmation check
201202
```
202203
203204
All that's left is to wrap everything in a controller and reference it in the initialization and consumption URLs in OneLogin. A full controller example could look like this:

lib/onelogin/ruby-saml/response.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def initialize(response, options = {})
4141
raise ArgumentError.new("Response cannot be nil") if response.nil?
4242

4343
@errors = []
44+
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+
4450
@options = options
4551
@soft = true
4652
unless options[:settings].nil?
@@ -708,6 +714,7 @@ def validate_session_expiration(soft = true)
708714
# Validates if exists valid SubjectConfirmation (If the response was initialized with the :allowed_clock_drift option,
709715
# timimg validation are relaxed by the allowed_clock_drift value. If the response was initialized with the
710716
# :skip_subject_confirmation option, this validation is skipped)
717+
# There is also an optional Recipient check
711718
# If fails, the error is added to the errors array
712719
# @return [Boolean] True if exists a valid SubjectConfirmation, otherwise False if soft=True
713720
# @raise [ValidationError] if soft == false and validation fails
@@ -736,7 +743,7 @@ def validate_subject_confirmation
736743
next if (attrs.include? "InResponseTo" and attrs['InResponseTo'] != in_response_to) ||
737744
(attrs.include? "NotOnOrAfter" and (parse_time(confirmation_data_node, "NotOnOrAfter") + allowed_clock_drift) <= now) ||
738745
(attrs.include? "NotBefore" and parse_time(confirmation_data_node, "NotBefore") > (now + allowed_clock_drift)) ||
739-
(attrs.include? "Recipient" and settings.assertion_consumer_service_url != nil and attrs['Recipient'] != settings.assertion_consumer_service_url)
746+
(attrs.include? "Recipient" and !options[:skip_recipient_check] and attrs['Recipient'] != settings.assertion_consumer_service_url)
740747

741748
valid_subject_confirmation = true
742749
break

lib/onelogin/ruby-saml/settings.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def single_logout_service_binding
9494
end
9595

9696
# Setter for Single Logout Service Binding.
97-
#
97+
#
9898
# (Currently we only support "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect")
9999
# @param url [String]
100100
#

test/response_test.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +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 })}
2021
let(:response_valid_signed_without_x509certificate) { OneLogin::RubySaml::Response.new(response_document_valid_signed_without_x509certificate) }
2122
let(:response_no_id) { OneLogin::RubySaml::Response.new(read_invalid_response("no_id.xml.base64")) }
2223
let(:response_no_version) { OneLogin::RubySaml::Response.new(read_invalid_response("no_saml2.xml.base64")) }
@@ -677,17 +678,25 @@ class RubySamlTest < Minitest::Test
677678
end
678679

679680
it "return true when valid subject confirmation recipient" do
680-
response_valid_signed.settings = settings
681-
response_valid_signed.settings.assertion_consumer_service_url= 'recipient'
681+
response_valid_signed_with_recipient.settings = settings
682+
response_valid_signed_with_recipient.settings.assertion_consumer_service_url = 'recipient'
682683
assert response_valid_signed.send(:validate_subject_confirmation)
683684
assert_empty response_valid_signed.errors
685+
assert_empty response_valid_signed_with_recipient.errors
686+
end
687+
688+
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"
684693
end
685694

686-
it "return false when valid subject confirmation recipient" do
695+
it "return false when invalid subject confirmation recipient, but skipping the check(default)" do
687696
response_valid_signed.settings = settings
688697
response_valid_signed.settings.assertion_consumer_service_url = 'not-the-recipient'
689-
assert !response_valid_signed.send(:validate_subject_confirmation)
690-
assert_includes response_valid_signed.errors, "A valid SubjectConfirmation was not found on this Response"
698+
assert response_valid_signed.send(:validate_subject_confirmation)
699+
assert_empty response_valid_signed.errors
691700
end
692701

693702
it "return true when the skip_subject_confirmation option is passed and the subject confirmation is valid" do

0 commit comments

Comments
 (0)