Skip to content

Preserve X-Xsrf-Token header from .htaccess #6520

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

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

thecodeholic
Copy link
Contributor

In .htaccess file right now we have rewrite rule to preserve Authorization header. That commit exists in .htaccess file since 2016, which was later updated.

Laravel uses X-XSRF-TOKEN for session based authentication in API and just like Authorization header is sometimes removed by some of the server configurations (Typically on shared hosting) X-XSRF-TOKEN is also removed and to properly implement session based authentication with Laravel API, the header needs to be preserved.

I came to this change when I tried to deploy my Laravel API into shared hosting and authorization did not work because X-XSRF-TOKEN was removed by server configuration and on shared hosting typically we do not have control on the server configuration.

I think this change will not affect anything else, other than it makes sure that X-XSRF-TOKEN header is always preserved and passed to Laravel.

I would be happy to write any tests to support the PR, but I think this particular change is the type of change for which you can not write any tests.

thecodeholic and others added 3 commits January 10, 2025 17:12
Preserve X-Xsrf-Token header for session based authentication when building API in Laravel
@taylorotwell taylorotwell merged commit f15301d into laravel:11.x Jan 14, 2025
4 checks passed
Comment on lines +13 to +14
RewriteCond %{HTTP:x-xsrf-token} .
RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

Choose a reason for hiding this comment

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

I know the mod_rewrite rule conditions are case-insensitive. But isn't it a Good practice to use same consistency between lines within the same file?

    RewriteCond %{HTTP:HTTP:X-XSRF-Token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

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