Skip to content

Commit d7c6806

Browse files
committed
Keep a pending login bound to the SP behind a proxy
commit 0a8c35252bccfc448fa8d41fc677c0ec749351c9 Author: Johan Kromhout <johan.kromhout@dawn.tech> Date: Tue Nov 24 16:19:56 2026 +0100 Keep a pending login bound to the SP behind a proxy Prior to this change, a pending login started through a trusted proxy was bound to the proxy, but not to the Service Provider behind it. This change also binds the pending login to the Service Provider the trusted proxy acts for, so the login only continues for that Service Provider. Ref: GHSA-753q-m5jf-v3m2 commit 5b68afda5c38e84d18636963aecd0720616cf9d7 Author: Johan Kromhout <johan.kromhout@dawn.tech> Date: Tue Nov 24 15:28:30 2026 +0100 Keep a pending login bound to the SP that started it Prior to this change, a pending login was not strictly tied to the Service Provider that started it. This change binds a pending login to its Service Provider and continues with the exact request that was sent to the IdP. Logins in flight during the upgrade end with a session lost error and must be restarted. Ref: GHSA-753q-m5jf-v3m2
1 parent e963719 commit d7c6806

11 files changed

Lines changed: 524 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ More information about our release strategy can be found in
1111
the [Development Guidelines](https://github.com/OpenConext/OpenConext-engineblock/wiki/Development-Guidelines#release-notes)
1212
on the EngineBlock wiki.
1313

14+
## 7.3.1
15+
Security:
16+
17+
* A login in progress now stays bound to the Service Provider that started it. EngineBlock rejects an AuthnRequest
18+
whose ID is already in use in the same session by another Service Provider, including another Service Provider behind
19+
the same trusted proxy. After the IdP responds, EngineBlock continues with the exact request it sent to the IdP.
20+
* Logins that are in progress during the upgrade end with a "session lost" error after the IdP responds. The user has
21+
to log in again.
22+
23+
1424
## 7.3.0
1525

1626
Features:

‎library/EngineBlock/Corto/Module/Bindings.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@ public function receiveRequest()
184184
);
185185
}
186186

187+
try {
188+
EngineBlock_ApplicationSingleton::getInstance()->getDiContainer()
189+
->getAuthnRequestSessionRepository()
190+
->assertRequestIdNotUsedByOtherIssuer($ebRequest);
191+
} catch (EngineBlock_Corto_Module_Bindings_Exception $e) {
192+
$this->_logger->warning(
193+
'Rejected AuthnRequest: its ID is already in use in this session by another Service Provider',
194+
[
195+
'request_id' => $ebRequest->getId(),
196+
'issuer' => $ebRequest->getIssuer()->getValue(),
197+
'requester_ids' => $ebRequest->getRequesterIds(),
198+
]
199+
);
200+
throw $e;
201+
}
202+
187203
EngineBlock_ApplicationSingleton::getInstance()->getDiContainerRuntime()->feedbackStateHelper->startNewFlow(
188204
$ebRequest->getId(),
189205
$ebRequest->getIssuer()->getValue()

‎library/EngineBlock/Corto/ProxyServer.php‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,10 +1123,16 @@ public function findRequestFromRequestId(string $requestId): ?EngineBlock_Saml2_
11231123
);
11241124
}
11251125

1126-
$spRequest = $authnRequestRepository->findRequestById($spRequestId);
1127-
if (!$spRequest) {
1128-
throw new EngineBlock_Corto_ProxyServer_Exception(
1129-
'Response has no known Request',
1126+
// Resolve the SP request that was linked when we sent our request to the IdP. Looking it up by the
1127+
// SP-chosen ID would return whatever request last used that ID in this session.
1128+
$spRequest = $authnRequestRepository->findLinkedRequest($requestId);
1129+
if ($spRequest === null) {
1130+
throw new EngineBlock_Corto_Module_Services_SessionLostException(
1131+
sprintf(
1132+
'Linked request snapshot missing for AuthnRequest (we made and sent) with id "%s". '.
1133+
'Likely the session was started before an upgrade, the user has to log in again.',
1134+
$requestId
1135+
),
11301136
EngineBlock_Corto_ProxyServer_Exception::CODE_NOTICE
11311137
);
11321138
}

‎library/EngineBlock/Saml2/AuthnRequestSessionRepository.php‎

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@
2222
/**
2323
* Session storage for Authentication Requests. Store AuthnRequests and link requests together.
2424
*
25-
* Uses the Symfony session bag under two keys:
26-
* 'SAMLRequest' — map of requestId => AuthnRequestAnnotationDecorator
27-
* 'SAMLRequestLinks' — map of idpRequestId => spRequestId
25+
* Uses the Symfony session bag under three keys:
26+
* 'SAMLRequest' — map of requestId => AuthnRequestAnnotationDecorator
27+
* 'SAMLRequestLinks' — map of idpRequestId => spRequestId
28+
* 'SAMLRequestLinkedRequests' — map of idpRequestId => AuthnRequestAnnotationDecorator
29+
*
30+
* 'SAMLRequest' is keyed on the ID chosen by the SP and can therefore be overwritten by a later request.
31+
* Lookups after the IdP has responded must use findLinkedRequest(), which is keyed on the ID generated
32+
* by EngineBlock and returns the exact request that was sent to the IdP.
2833
*
2934
* All methods are safe no-ops when no session is available (unit tests, CLI).
3035
*/
3136
class EngineBlock_Saml2_AuthnRequestSessionRepository
3237
{
3338
private const string SESSION_KEY_REQUESTS = 'SAMLRequest';
3439
private const string SESSION_KEY_LINKS = 'SAMLRequestLinks';
40+
private const string SESSION_KEY_LINKED_REQUESTS = 'SAMLRequestLinkedRequests';
3541

3642
/**
3743
* @var RequestStack
@@ -77,6 +83,21 @@ public function findLinkedRequestId($requestId)
7783
return $session->get(self::SESSION_KEY_LINKS, [])[$requestId] ?? null;
7884
}
7985

86+
public function findLinkedRequest(?string $requestId): ?EngineBlock_Saml2_AuthnRequestAnnotationDecorator
87+
{
88+
if (!$requestId) {
89+
return null;
90+
}
91+
92+
try {
93+
$session = $this->requestStack->getSession();
94+
} catch (SessionNotFoundException $e) {
95+
return null;
96+
}
97+
98+
return $session->get(self::SESSION_KEY_LINKED_REQUESTS, [])[$requestId] ?? null;
99+
}
100+
80101
/**
81102
* @param EngineBlock_Saml2_AuthnRequestAnnotationDecorator $spRequest
82103
* @return $this
@@ -90,12 +111,49 @@ public function store(EngineBlock_Saml2_AuthnRequestAnnotationDecorator $spReque
90111
}
91112

92113
$requests = $session->get(self::SESSION_KEY_REQUESTS, []);
114+
$this->assertNoIssuerConflict($requests[$spRequest->getId()] ?? null, $spRequest);
93115
$requests[$spRequest->getId()] = $spRequest;
94116
$session->set(self::SESSION_KEY_REQUESTS, $requests);
95117

96118
return $this;
97119
}
98120

121+
/**
122+
* A request ID in this session may never be reused by a different Service Provider, as the consent and
123+
* processing state are keyed on the request ID alone. A trusted proxy uses its last RequesterID to identify
124+
* the Service Provider behind it, so that RequesterID must match as well.
125+
*
126+
* @throws EngineBlock_Corto_Module_Bindings_Exception
127+
*/
128+
public function assertRequestIdNotUsedByOtherIssuer(EngineBlock_Saml2_AuthnRequestAnnotationDecorator $request): void
129+
{
130+
$this->assertNoIssuerConflict($this->findRequestById($request->getId()), $request);
131+
}
132+
133+
private function assertNoIssuerConflict(
134+
?EngineBlock_Saml2_AuthnRequestAnnotationDecorator $existing,
135+
EngineBlock_Saml2_AuthnRequestAnnotationDecorator $new
136+
): void {
137+
if ($existing === null) {
138+
return;
139+
}
140+
141+
if ($existing->getIssuer()?->getValue() !== $new->getIssuer()?->getValue()
142+
|| $this->getLastRequesterId($existing) !== $this->getLastRequesterId($new)
143+
) {
144+
throw new EngineBlock_Corto_Module_Bindings_Exception(
145+
'AuthnRequest ID is already in use in this session by another Service Provider'
146+
);
147+
}
148+
}
149+
150+
private function getLastRequesterId(EngineBlock_Saml2_AuthnRequestAnnotationDecorator $request): ?string
151+
{
152+
$requesterIds = $request->getRequesterIds();
153+
154+
return empty($requesterIds) ? null : end($requesterIds);
155+
}
156+
99157
/**
100158
* @param EngineBlock_Saml2_AuthnRequestAnnotationDecorator $fromRequest
101159
* @param EngineBlock_Saml2_AuthnRequestAnnotationDecorator $toRequest
@@ -115,6 +173,10 @@ public function link(
115173
$links[$fromRequest->getId()] = $toRequest->getId();
116174
$session->set(self::SESSION_KEY_LINKS, $links);
117175

176+
$linkedRequests = $session->get(self::SESSION_KEY_LINKED_REQUESTS, []);
177+
$linkedRequests[$fromRequest->getId()] = $toRequest;
178+
$session->set(self::SESSION_KEY_LINKED_REQUESTS, $linkedRequests);
179+
118180
return $this;
119181
}
120182
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
Feature:
2+
In order to make sure access rules are enforced for the Service Provider that started a login
3+
As an EngineBlock
4+
I want a pending login to stay bound to that Service Provider, even if another one reuses its AuthnRequest ID
5+
6+
Background:
7+
Given an EngineBlock instance on "dev.openconext.local"
8+
And no registered SPs
9+
And no registered Idps
10+
And an Identity Provider named "Reuse-IdP"
11+
And an Identity Provider named "Other-IdP"
12+
And a Service Provider named "Easy-SP"
13+
And a Service Provider named "Target-SP"
14+
And a Service Provider named "Proxy-SP"
15+
And SP "Easy-SP" is not connected to IdP "Other-IdP"
16+
17+
Scenario: Control - a policy enforcement deny on Target-SP denies access
18+
Given SP "Target-SP" requires a policy enforcement decision
19+
And SP "Target-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
20+
And pdp gives a deny response
21+
When I log in at "Target-SP"
22+
And I select "Reuse-IdP" on the WAYF
23+
And I pass through EngineBlock
24+
And I pass through the IdP
25+
Then I should see "Error - Access denied"
26+
27+
Scenario: A policy enforcement deny on Target-SP is not bypassed by reusing the AuthnRequest ID
28+
Given SP "Target-SP" requires a policy enforcement decision
29+
And pdp gives a deny response
30+
And SP "Easy-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
31+
And SP "Target-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
32+
When I log in at "Easy-SP"
33+
And I pass through EngineBlock
34+
And I pass through the IdP
35+
Then the response should contain "Easy-SP will receive"
36+
When I log in at "Target-SP"
37+
Then I should see "Error - An error occurred"
38+
When I post consent for request ID "_authnrequestidreuse00000000000000000001"
39+
Then the response should not contain "/functional-testing/Target-SP/acs"
40+
And the response should contain "/functional-testing/Easy-SP/acs"
41+
42+
Scenario: Control - an IdP that is not connected to Target-SP is not offered
43+
Given SP "Target-SP" is not connected to IdP "Reuse-IdP"
44+
And SP "Target-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
45+
When I log in at "Target-SP"
46+
Then the response should contain "/functional-testing/Other-IdP/sso"
47+
And the response should not contain "/functional-testing/Reuse-IdP/sso"
48+
49+
Scenario: An IdP that is not connected to Target-SP cannot be used by reusing the AuthnRequest ID
50+
Given SP "Target-SP" is not connected to IdP "Reuse-IdP"
51+
And SP "Easy-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
52+
And SP "Target-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
53+
When I log in at "Easy-SP"
54+
And I pass through EngineBlock
55+
And I pass through the IdP
56+
Then the response should contain "Easy-SP will receive"
57+
When I log in at "Target-SP"
58+
Then I should see "Error - An error occurred"
59+
When I post consent for request ID "_authnrequestidreuse00000000000000000001"
60+
Then the response should not contain "/functional-testing/Target-SP/acs"
61+
And the response should contain "/functional-testing/Easy-SP/acs"
62+
63+
Scenario: Control - a Stepup LoA required by Target-SP sends the user to Stepup
64+
Given the SP "Target-SP" requires Stepup LoA "http://dev.openconext.local/assurance/loa3"
65+
And SP "Target-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
66+
When I log in at "Target-SP"
67+
And I select "Reuse-IdP" on the WAYF
68+
And I pass through EngineBlock
69+
And I pass through the IdP
70+
Then the response should contain "/authentication/stepup/consume-assertion"
71+
72+
Scenario: A Stepup LoA required by Target-SP is not bypassed by reusing the AuthnRequest ID
73+
Given the SP "Target-SP" requires Stepup LoA "http://dev.openconext.local/assurance/loa3"
74+
And SP "Easy-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
75+
And SP "Target-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
76+
When I log in at "Easy-SP"
77+
And I pass through EngineBlock
78+
And I pass through the IdP
79+
Then the response should contain "Easy-SP will receive"
80+
When I log in at "Target-SP"
81+
Then I should see "Error - An error occurred"
82+
When I post consent for request ID "_authnrequestidreuse00000000000000000001"
83+
Then the response should not contain "/functional-testing/Target-SP/acs"
84+
And the response should contain "/functional-testing/Easy-SP/acs"
85+
86+
Scenario: Reusing the ID of a signed AuthnRequest of Target-SP is rejected as well
87+
Given SP "Target-SP" requires a policy enforcement decision
88+
And pdp gives a deny response
89+
And SP "Target-SP" signs its requests
90+
And SP "Easy-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
91+
And SP "Target-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
92+
When I log in at "Easy-SP"
93+
And I pass through EngineBlock
94+
And I pass through the IdP
95+
Then the response should contain "Easy-SP will receive"
96+
When I log in at "Target-SP"
97+
Then I should see "Error - An error occurred"
98+
When I post consent for request ID "_authnrequestidreuse00000000000000000001"
99+
Then the response should not contain "/functional-testing/Target-SP/acs"
100+
And the response should contain "/functional-testing/Easy-SP/acs"
101+
102+
Scenario: The same SP can resubmit an AuthnRequest with the same ID
103+
Given SP "Easy-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
104+
When I log in at "Easy-SP"
105+
And I log in at "Easy-SP"
106+
And I pass through EngineBlock
107+
And I pass through the IdP
108+
And I give my consent
109+
And I pass through EngineBlock
110+
Then the url should match "/functional-testing/Easy-SP/acs"
111+
112+
Scenario: Control - an SP behind a trusted proxy that requires Stepup LoA3 sends the user to Stepup for LoA3
113+
Given SP "Proxy-SP" is a trusted proxy
114+
And SP "Proxy-SP" signs its requests
115+
And SP "Proxy-SP" does not require consent
116+
And SP "Target-SP" does not require consent
117+
And the SP "Target-SP" requires Stepup LoA "http://dev.openconext.local/assurance/loa3"
118+
And SP "Proxy-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
119+
And SP "Proxy-SP" is authenticating for SP "Target-SP"
120+
When I log in at "Proxy-SP"
121+
And I select "Reuse-IdP" on the WAYF
122+
And I pass through EngineBlock
123+
And I pass through the IdP
124+
Then the received AuthnRequest should match xpath '//saml:AuthnContextClassRef[text()="http://dev.openconext.local/assurance/loa3"]'
125+
126+
Scenario: A Stepup LoA required by an SP behind a trusted proxy is not bypassed by reusing the AuthnRequest ID for it
127+
Given SP "Proxy-SP" is a trusted proxy
128+
And SP "Proxy-SP" signs its requests
129+
And SP "Proxy-SP" does not require consent
130+
And SP "Easy-SP" does not require consent
131+
And SP "Target-SP" does not require consent
132+
And the SP "Easy-SP" requires Stepup LoA "http://dev.openconext.local/assurance/loa2"
133+
And the SP "Target-SP" requires Stepup LoA "http://dev.openconext.local/assurance/loa3"
134+
And SP "Easy-SP" has the following Attribute Manipulation:
135+
"""
136+
$attributes['nl:surf:test:easy-sp'] = array("easy");
137+
"""
138+
And SP "Target-SP" has the following Attribute Manipulation:
139+
"""
140+
$attributes['nl:surf:test:target-sp'] = array("target");
141+
"""
142+
And SP "Proxy-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
143+
And SP "Proxy-SP" is authenticating for SP "Easy-SP"
144+
When I log in at "Proxy-SP"
145+
And I pass through EngineBlock
146+
And I pass through the IdP
147+
And I keep the Stepup "success" response for later
148+
And SP "Proxy-SP" is authenticating for SP "Target-SP" resetting the RequesterID chain
149+
And I log in at "Proxy-SP"
150+
Then I should see "Error - An error occurred"
151+
When I submit the kept Stepup response
152+
And I pass through EngineBlock
153+
Then the url should match "/functional-testing/Proxy-SP/acs"
154+
And the response should contain "nl:surf:test:easy-sp"
155+
And the response should not contain "nl:surf:test:target-sp"
156+
157+
Scenario: The same SP behind a trusted proxy can resubmit an AuthnRequest with the same ID
158+
Given SP "Proxy-SP" is a trusted proxy
159+
And SP "Proxy-SP" signs its requests
160+
And SP "Proxy-SP" does not require consent
161+
And SP "Easy-SP" does not require consent
162+
And SP "Proxy-SP" uses AuthnRequest ID "_authnrequestidreuse00000000000000000001"
163+
And SP "Proxy-SP" is authenticating for SP "Easy-SP"
164+
When I log in at "Proxy-SP"
165+
And I log in at "Proxy-SP"
166+
And I pass through EngineBlock
167+
And I pass through the IdP
168+
And I pass through EngineBlock
169+
Then the url should match "/functional-testing/Proxy-SP/acs"

‎src/OpenConext/EngineBlockFunctionalTestingBundle/Features/Context/EngineBlockContext.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,17 @@ public function iPostDataToEngineBlockUrl($data, $path)
878878
$this->getMinkContext()->getSession()->getDriver()->getClient()->request('POST', $url, $postdata);
879879
}
880880

881+
/**
882+
* @When /^I post consent for request ID "([^"]*)"$/
883+
*/
884+
public function iPostConsentForRequestId(string $requestId): void
885+
{
886+
$this->iPostDataToEngineBlockUrl(
887+
json_encode(['ID' => $requestId, 'consent' => 'yes']),
888+
'/authentication/idp/process-consent'
889+
);
890+
}
891+
881892
/**
882893
* @Given /^the attribute aggregator returns no attributes$/
883894
*/

‎src/OpenConext/EngineBlockFunctionalTestingBundle/Features/Context/MockSpContext.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,17 @@ public function spIsConfiguredToGenerateAPassiveAuthnRequest($spName)
618618
$this->mockSpRegistry->save();
619619
}
620620

621+
/**
622+
* @Given /^SP "([^"]*)" uses AuthnRequest ID "([^"]*)"$/
623+
*/
624+
public function spUsesAuthnRequestId(string $spName, string $requestId): void
625+
{
626+
$sp = $this->mockSpRegistry->get($spName);
627+
$sp->setAuthnRequestId($requestId);
628+
629+
$this->mockSpRegistry->save();
630+
}
631+
621632
/**
622633
* @Given /^SP "([^"]*)" requires a policy enforcement decision$/
623634
* @param string $spName

0 commit comments

Comments
 (0)