Hi Frappe Community,
I’m facing an issue related to CSRF tokens in my Frappe-based application, specifically with my custom CRM frontend/CRM Override.
- After logging out and logging in, everything works fine when directly accessing
site.local/crm. - However, when switching to
site.local/appor any other URL and then navigating back to/crm, I encounter CSRF token errors for the custom API calls I’ve added or modified. - The default Frappe API calls work fine, but the CSRF issue arises for custom front-end pages or actions where I’ve made modifications.
- Steps to reproduce:
- Log in to the site.
- Visit
/crm– everything works. - Visit
/appor any other page, and then navigate back to/crm. - CSRF token error occurs when attempting to call my custom API.
- Only logging out and logging back in directly to
/crmsolves the issue temporarily.
This happens both in development and in Frappe Cloud, and I’m unable to pinpoint the cause.
I’ve already tried:
- Using
ignore_csrf: 1(but this is not secure for production). - Ensuring the token is set with
frappe.csrf_token– but it still doesn’t get sent for custom pages. - Attempting to use a fresh login flow, but the issue persists when switching between URLs.
What I need help with:
- Understanding why CSRF tokens aren’t being sent for custom frontend pages.
- Ensuring proper CSRF protection for these custom pages while maintaining session integrity when switching between app pages.
- Any suggestions on workarounds or best practices for dealing with CSRF token issues in custom-built pages or apps.