Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct logic for URI check #8

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LogtoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function handleSignInCallback(): void
// Some loose checks
if (
parse_url($signInSession->redirectUri, PHP_URL_HOST) !== ($_SERVER['SERVER_NAME'] ?? null) ||
parse_url($signInSession->redirectUri, PHP_URL_PATH) !== ($_SERVER['PATH_INFO'] ?? null)
parse_url($signInSession->redirectUri, PHP_URL_PATH) !== parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
) {
throw new LogtoException('The redirect URI in the sign-in session does not match the current request.');
}
Expand Down
8 changes: 4 additions & 4 deletions tests/LogtoClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function test_handleSignInCallback_sessionNotFound()
function test_handleSignInCallback_pathDoesNotMatch()
{
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['PATH_INFO'] = '/foo';
$_SERVER['REQUEST_URI'] = '/foo';
$client = $this->getInstance();
$client->storage->set(
StorageKey::signInSession,
Expand All @@ -166,7 +166,7 @@ function test_handleSignInCallback_pathDoesNotMatch()
function test_handleSignInCallback_stateDoesNotMatch()
{
$_SERVER['SERVER_NAME'] = 'redirect_uri';
$_SERVER['PATH_INFO'] = '/some_path';
$_SERVER['REQUEST_URI'] = '/some_path';
$_SERVER['QUERY_STRING'] = null;
$client = $this->getInstance();
$client->storage->set(
Expand All @@ -181,7 +181,7 @@ function test_handleSignInCallback_stateDoesNotMatch()
function test_handleSignInCallback_codeNotFound()
{
$_SERVER['SERVER_NAME'] = 'redirect_uri';
$_SERVER['PATH_INFO'] = '/some_path';
$_SERVER['REQUEST_URI'] = '/some_path';
$_SERVER['QUERY_STRING'] = 'state=state';
$client = $this->getInstance();
$client->storage->set(
Expand All @@ -196,7 +196,7 @@ function test_handleSignInCallback_codeNotFound()
function test_handleSignInCallback()
{
$_SERVER['SERVER_NAME'] = 'redirect_uri';
$_SERVER['PATH_INFO'] = '/some_path';
$_SERVER['REQUEST_URI'] = '/some_path';
$_SERVER['QUERY_STRING'] = 'state=state&code=code';
$tokenResponse = new TokenResponse(
access_token: 'access_token',
Expand Down
Loading