diff options
| author | Laurent Stukkens (LTU) <ltu@odoo.com> | 2020-09-11 08:07:20 +0000 |
|---|---|---|
| committer | Jeremy Kersten <jke@odoo.com> | 2020-09-18 14:45:01 +0000 |
| commit | 58e1c143faa8c84116166561196a02b5e2a32f6c (patch) | |
| tree | 1dfb6b82376bfc5faa02af4d9fd0525202610711 /addons/website_form | |
| parent | 493d76d8335269e8e0f27ec1780511cfbb6cb4c8 (diff) | |
[FIX] website_form: allow to submit form without csrf if not logged
Chrome recently changed their SameSite policy default value from None to Lax,
the session is no more shared between the webpage and the iframe.
As a result, the csrf check systematically fails.
After this commit, the csrf_token check is only made when you have a session.
In case you are using your form in an iframe on another site, with the new
cookies policy, your cookies with the session_id (linked to the csrf token)
is not sent to the server and the check csrf always fails.
Since the purpose of the csrf is to prevent another website to submit a form
with your 'authenticated account', we can consider that if you are not logged
and so have no session_id, it is no critical and we can ignore the csrf check.
opw-2330286
closes odoo/odoo#58046
X-original-commit: 9a0c9f3192bc7043add89446cbe6c2650499a654
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Diffstat (limited to 'addons/website_form')
| -rw-r--r-- | addons/website_form/controllers/main.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/addons/website_form/controllers/main.py b/addons/website_form/controllers/main.py index 3a07fee8c57..bd7a68c3c22 100644 --- a/addons/website_form/controllers/main.py +++ b/addons/website_form/controllers/main.py @@ -7,6 +7,7 @@ import pytz from datetime import datetime from psycopg2 import IntegrityError +from werkzeug.exceptions import BadRequest from odoo import http, SUPERUSER_ID, _ from odoo.http import request @@ -19,8 +20,16 @@ from odoo.addons.base.models.ir_qweb_fields import nl2br class WebsiteForm(http.Controller): # Check and insert values from the form on the model <model> - @http.route('/website_form/<string:model_name>', type='http', auth="public", methods=['POST'], website=True) + @http.route('/website_form/<string:model_name>', type='http', auth="public", methods=['POST'], website=True, csrf=False) def website_form(self, model_name, **kwargs): + # Partial CSRF check, only performed when session is authenticated, as there + # is no real risk for unauthenticated sessions here. It's a common case for + # embedded forms now: SameSite policy rejects the cookies, so the session + # is lost, and the CSRF check fails, breaking the post for no good reason. + csrf_token = request.params.pop('csrf_token', None) + if request.session.uid and not request.validate_csrf(csrf_token): + raise BadRequest('Session expired (invalid CSRF token)') + try: if request.env['ir.http']._verify_request_recaptcha_token('website_form'): return self._handle_website_form(model_name, **kwargs) |
