Skip to content

Conversation

@arpitjalan
Copy link
Member

class PageVisitsController < ::ApplicationController
requires_plugin PLUGIN_NAME

skip_before_action :verify_authenticity_token, only: [:create]

Choose a reason for hiding this comment

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

I think we still want this still. As far as I can tell it's possible to add the X-CSRF-Token header in sendBeacon.

Here is where Core injects the header
https://github.com/discourse/discourse/blob/9bb15488bdcf2c2a976249d23c5c809f3c52ba73/frontend/discourse/app/instance-initializers/csrf-token.js#L24

The Ajax library has an exported function for ensuring we have a valid token - https://github.com/discourse/discourse/blob/9bb15488bdcf2c2a976249d23c5c809f3c52ba73/frontend/discourse/app/lib/ajax.js#L49-L57

You can see how it's used in various places:
https://github.com/discourse/discourse/blob/9bb15488bdcf2c2a976249d23c5c809f3c52ba73/frontend/discourse/app/lib/uppy/uppy-upload.js#L497

Copy link
Member Author

Choose a reason for hiding this comment

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

Excellent feedback, thank you! I just pushed another commit to add CSRF token to verify authenticity.

@markvanlan markvanlan merged commit d712081 into main Nov 17, 2025
5 checks passed
@markvanlan markvanlan deleted the improve-tracking branch November 17, 2025 16:18
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.

3 participants