@@ -1288,4 +1288,42 @@ class RubySamlTest < Minitest::Test
12881288 assert_equal "ZdrjpwEdw22vKoxWAbZB78/gQ7s=" , response . attributes . single ( 'urn:oid:1.3.6.1.4.1.5923.1.1.1.10' )
12891289 end
12901290 end
1291+
1292+ describe "signature wrapping attack with encrypted assertion" do
1293+ it "should not be valid" do
1294+ settings . private_key = ruby_saml_key_text
1295+ signature_wrapping_attack = read_invalid_response ( "encrypted_new_attack.xml.base64" )
1296+ response_wrapped = OneLogin ::RubySaml ::Response . new ( signature_wrapping_attack , :settings => settings )
1297+ response_wrapped . stubs ( :conditions ) . returns ( nil )
1298+ response_wrapped . stubs ( :validate_subject_confirmation ) . returns ( true )
1299+ settings . idp_cert_fingerprint = "385b1eec71143f00db6af936e2ea12a28771d72c"
1300+ assert !response_wrapped . is_valid?
1301+ assert_includes response_wrapped . errors , "Found an invalid Signed Element. SAML Response rejected"
1302+ end
1303+ end
1304+
1305+ describe "signature wrapping attack - concealed SAML response body" do
1306+ it "should not be valid" do
1307+ signature_wrapping_attack = read_invalid_response ( "response_with_concealed_signed_assertion.xml" )
1308+ response_wrapped = OneLogin ::RubySaml ::Response . new ( signature_wrapping_attack , :settings => settings )
1309+ settings . idp_cert_fingerprint = '4b68c453c7d994aad9025c99d5efcf566287fe8d'
1310+ response_wrapped . stubs ( :conditions ) . returns ( nil )
1311+ response_wrapped . stubs ( :validate_subject_confirmation ) . returns ( true )
1312+ assert !response_wrapped . is_valid?
1313+ assert_includes response_wrapped . errors , "SAML Response must contain 1 assertion"
1314+ end
1315+ end
1316+
1317+ describe "signature wrapping attack - doubled signed assertion SAML response" do
1318+ it "should not be valid" do
1319+ signature_wrapping_attack = read_invalid_response ( "response_with_doubled_signed_assertion.xml" )
1320+ response_wrapped = OneLogin ::RubySaml ::Response . new ( signature_wrapping_attack , :settings => settings )
1321+ settings . idp_cert_fingerprint = '4b68c453c7d994aad9025c99d5efcf566287fe8d'
1322+ response_wrapped . stubs ( :conditions ) . returns ( nil )
1323+ response_wrapped . stubs ( :validate_subject_confirmation ) . returns ( true )
1324+ assert !response_wrapped . is_valid?
1325+ assert_includes response_wrapped . errors , "SAML Response must contain 1 assertion"
1326+ end
1327+ end
1328+
12911329end
0 commit comments