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

X-XSRF-TOKEN request header should be X-CSRF-TOKEN instead in the documentation #170

Open
youyoumu opened this issue Nov 30, 2024 · 4 comments

Comments

@youyoumu
Copy link

youyoumu commented Nov 30, 2024

docs: https://inertia-rails.dev/guide/csrf-protection
reference: https://guides.rubyonrails.org/security.html#csrf-countermeasures

here is the video showing X-XSRF-TOKEN doesn't work but X-CSRF-TOKEN does

Screencast.From.2024-11-30.17-43-11.mp4

note: this is my first issue on open source project, can i get assigned to this? 👀

@skryukov
Copy link
Contributor

skryukov commented Nov 30, 2024

Hey @youyoumu, thanks for the issue! I'm happy that inertia-rails became your first OSS repo to contribute an issue to! 😄

It's a bit tricky, but Inertia Rails supports X-XSRF-TOKEN for Inertia requests:

def copy_xsrf_to_csrf!
@env['HTTP_X_CSRF_TOKEN'] = @env['HTTP_X_XSRF_TOKEN'] if @env['HTTP_X_XSRF_TOKEN'] && inertia_request?
end

So the example from your reproduction will work once you add the X-Inertia header.

@youyoumu
Copy link
Author

i see. what if we add additional note?

Note

X-XSRF-TOKEN header only works for Inertia requests. If you want to send a normal request you can use X-CSRF-TOKEN instead


or it's not needed because people should use router.visit() instead 🤔
for context, i'm using wretch here

@skryukov
Copy link
Contributor

Yup, sounds great 🙏

@youyoumu
Copy link
Author

youyoumu commented Dec 2, 2024

ok. i just created the PR #171 😄

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

No branches or pull requests

2 participants