[3.x]: "Unable to verify your data submission" error when using CSRF token in an iframe #13440
Replies: 2 comments 2 replies
-
How exactly are you rendering the form? Is the iframe page being rendered by the same Craft CMS install? |
Beta Was this translation helpful? Give feedback.
-
The iframe is hosted on an external, non-Craft, website. It's loaded by JavaScript, something like this:
Within the iframe we have the Craft site. We're setting a
The form within the iframe is rendered like this:
The form submits to the same domain where it's hosted. It's submitted using the Fetch API, like this:
We're not currently caching the page, but I've tried including Formie's refresh-token code as well, in preparation for caching, and got the 400 error either way. Weirdly, there's no error when testing in Firefox. But we have seen it on multiple devices using Chrome, Safari and Edge. |
Beta Was this translation helpful? Give feedback.
-
What happened?
I need to embed a Craft form (using the Formie plugin) in an iframe on another website and, when I test it, the form submission hits a 400 error.
In the logs, it looks like this:
In Chrome dev tools, the Set-Cookie Response Headers for the iframe showed the warning:
So, I found I can avoid the error using either of the following General Config settings:
'sameSiteCookieValue' => 'None'
'enableCsrfProtection' => false
(it's also possible to disable CSRF tokens in Formie's Settings)But I'm wondering: which of these options is the least insecure? Or is there a better option?
This blog post says when you set SameSite=None, "cookies...do nothing to protect you from CSRF attacks", so it seems like there's no point in using the first option and I should just disable the CSRF token. But I'd prefer not to compromise the security if there's another way around it...?
Craft CMS version
Craft Pro 3.7.61
PHP version
8.0.28
Operating system and version
Linux 5.10.0-0.deb10.17-amd64
Database type and version
MySQL 10.11.2
Image driver and version
Imagick 3.7.0 (ImageMagick 7.1.0-50)
Installed plugins and versions
1.3.0
1.0.0
dev-craft-3-backport-v2
1.3.0
2.0.0
2.2.1
2.4.0
2.4.0
1.0.1
3.0.3
2.8.6.1
1.6.27
1.0.2
1.5.0
1.0.6
2.3.1
2.10.10
1.0.1
2.6.0
1.0.0
2.9.6
Beta Was this translation helpful? Give feedback.
All reactions