You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improved Error Messaging for Invalid Signatures #2505
Currently when SSP is unable to verify the signature on an assertion or an authnrequest it displays an error like "Unable to validate Signature". This message is accurate, but means the support request we/Cirrus receive always start with "What does this mean?", and we would like to improve that process by providing a more informative message. I believe this could be useful to the SSP project in general, since the mailing list/slack do get similar questions.
We propose improving the error messaging to:
Indicate the affected SP or IdP entityId
Provide corrective instructions/hints
For our own theme's error template we want to know the entityId and if we are processing a saml response or an authn request when the error happened.
Currently we are thinking of adjustment to Message checkSign to wrap $lastException to include the entityId and SignedElement class to use in an improved message.
An area I have little experience is how to tie this into the error page to display an informative message. I see some areas where SSP subclasses SimpleSAML\Error\Exception, and some we use Error class and some times just use SimpleSAML\Error\Exception directly. Any guidance on this would be appreciated.
Lastly, what would the default, more informative message say? We were thinking something like " is signing messages with a new key. Please provide your admin with the new metadata for "
Please let us know if this seems useful for the project, and Ioannis can build out this improvement.
It's a bit unclear to me too, even after 10 years working on this project :')
I see some areas where SSP subclasses SimpleSAML\Error\Exception, and some we use Error class and some times just use SimpleSAML\Error\Exception directly. Any guidance on this would be appreciated.
I believe SimpleSAML\Error\Exception is more like a base-class that probably shouldn't be used directly.
You can use SimpleSAML\Error\Error if you just want to change the error-message on an otherwise generic error-page, or you can create a subclass of it (i.e. SignatureVerificationError). This would allow you to use a custom twig-template for this type of error to display the info you want to add.
To follow up on the above, the change we propose for the core SimpleSAMLphp code is to enhance signature validation error handling so that exceptions include key context such as the affected entityId, the SAML message type (e.g., Response or AuthnRequest), and probably a more descriptive error message. This context will be made available to error templates, allowing us to present clearer, more actionable error messages to end users.
Here under i paste the checkSign method with the proposed changes.
I can open a Pull Request if it is more helpful.
publicstaticfunctioncheckSign(Configuration$srcMetadata, SignedElement$element): bool
{
// find the public key that should verify signatures by this entity$keys = $srcMetadata->getPublicKeys('signing');
if (!empty($keys)) {
$pemKeys = [];
foreach ($keysas$key) {
switch ($key['type']) {
case'X509Certificate':
$pemKeys[] = "-----BEGIN CERTIFICATE-----\n" .
chunk_split($key['X509Certificate'], 64) .
"-----END CERTIFICATE-----\n";
break;
default:
Logger::debug('Skipping unknown key type: ' . $key['type']);
}
}
} else {
thrownewSSP_Error\Exception(
'Missing certificate in metadata for ' .
var_export($srcMetadata->getString('entityid'), true),
);
}
Logger::debug('Has ' . count($pemKeys) . ' candidate keys for validation.');
$lastException = null;
foreach ($pemKeysas$i => $pem) {
$key = newXMLSecurityKey(XMLSecurityKey::RSA_SHA256, ['type' => 'public']);
$key->loadKey($pem);
try {
// make sure that we have a valid signature on either the response or the assertion$res = $element->validate($key);
if ($res) {
Logger::debug('Validation with key #' . $i . ' succeeded.');
returntrue;
}
Logger::debug('Validation with key #' . $i . ' failed without exception.');
} catch (\Exception$e) {
Logger::debug('Check Signature for ' . get_class($element) . ' element');
Logger::debug('EntityID: ' . $srcMetadata->getString('entityid'));
Logger::debug('Validation with key #' . $i . ' failed with exception: ' . $e->getMessage());
// Clone the exception and improve the message// This form does not give us the opportunity to pass more error related information like the one below.// $lastException = new SSP_Error\Exception(// $element->getIssuer()->getValue(). '::' . get_class($element) . ' - ' . $e->getMessage(),// $e->getCode(),// $e->getPrevious()// );$lastException = newSSP_Error\Error(
[
(string)$e->getCode(),
'element' => get_class($element),
'message' => $e->getMessage(),
'issuer' => $element->getIssuer()->getValue(),
'entityid' => $srcMetadata->getString('entityid'),
]
);
}
}
// we were unable to validate the signature with any of our keysif ($lastException !== null) {
throw$lastException;
} else {
returnfalse;
}
}
The type of exception is also available in {{ parameters['element'] }}.
The above gives more info about the error and the element should allow the template to differentiate a bit on the type of error.
I like the idea of adding more logic in Error::show() so that we can export more verbose, user friendly messages for error.twig to possibly use to show the user as the example about the "new key". I guess for that it makes sense toi take a look at what happens when one forces one of those exceptions to happen in checkSign.
I am thinking we should perhaps inclode the above issuer/entityid info as comments in the default error.twig to allow people to see what information might be on offer without having to find that by manual digging into the code itself.
Activity
tvdijen commentedon Aug 27, 2025
It's a bit unclear to me too, even after 10 years working on this project :')
I believe
SimpleSAML\Error\Exceptionis more like a base-class that probably shouldn't be used directly.You can use
SimpleSAML\Error\Errorif you just want to change the error-message on an otherwise generic error-page, or you can create a subclass of it (i.e. SignatureVerificationError). This would allow you to use a custom twig-template for this type of error to display the info you want to add.ioigoume commentedon Aug 28, 2025
Hi @tvdijen ,
To follow up on the above, the change we propose for the core SimpleSAMLphp code is to enhance signature validation error handling so that exceptions include key context such as the affected
entityId, the SAML message type (e.g., Response or AuthnRequest), and probably a more descriptive error message. This context will be made available to error templates, allowing us to present clearer, more actionable error messages to end users.Here under i paste the
checkSignmethod with the proposed changes.I can open a Pull Request if it is more helpful.
tvdijen commentedon Aug 28, 2025
Seems fine with me @ioigoume ! I'll gladly accept your pull requeest
ioigoume commentedon Aug 28, 2025
@tvdijen i will have it ready in the next couple of hours and ping you. Thank you!
ioigoume commentedon Aug 28, 2025
@tvdijen i opened PR-2506
monkeyiq commentedon Sep 2, 2025
A good move on this has been made with #2506
As I mentioned for my testing on 2506 it does allow the
issuerandentityidto be seen from theerror.twigtemplate.The type of exception is also available in
{{ parameters['element'] }}.The above gives more info about the error and the element should allow the template to differentiate a bit on the type of error.
I like the idea of adding more logic in
Error::show()so that we can export more verbose, user friendly messages for error.twig to possibly use to show the user as the example about the "new key". I guess for that it makes sense toi take a look at what happens when one forces one of those exceptions to happen incheckSign.I am thinking we should perhaps inclode the above issuer/entityid info as comments in the default error.twig to allow people to see what information might be on offer without having to find that by manual digging into the code itself.