Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More specific error messages for request certificate validation #545

Conversation

FabioCareMonkey
Copy link

@FabioCareMonkey FabioCareMonkey commented Sep 19, 2020

When validations find that the SAML request certificate does not match idp certificate they report the generic error message "Response signature validation failed";
This PR adds a more specific message for this scenario.

additionally the 'soff' variable which is required when calling the "append_error" method was not passed down to the 'validate_document_with_cert' method. This is also fixed

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.884% when pulling 229221e on FabioCareMonkey:bugfix-missing-soft-variable into 63f43a7 on onelogin:master.

@coveralls
Copy link

coveralls commented Sep 19, 2020

Coverage Status

Coverage increased (+0.1%) to 98.008% when pulling 9dbfe66 on FabioCareMonkey:bugfix-missing-soft-variable into 63f43a7 on onelogin:master.

@@ -241,7 +241,7 @@ def validate_document(idp_cert_fingerprint, soft = true, options = {})
validate_signature(base64_cert, soft)
end

def validate_document_with_cert(idp_cert)
def validate_document_with_cert(idp_cert, soft = true)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the softvariable (from line 258) was missing on the scope of this method

@FabioCareMonkey FabioCareMonkey changed the title Bugfix missing soft variable More specific error message for SAML request certificate validation Sep 19, 2020
Comment on lines +398 to +401
let(:document_data) { read_response('response_with_signed_message_and_assertion.xml') }
let(:document) { OneLogin::RubySaml::Response.new(document_data).document }
let(:idp_cert) { OpenSSL::X509::Certificate.new(ruby_saml_cert_text) }
let(:fingerprint) { '4b68c453c7d994aad9025c99d5efcf566287fe8d' }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved these up a couple of levels to reuse them in the other tests at this level

@FabioCareMonkey FabioCareMonkey changed the title More specific error message for SAML request certificate validation More specific error messages for request certificate validation Sep 19, 2020
"<ds:X509Certificate>an-invalid-certificate</ds:X509Certificate>")
end

it 'is not valid' do
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would fail on the current version of the gem (and it should not)

@@ -863,8 +863,12 @@ def validate_signature
valid = false
expired = false
idp_certs[:signing].each do |idp_cert|
valid = doc.validate_document_with_cert(idp_cert)
valid = doc.validate_document_with_cert(idp_cert, true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be used

valid = doc.validate_document_with_cert(idp_cert, @soft)

instead

 valid = doc.validate_document_with_cert(idp_cert, true)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cannot use the @soft variable here, as it would raise if any of the certificates is invalid (when @soft is false). this validation is required to be soft in the loop.

I will adjust the code as per your second comment. and using the soft variable to determine if it should raise after validating all certificates

end

# check saml response cert matches provided idp cert
if idp_cert.to_pem != cert.to_pem
return false
return append_error("Document certificate does not match idp certificate", soft)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an environment where multiple idps cert are registered , that error gonna be registered for each validation executed.
In my opinion, this error should not be registered here because can't confuse the admin reviewing the logs.

I'm ok raising an error that none of the registered certs matched the certificate in the document which will require some refactor in the code,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let me know what you think about the new changes

@pitbulk
Copy link
Collaborator

pitbulk commented Feb 17, 2021

Followed a similar approach at: 59b9ade

@pitbulk pitbulk closed this Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants