Skip to content

Commit bfbfe74

Browse files
mikedammgao-sun
andauthored
fix: use correct logic for URI check (#8)
* Fix logic for URI check PATH_INFO is specific to Apache, so this code fails if you use any other webserver https://httpd.apache.org/docs/2.4/mod/core.html#acceptpathinfo * refactor: fix tests --------- Co-authored-by: Gao Sun <gao@silverhand.io>
1 parent d5a6fe6 commit bfbfe74

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/LogtoClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function handleSignInCallback(): void
248248
// Some loose checks
249249
if (
250250
parse_url($signInSession->redirectUri, PHP_URL_HOST) !== ($_SERVER['SERVER_NAME'] ?? null) ||
251-
parse_url($signInSession->redirectUri, PHP_URL_PATH) !== ($_SERVER['PATH_INFO'] ?? null)
251+
parse_url($signInSession->redirectUri, PHP_URL_PATH) !== parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
252252
) {
253253
throw new LogtoException('The redirect URI in the sign-in session does not match the current request.');
254254
}

tests/LogtoClientTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function test_handleSignInCallback_sessionNotFound()
152152
function test_handleSignInCallback_pathDoesNotMatch()
153153
{
154154
$_SERVER['SERVER_NAME'] = 'localhost';
155-
$_SERVER['PATH_INFO'] = '/foo';
155+
$_SERVER['REQUEST_URI'] = '/foo';
156156
$client = $this->getInstance();
157157
$client->storage->set(
158158
StorageKey::signInSession,
@@ -166,7 +166,7 @@ function test_handleSignInCallback_pathDoesNotMatch()
166166
function test_handleSignInCallback_stateDoesNotMatch()
167167
{
168168
$_SERVER['SERVER_NAME'] = 'redirect_uri';
169-
$_SERVER['PATH_INFO'] = '/some_path';
169+
$_SERVER['REQUEST_URI'] = '/some_path';
170170
$_SERVER['QUERY_STRING'] = null;
171171
$client = $this->getInstance();
172172
$client->storage->set(
@@ -181,7 +181,7 @@ function test_handleSignInCallback_stateDoesNotMatch()
181181
function test_handleSignInCallback_codeNotFound()
182182
{
183183
$_SERVER['SERVER_NAME'] = 'redirect_uri';
184-
$_SERVER['PATH_INFO'] = '/some_path';
184+
$_SERVER['REQUEST_URI'] = '/some_path';
185185
$_SERVER['QUERY_STRING'] = 'state=state';
186186
$client = $this->getInstance();
187187
$client->storage->set(
@@ -196,7 +196,7 @@ function test_handleSignInCallback_codeNotFound()
196196
function test_handleSignInCallback()
197197
{
198198
$_SERVER['SERVER_NAME'] = 'redirect_uri';
199-
$_SERVER['PATH_INFO'] = '/some_path';
199+
$_SERVER['REQUEST_URI'] = '/some_path';
200200
$_SERVER['QUERY_STRING'] = 'state=state&code=code';
201201
$tokenResponse = new TokenResponse(
202202
access_token: 'access_token',

0 commit comments

Comments
 (0)