Skip to content

Improved Error Messaging for Invalid Signatures #2505

Open

Description

@pradtke

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:

  1. Indicate the affected SP or IdP entityId
  2. 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.

@ioigoume is figuring out how this could work.

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.

Activity

  1. tvdijen commented on Aug 27, 2025

    @tvdijen
    Member

    Any guidance on this would be appreciated.

    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.

  2. ioigoume commented on Aug 28, 2025

    @ioigoume
    Contributor

    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 checkSign method with the proposed changes.

    I can open a Pull Request if it is more helpful.

        public static function checkSign(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 ($keys as $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 {
                throw new SSP_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 ($pemKeys as $i => $pem) {
                $key = new XMLSecurityKey(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.');
                        return true;
                    }
                    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 = new SSP_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 keys
            if ($lastException !== null) {
                throw $lastException;
            } else {
                return false;
            }
        }
  3. tvdijen commented on Aug 28, 2025

    @tvdijen
    Member

    Seems fine with me @ioigoume ! I'll gladly accept your pull requeest

  4. ioigoume commented on Aug 28, 2025

    @ioigoume
    Contributor

    @tvdijen i will have it ready in the next couple of hours and ping you. Thank you!

  5. ioigoume commented on Aug 28, 2025

    @ioigoume
    Contributor

    @tvdijen i opened PR-2506

  6. monkeyiq commented on Sep 2, 2025

    @monkeyiq
    Contributor

    A good move on this has been made with #2506

    As I mentioned for my testing on 2506 it does allow the issuer and entityid to be seen from the error.twig template.

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

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions