Skip to content

Commit c6256ef

Browse files
committed
Minor refactor
1 parent 31039b8 commit c6256ef

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ options = {
2424
},
2525
}
2626
slo_logout_request = OneLogin::RubySaml::SloLogoutrequest.new(query_params["SAMLRequest"], settings, options)
27-
raise "Uh oh!" unless slo_logout_request.is_valid?
27+
raise "Invalid Logout Request" unless slo_logout_request.is_valid?
2828
```
2929

3030
The old form is still supported for backward compatibility, but all Ruby SAML users should prefer `options[:raw_get_params]` where possible to ensure compatibility with other SAML implementations.

lib/onelogin/ruby-saml/logoutresponse.rb

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -211,32 +211,8 @@ def validate_signature
211211
return true unless options.has_key? :get_params
212212
return true unless options[:get_params].has_key? 'Signature'
213213

214-
# SAML specifies that the signature should be derived from a concatenation
215-
# of URI-encoded values _as sent by the IDP_:
216-
#
217-
# > Further, note that URL-encoding is not canonical; that is, there are multiple legal encodings for a given
218-
# > value. The relying party MUST therefore perform the verification step using the original URL-encoded
219-
# > values it received on the query string. It is not sufficient to re-encode the parameters after they have been
220-
# > processed by software because the resulting encoding may not match the signer's encoding.
221-
#
222-
# <http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf>
223-
#
224-
# If we don't have the original parts (for backward compatibility) required to correctly verify the signature,
225-
# then fabricate them by re-encoding the parsed URI parameters, and hope that we're lucky enough to use
226-
# the exact same URI-encoding as the IDP. (This is not the case if the IDP is ADFS!)
227-
options[:raw_get_params] ||= {}
228-
if options[:raw_get_params]['SAMLResponse'].nil? && !options[:get_params]['SAMLResponse'].nil?
229-
options[:raw_get_params]['SAMLResponse'] = CGI.escape(options[:get_params]['SAMLResponse'])
230-
end
231-
if options[:raw_get_params]['RelayState'].nil? && !options[:get_params]['RelayState'].nil?
232-
options[:raw_get_params]['RelayState'] = CGI.escape(options[:get_params]['RelayState'])
233-
end
234-
if options[:raw_get_params]['SigAlg'].nil? && !options[:get_params]['SigAlg'].nil?
235-
options[:raw_get_params]['SigAlg'] = CGI.escape(options[:get_params]['SigAlg'])
236-
end
214+
options[:raw_get_params] = OneLogin::RubySaml::Utils.prepare_raw_get_params(options[:raw_get_params], options[:get_params])
237215

238-
# If we only received the raw version of SigAlg,
239-
# then parse it back into the decoded params hash for convenience.
240216
if options[:get_params]['SigAlg'].nil? && !options[:raw_get_params]['SigAlg'].nil?
241217
options[:get_params]['SigAlg'] = CGI.unescape(options[:raw_get_params]['SigAlg'])
242218
end

lib/onelogin/ruby-saml/utils.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def self.build_query(params)
7676
end
7777

7878
# Reconstruct a canonical query string from raw URI-encoded parts, to be used in verifying a signature
79-
# sent by an IDP.
8079
#
8180
# @param params [Hash] Parameters to build the Query String
8281
# @option params [String] :type 'SAMLRequest' or 'SAMLResponse'
@@ -93,6 +92,32 @@ def self.build_query_from_raw_parts(params)
9392
url_string << "&SigAlg=#{raw_sig_alg}"
9493
end
9594

95+
# Prepare raw GET parameters (build them from normal parameters
96+
# if not provided).
97+
#
98+
# @param rawparams [Hash] Raw GET Parameters
99+
# @param params [Hash] GET Parameters
100+
# @return [Hash] New raw parameters
101+
#
102+
def self.prepare_raw_get_params(rawparams, params)
103+
rawparams ||= {}
104+
105+
if rawparams['SAMLRequest'].nil? && !params['SAMLRequest'].nil?
106+
rawparams['SAMLRequest'] = CGI.escape(params['SAMLRequest'])
107+
end
108+
if rawparams['SAMLResponse'].nil? && !params['SAMLResponse'].nil?
109+
rawparams['SAMLResponse'] = CGI.escape(params['SAMLResponse'])
110+
end
111+
if rawparams['RelayState'].nil? && !params['RelayState'].nil?
112+
rawparams['RelayState'] = CGI.escape(params['RelayState'])
113+
end
114+
if rawparams['SigAlg'].nil? && !params['SigAlg'].nil?
115+
rawparams['SigAlg'] = CGI.escape(params['SigAlg'])
116+
end
117+
118+
rawparams
119+
end
120+
96121
# Validate the Signature parameter sent on the HTTP-Redirect binding
97122
# @param params [Hash] Parameters to be used in the validation process
98123
# @option params [OpenSSL::X509::Certificate] cert The Identity provider public certtificate

0 commit comments

Comments
 (0)