Skip to content

SSP-Improved_Error_Messaging_for_Invalid_Signatures - #2506

Merged
monkeyiq merged 5 commits into
simplesamlphp:simplesamlphp-2.5from
ioigoume:SSP-Improved_Error_Messaging_for_Invalid_Signatures
Sep 1, 2025
Merged

monkeyiq merged 5 commits into
simplesamlphp:simplesamlphp-2.5from
ioigoume:SSP-Improved_Error_Messaging_for_Invalid_Signatures

Conversation

@ioigoume

Copy link
Copy Markdown
Contributor

Improve Error Messaging on checkSign failure.

Comment thread modules/saml/src/Message.php Resolved
Comment thread tests/modules/saml/MessageTest.php Outdated
{
$this->acmeeEntityId = 'https://idp.acmee.com/example';

$this->acmeeCertificate = <<<EOCERTVALID

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's see if we can replace these test-keys with the ones available in simplesamlphp/xml-security.. We can pull them in using the PEMCertificatesMock-class

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@tvdijen thank you for the hint. I will update the PR later today

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@tvdijen the PEMCertificatesMock class is really helpful! I replaced the hard coded certificates and removed the certs directory since it is not longer required.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, it's a great tool for testing :) Really helps to keep our tests clean.
Thanks for the updated PR! This is ready for merging now

@monkeyiq

monkeyiq commented Aug 29, 2025 •

Copy link
Copy Markdown
Contributor

I have been testing trying to break stuff. So I added in checkSign a throw new SignatureVerificationFailedException after the $element->validate to force an issue on my rig. If I add that line and use admin/test to login to an authsource I see a page with title_0 and descr_0 in the header.

In the new $lastException = new SSP_Error\Error( code if I add in

 'errorCode' => $e->getErrorCode(),

then the SimpleSAML\Error\Error ctor can set

$this->dictTitle = $errorCodes->getTitle($this->errorCode);
$this->dictDescr = $errorCodes->getDescription($this->errorCode);

I may be doing something wrong here but I thought I'd see what a strategically placed wrench might look like.

@ioigoume

Copy link
Copy Markdown
Contributor Author

I have been testing trying to break stuff. So I added in checkSign a throw new SignatureVerificationFailedException after the $element->validate to force an issue on my rig. If I add that line and use admin/test to login to an authsource I see a page with title_0 and descr_0 in the header.

In the new $lastException = new SSP_Error\Error( code if I add in

 'errorCode' => $e->getErrorCode(),

then the SimpleSAML\Error\Error ctor can set

$this->dictTitle = $errorCodes->getTitle($this->errorCode);
$this->dictDescr = $errorCodes->getDescription($this->errorCode);

I may be doing something wrong here but I thought I'd see what a strategically placed wrench might look like.

@monkeyiq thank you for testing this. I will work on this today and update the Pull Request.

@ioigoume
ioigoume requested a review from monkeyiq August 30, 2025 06:34
@ioigoume

Copy link
Copy Markdown
Contributor Author

@monkeyiq i fixed the issue. Can you please recheck?

@monkeyiq

Copy link
Copy Markdown
Contributor

@ioigoume looks good!

I now see:

Invalid certificate signature
Unable to validate certificate signature.

... when I force the issue by throwing the exception :)

@monkeyiq

monkeyiq commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

Looking at the issue where this was raised (#2505) some of the goals including knowing the issuer and entityid where this failed. With this PR it is passed but it took a moment to see how to see it....

Digging in along those lines, with this PR in place the error.twig page can access this data through the parameters array:

<br/>issuer   {{ parameters['issuer'] }}
<br/>entityid {{ parameters['entityid'] }}

A few options present themselves here

(a) the error.twig include some commented out information about this and the docs include information for those who want to get at those values but do not want to search for how to do it. This would also include some indication of if/when one might expect those values to be populated.

(b) like above but elevate them to top level issuer/entityid twig parameters similar to what is done for $data['module'] in Error::show() for example.

(c) something better that can be here.

@monkeyiq

monkeyiq commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

For my testing I see that the element class name SAML2\Response is passed in error.twig

{{ parameters['element'] }}

So that could either be switched on in the twig or something else to better display if the error was raised while processing a Response or a authn request.

Is it worthwhile supporting making a more verbose message in Error::show that explains if this is a Response or Authn related? If that is commonly desired to show maybe we should explicitly export that to the twig page rather than only through parameters['element'] ?

@ioigoume

ioigoume commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

For my testing I see that the element class name SAML2\Response is passed in error.twig

{{ parameters['element'] }}

So that could either be switched on in the twig or something else to better display if the error was raised while processing a Response or a authn request.

Is it worthwhile supporting making a more verbose message in Error::show that explains if this is a Response or Authn related? If that is commonly desired to show maybe we should explicitly export that to the twig page rather than only through parameters['element'] ?

@monkeyiq
This fix primarily enhances the propagation of additional information related to exceptions thrown by the checkSign method. This supplementary data can subsequently be utilized both in custom themes and the default theme; however, the way i understood it, modifications to the default theme are outside the scope of this pull request.

For instance, we could process this information within the Controller to construct more informative error messages, which would then be rendered by the view. I am uncertain whether such front-end message improvements should be included in this pull request or addressed separately. We could consider a dedicated PR, as part of the original issue, to further refine how error messages are presented to users. error.twig

Additionally, what do you consider a meaningful error message in this context? Should we vary the verbosity of these messages based on whether SSP is configured for production or development environments?

@monkeyiq

monkeyiq commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

I guess part of my mentioning here is to capture info I found during testing. I will know that {{ parameters['entityid'] }} is interesting and if anyone else is searching around they will likely find this PR by back tracking the source code and see the additional info.

This PR certainly allows that info to propagate back :)

@monkeyiq

monkeyiq commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

Given the 2 approvals I will merge this tomorrow and pick it to master.

@ioigoume thank you for the contribution!

@monkeyiq
monkeyiq merged commit 8b26c66 into simplesamlphp:simplesamlphp-2.5 Sep 1, 2025
monkeyiq pushed a commit that referenced this pull request Sep 1, 2025
* Improve Error Messaging on checkSign failure when the certificate is invalid.

* update error message check in testing

* Use PEMCertificateMock instead of hardcoded certificates

* Fix title_0 issue.Add NOTVALIDCERTIFICATESIGNATURE error code.

* Fix tests
@ioigoume
ioigoume deleted the SSP-Improved_Error_Messaging_for_Invalid_Signatures branch September 2, 2025 06:23
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants