Skip to content

Commit 4413590

Browse files
committed
Changes on empty URI of Signature reference management
1 parent 71e3bb9 commit 4413590

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

lib/xml_security.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,6 @@ def validate_signature(base64_cert, soft = true)
278278
noko_sig_element = document.at_xpath('//ds:Signature', 'ds' => DSIG)
279279
noko_signed_info_element = noko_sig_element.at_xpath('./ds:SignedInfo', 'ds' => DSIG)
280280

281-
# Handle when no URI
282-
# noko_signed_info_reference_element_uri_attr = noko_signed_info_element.at_xpath('./ds:Reference', 'ds' => DSIG).attributes["URI"]
283-
# if (noko_signed_info_reference_element_uri_attr.value.empty?)
284-
# noko_signed_info_reference_element_uri_attr.value = "##{document.root.attribute('ID')}"
285-
# end
286-
287281
canon_string = noko_signed_info_element.canonicalize(canon_algorithm)
288282
noko_sig_element.remove
289283

@@ -294,8 +288,8 @@ def validate_signature(base64_cert, soft = true)
294288
ref = REXML::XPath.first(sig_element, "//ds:Reference", {"ds"=>DSIG})
295289
uri = ref.attributes.get_attribute("URI").value
296290

297-
hashed_element = uri.empty? ? document : document.at_xpath("//*[@ID=$uri]", nil, { 'uri' => uri[1..-1] })
298-
# hashed_element = document.at_xpath("//*[@ID=$uri]", nil, { 'uri' => uri[1..-1] })
291+
hashed_element = document.at_xpath("//*[@ID=$id]", nil, { 'id' => extract_signed_element_id })
292+
299293
canon_algorithm = canon_algorithm REXML::XPath.first(
300294
ref,
301295
'//ds:CanonicalizationMethod',
@@ -350,7 +344,7 @@ def extract_signed_element_id
350344
return nil if reference_element.nil?
351345

352346
sei = reference_element.attribute("URI").value[1..-1]
353-
sei.nil? ? self.root.attribute("ID") : sei
347+
sei.nil? ? reference_element.parent.parent.parent.attribute("ID").value : sei
354348
end
355349

356350
def extract_inclusive_namespaces

test/response_test.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,12 @@ class RubySamlTest < Minitest::Test
389389
end
390390

391391
it "return true when a nil URI is given in the ds:Reference" do
392-
393-
response_without_reference_uri.stubs(:conditions).returns(nil)
394392
settings.idp_cert = ruby_saml_cert_text
395393
response_without_reference_uri.settings = settings
396-
assert response_without_reference_uri.is_valid?
397-
assert_empty response.errors
394+
response_without_reference_uri.stubs(:conditions).returns(nil)
395+
response_without_reference_uri.is_valid?
398396
assert_empty response_without_reference_uri.errors
399-
assert 'saml@user.com', response.attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress']
397+
assert 'saml@user.com', response_without_reference_uri.attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress']
400398
end
401399
end
402400
end

0 commit comments

Comments
 (0)