Skip to content

Conversation

@eldair
Copy link
Contributor

@eldair eldair commented May 21, 2025

This code change solves Laravel\Passport\Guards\TokenGuard::getTokenFromRequest(): Return value must be of type string, null returned error which can happen when X-CSRF-TOKEN is missing from the request.

It also aligns getTokenFromRequest method with it's counterpart in VerifyCsrfToken class (which has no return value and handles null value in tokensMatch method)

@hafezdivandari
Copy link
Contributor

I think it is safer to just change the return type to ?string ?

@eldair
Copy link
Contributor Author

eldair commented May 21, 2025

@hafezdivandari hash_equals function which uses the return value of this method requires all arguments to be string

@hafezdivandari
Copy link
Contributor

@eldair yes, that's why we should change the validCsrf method instead, check if the token is not null there.

@eldair
Copy link
Contributor Author

eldair commented May 21, 2025

@hafezdivandari something like this? Partly copied from similar method (tokensMatch) in Illuminate\Foundation\Http\Middleware\VerifyCsrfToken

@hafezdivandari
Copy link
Contributor

Lgtm, thanks.

Co-authored-by: Hafez Divandari <[email protected]>
@taylorotwell taylorotwell marked this pull request as draft May 23, 2025 14:37
@taylorotwell
Copy link
Member

Tests fail.

@hafezdivandari
Copy link
Contributor

hafezdivandari commented May 23, 2025

@taylorotwell failed tests are unrelated to changes on this PR and already have been fixed via laravel/framework#55800 (not released yet).

@eldair you may mark this PR as ready again, thanks.

@eldair eldair marked this pull request as ready for review May 23, 2025 14:59
@taylorotwell taylorotwell merged commit a65bb03 into laravel:13.x May 26, 2025
4 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants