Problem/Motivation
The /api/ai-content-chat/ask POST endpoint currently has no CSRF token validation. This means any external website could craft a form or JavaScript request that sends chat requests on behalf of an authenticated user (Cross-Site Request Forgery).
While the endpoint only returns AI-generated text (no data modification), it still poses a risk:
External sites could consume AI API credits by triggering requests through a user's session
It could be used to probe indexed content from another domain
Proposed resolution
Add Drupal's built-in CSRF token validation to the API endpoint:
- Add X-Drupal-Ajax-Token header validation in the controller, or use the _csrf_token route requirement
- Update the JavaScript to include the CSRF token in API requests via drupalSettings
Issue fork 3569915-3573405
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
solimanharkas commented