Skip to content

fix: Update Redirect URI checks for different runtimes#23

Open
LeoAdamek wants to merge 1 commit into
logto-io:masterfrom
LeoAdamek:patch-1
Open

fix: Update Redirect URI checks for different runtimes#23
LeoAdamek wants to merge 1 commit into
logto-io:masterfrom
LeoAdamek:patch-1

Conversation

@LeoAdamek

Copy link
Copy Markdown

Fixes #22

Fixes issues on runtimes which don't set `SERVER_NAME`, relies now only on `REQUEST_URI`
Comment thread src/LogtoClient.php
// Some loose checks: ensure the host and path of the current request URL matches what was set when initiating the sign-in.
if (
parse_url($signInSession->redirectUri, PHP_URL_HOST) !== ($_SERVER['SERVER_NAME'] ?? null) ||
parse_url($signInSession->redirectUri, PHP_URL_HOST) !== parse_url($_SERVER['REQUEST_URI'], PHP_URL_HOST) ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_url($_SERVER['REQUEST_URI'], PHP_URL_HOST) looks problematic here. In a typical PHP request, $_SERVER['REQUEST_URI'] only contains the path and query string, such as /callback?code=..., so PHP_URL_HOST usually resolves to null. That means this change can turn a valid callback into a host mismatch and make handleSignInCallback() throw unexpectedly.

So while this PR is trying to address the RoadRunner case where $_SERVER['SERVER_NAME'] may be missing, the current fix risks breaking the common PHP/FPM flow. In other words, it may solve the original issue in one runtime by introducing a regression in more standard environments.

I think a safer approach would be to fall back to HTTP_HOST / SERVER_NAME, or skip the host check when the runtime does not expose host information, while still keeping the path validation.

Also, could you add tests for this? At minimum, it would be good to cover:

  • the original scenario this PR is trying to fix: SERVER_NAME missing but callback still succeeds when the request matches
  • the normal callback case in a typical PHP environment, to make sure this change does not introduce a regression

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll give this a look. 👍🏽

@LeoAdamek LeoAdamek changed the title fix: Update redirect URI checks to use REQUEST_URI only fix: Update Redirect URI checks for different runtimes May 5, 2026
@LeoAdamek

Copy link
Copy Markdown
Author

I've updated the change so that it tries to get the server host in the following order:

  • HTTP Host header ($_SERVER['HTTP_HOST'])
  • Server Name ($_SERVER['SERVER_NAME'])
  • Request URI

I've added a test that mimicks the roadrunner runtime's behaviour, so this should cover both scenarios.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

bug: handleSignInCallback fails on RoadRunner (SERVER_NAME not set)

2 participants