Skip to content

Commit 0cb1843

Browse files
Jacob Klapwijkmentimetercanclini
andcommitted
Use Singlelogout response url in LogoutResponse if set
Co-authored-by: Sofia Canclini <sofia.canclini@mentimeter.com>
1 parent 62ac2fe commit 0cb1843

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

lib/onelogin/ruby-saml/slo_logoutresponse.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ def initialize
3232
def create(settings, request_id = nil, logout_message = nil, params = {})
3333
params = create_params(settings, request_id, logout_message, params)
3434
params_prefix = (settings.idp_slo_target_url =~ /\?/) ? '&' : '?'
35+
url = settings.idp_slo_response_service_url || settings.idp_slo_target_url
3536
saml_response = CGI.escape(params.delete("SAMLResponse"))
3637
response_params = "#{params_prefix}SAMLResponse=#{saml_response}"
3738
params.each_pair do |key, value|
3839
response_params << "&#{key.to_s}=#{CGI.escape(value.to_s)}"
3940
end
4041

41-
raise SettingError.new "Invalid settings, idp_slo_target_url is not set!" if settings.idp_slo_target_url.nil? or settings.idp_slo_target_url.empty?
42-
@logout_url = settings.idp_slo_target_url + response_params
42+
raise SettingError.new "Invalid settings, idp_slo_target_url is not set!" if url.nil? or url.empty?
43+
@logout_url = url + response_params
4344
end
4445

4546
# Creates the Get parameters for the logout response.
@@ -109,12 +110,14 @@ def create_xml_document(settings, request_id = nil, logout_message = nil)
109110
response_doc = XMLSecurity::Document.new
110111
response_doc.uuid = uuid
111112

113+
destination = settings.idp_slo_response_service_url || settings.idp_slo_target_url
114+
112115
root = response_doc.add_element 'samlp:LogoutResponse', { 'xmlns:samlp' => 'urn:oasis:names:tc:SAML:2.0:protocol', "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion" }
113116
root.attributes['ID'] = uuid
114117
root.attributes['IssueInstant'] = time
115118
root.attributes['Version'] = '2.0'
116119
root.attributes['InResponseTo'] = request_id unless request_id.nil?
117-
root.attributes['Destination'] = settings.idp_slo_target_url unless settings.idp_slo_target_url.nil? or settings.idp_slo_target_url.empty?
120+
root.attributes['Destination'] = destination unless destination.nil? or destination.empty?
118121

119122
if settings.sp_entity_id != nil
120123
issuer = root.add_element "saml:Issuer"

test/slo_logoutresponse_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ class SloLogoutresponseTest < Minitest::Test
6565
assert_match /<samlp:StatusMessage>Custom Logout Message<\/samlp:StatusMessage>/, inflated
6666
end
6767

68+
it "uses the response location when set" do
69+
settings.idp_slo_response_service_url = "http://unauth.com/logout/return"
70+
71+
unauth_url = OneLogin::RubySaml::SloLogoutresponse.new.create(settings, logout_request.id)
72+
assert_match /^http:\/\/unauth\.com\/logout\/return\?SAMLResponse=/, unauth_url
73+
74+
inflated = decode_saml_response_payload(unauth_url)
75+
assert_match /Destination='http:\/\/unauth.com\/logout\/return'/, inflated
76+
end
77+
6878
describe "when the settings indicate to sign (embedded) logout response" do
6979

7080
before do

0 commit comments

Comments
 (0)