Repository navigation
Description
We're having a bit of an unexcpected behaviour with SimpleSAMLphp running as SP. After successful login, if the user clicks on the back button in the browser, saml2-acs.php throws an unhandled exception:
Unsolicited Response MUST NOT contain InResponseTo. Got: SOME_ID
As far as I can tell, the issue lies with how SimpleSAMLphp handles states. Before user is redirected to IdP's login page, a state is created by SimpleSAMLphp. ID of that state is sent in POST to the IdP during authentication process. It then deletes that state, after saving all the necessary data to the store defined in the config (in our case - Memcache). It also saves the Response ID to a prevAuth array, so it can be identified if, for whatever reason, it is resent.
When user presses back button in their browser, they resend the authentication request. I assume because IdP has no way of knowing that the old state doesn't exist in SimpleSAMLphp anymore, it treats the request as a new one, and assigns a new Response ID. This means, the mechanism in assertionConsumerService function, which is supposed to catch such an event, doesn't trigger ($prevAuth['ID'] !== $response->getId()), and response is processesed as Unsolicited. However, because it's not really Unsolicited, it has an InResponseTo value set, causing the exception to be thrown.
Specifics of your environment
- Are you acting as SP/IdP/proxy?
- SimpleSAMLphp acts as SP
- SimpleSAMLphp: What version are you using?
- 2.4.10
- PHP: What version are you using?
- 8.2
- Platform: unix or Windows?
- Linux (Debian 12)
- Webserver: Apache/Nginx/ISS?
- Apache2 2.4.68
Describe the bug
Pressing "Back" button in the browser right after logging in throws an unhandled exception:
Unsolicited Response MUST NOT contain InResponseTo. Got: SOME_ID
To Reproduce
Steps to reproduce the behavior:
- Log into your remote IdP
- Click on "Back" button in the browser
- See error
Expected behavior
User is moved to a page before triggering the IdP logging behaviour, or, if impossible, redirected back on the same page they clicked "Back" button from.
Screenshots or logs
Start:
Oct 14 08:26:24 simplesamlphp DEBUG [2830826d0a] Session: 'IdP_Name' not valid because we are not authenticated.
Oct 14 08:26:24 simplesamlphp DEBUG [2830826d0a] saving key .session.SESSION-KEY-ID to memcache
IdP Login page:
Oct 14 08:28:40 simplesamlphp DEBUG [2830826d0a] loading key .session.SESSION-KEY-ID from memcache
Oct 14 08:28:40 simplesamlphp DEBUG [2830826d0a] Saved state: '_STATE-ID' // _acfc0415b18578645cb631d7818df892192fab06a7
Oct 14 08:28:40 simplesamlphp DEBUG [2830826d0a] Sending SAML 2 AuthnRequest to 'https://My-Keycloak-Instance.com/realms/My-Realm
Oct 14 08:28:40 simplesamlphp DEBUG [2830826d0a] Redirect to 1252 byte URL: https://My-Keycloak-Instance.com/realms/My-Realm/protocol/saml?(...)
Oct 14 08:28:40 simplesamlphp DEBUG [2830826d0a] saving key .session.SESSION-KEY-ID to memcache
IdP Post-Login Redirect:
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] loading key .session.SESSION-KEY-ID from memcache
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] Loading state: '_STATE-ID'
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] Received SAML2 Response from 'https://My-Keycloak-Instance.com/realms/My-Realm'.
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] Has 1 candidate keys for validation.
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] Validation with key #0 succeeded.
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] Decryption with key #0 succeeded.
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] Has 1 candidate keys for validation.
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] Validation with key #0 failed without exception.
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] loading key .saml.AssertionReceived.ID_ASSERTION-ID from memcache
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] key .saml.AssertionReceived.ID_ASSERTION-ID not found in memcache
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] saving key .saml.AssertionReceived.ID_ASSERTION-ID to memcache
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] saving key .saml.LogoutStore.LOGOUTSTORE-ID to memcache
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] Filter config for https://My-Keycloak-Instance.com/realms/My-Realm->My-Realm>: Array( [0] => SimpleSAML\Module\core\Auth\Process\LanguageAdaptor Object ( [priority] => 90 [precondition] => return true; [langattr:SimpleSAML\Module\core\Auth\Process\LanguageAdaptor:private] => preferredLanguage ))
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] Deleting state: '_STATE-ID'
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] Session: doLogin("My-IDP")
Oct 14 08:31:41 simplesamlphp DEBUG [2830826d0a] saving key .session.SESSION-KEY-ID to memcache
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] loading key .session.SESSION-KEY-ID from memcache
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] Localization: load domain 'messages' at '/var/simplesamlphp/locales'
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] Trying langpath for 'pl' as '/var/simplesamlphp/locales/pl/LC_MESSAGES/'
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] Localization: load domain 'core' at '/var/simplesamlphp/modules/core/locales'
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] Trying langpath for 'pl' as '/var/simplesamlphp/modules/core/locales/pl/LC_MESSAGES/'
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] Localization: load domain 'attributes' at '/var/simplesamlphp/locales'
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] Trying langpath for 'pl' as '/var/simplesamlphp/locales/pl/LC_MESSAGES/'
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] saving key .session.SESSION-KEY-ID to memcache
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] loading key .session.SESSION-KEY-ID from memcache
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] Session: Valid session found with 'My-IDP'.
Oct 14 08:31:42 simplesamlphp DEBUG [2830826d0a] Session: Valid session found with 'My-IDP'.
Back Button clicked:
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] loading key .session.SESSION-KEY-ID from memcache
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Loading state: '_STATE-ID'
Oct 14 08:37:27 simplesamlphp WARNING [2830826d0a] Could not load state specified by InResponseTo: NOSTATE Processing response as unsolicited.
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Received SAML2 Response from 'https://My-Keycloak-Instance.com/realms/My-Realm'.
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Has 1 candidate keys for validation.
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Validation with key #0 succeeded.
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] SimpleSAML\Error\Error: UNHANDLEDEXCEPTION
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] Backtrace:
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] 2 /var/simplesamlphp/src/SimpleSAML/Error/ExceptionHandler.php:36 (SimpleSAML\Error\ExceptionHandler::customExceptionHandler)
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] 1 /var/simplesamlphp/vendor/symfony/error-handler/ErrorHandler.php:538 (Symfony\Component\ErrorHandler\ErrorHandler::handleException)
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] 0 [builtin] (N/A)
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] Caused by: SimpleSAML\Error\Exception: Unsolicited Response MUST NOT contain InResponseTo. Got: '_acfc0415b18578645cb631d7818df892192fab06a7'
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] Backtrace:
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] 6 /var/simplesamlphp/modules/saml/src/Message.php:682 (SimpleSAML\Module\saml\Message::processResponse)
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] 5 /var/simplesamlphp/modules/saml/src/Controller/ServiceProvider.php:417 (SimpleSAML\Module\saml\Controller\ServiceProvider::assertionConsumerService)
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] 4 /var/simplesamlphp/vendor/symfony/http-kernel/HttpKernel.php:181 (Symfony\Component\HttpKernel\HttpKernel::handleRaw)
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] 3 /var/simplesamlphp/vendor/symfony/http-kernel/HttpKernel.php:76 (Symfony\Component\HttpKernel\HttpKernel::handle)
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] 2 /var/simplesamlphp/vendor/symfony/http-kernel/Kernel.php:208 (Symfony\Component\HttpKernel\Kernel::handle)
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] 1 /var/simplesamlphp/src/SimpleSAML/Module.php:234 (SimpleSAML\Module::process)
Oct 14 08:37:27 simplesamlphp ERROR [2830826d0a] 0 /var/simplesamlphp/public/module.php:17 (N/A)
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Session: Valid session found with 'My-IDP'.
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Localization: load domain 'messages' at '/var/simplesamlphp/locales'
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Trying langpath for 'pl' as '/var/simplesamlphp/locales/pl/LC_MESSAGES/'
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Localization: load domain 'core' at '/var/simplesamlphp/modules/core/locales'
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Trying langpath for 'pl' as '/var/simplesamlphp/modules/core/locales/pl/LC_MESSAGES/'
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Localization: load domain 'attributes' at '/var/simplesamlphp/locales'
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] Trying langpath for 'pl' as '/var/simplesamlphp/locales/pl/LC_MESSAGES/'
Oct 14 08:37:27 simplesamlphp DEBUG [2830826d0a] saving key .session.SESSION-KEY-ID to memcache
Additional context
IdP: Keycloak 26.8.0
SimpleSAMLphp Store Type: Memcache
Activity
tbone-tech commentedon Oct 23, 2026
We are experiencing this same bug also, after uprading simple saml 2.5.3.1 the latest version, we experience the issue with multiple IDP's it. When I tested I did with entra, I logged in successfull then once I hit our app I hit back button and went back to microsoft page it had a error, but then if I hit back once again it would go to simple saml page and give the same error as explained above. Shows in browser but also will show in my simple saml logs .
tbone-tech commentedon Nov 2, 2026
I had our developer create a workaround for this is someone hits back button its corrects its self, we made change in the ServiceProvider.php
DSK-IFJ commentedon Nov 25, 2026
@tbone-tech Can you share the workaround you ended up using?
tvdijen commentedon Nov 25, 2026
That would be very helpful indeed! Also, perhaps you could persuade your developer into opening a pull request?
tbone-tech commentedon Nov 25, 2026
ServiceProvider.php here is the file I have them modify. THis should be the extra code they added to fix this .
tvdijen commentedon Nov 25, 2026
Thanks! This could be useful when doing some debugging.. It's probably not a patch that should ever see production
tbone-tech commentedon Nov 25, 2026
well we have that for now , as we had no other fix, hopefully you can come up with something that would work better
DSK-IFJ commentedon Dec 3, 2026
Unfortunately the temporary fix doesn't work for us on 2.4.10 . Now we're getting
Exception: The POST data we should restore was lost.from the
/var/simplesamlphp/modules/core/src/Controller/Redirection.phpI dug a bit there and it seems that, with Keycloak, we already "use up" our one opportuninty to restore POST data by triggering the
postredirectfunction after login. Data is deleted first time it is accessed with this function, so we cannot retrieve it again.Commenting out the
deleteDataline fixes it, but, correct me if I'm wrong, I believe it would compromize security even further, so I'm hesitant to apply such a "fix" in prod.