Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to verify your data submission since updated to 2.0.14 #15783

Closed
cluwong opened this issue Feb 27, 2018 · 31 comments
Closed

Unable to verify your data submission since updated to 2.0.14 #15783

cluwong opened this issue Feb 27, 2018 · 31 comments
Assignees
Milestone

Comments

@cluwong
Copy link

cluwong commented Feb 27, 2018

What steps will reproduce the problem?

Submit a form.

What is the expected result?

Form is submitted - data is saved or whatever the the form is supposed to do.

What do you get instead?

yii\web\BadRequestHttpException: Unable to verify your data submission. in /var/www/my.uhub.biz/vendor/yiisoft/yii2/web/Controller.php:166

Additional info

I haven't been able to submit any forms since updated to 2.0.14. Have updated to 2.0.14.1 and still same error. Have tried to clear all browser cookies, restart services and server, but still cannot submit forms. Form can be submitted if csrf is disabled but this is not an option.
Fall back to V2.0.13.1 and it works as intended.

Q A
Yii version 2.0.14 and 2.0.14.1
PHP version 7.0.22
Operating system Ubuntu 16.04
@frontbear
Copy link
Contributor

@cluwong
Copy link
Author

cluwong commented Feb 27, 2018

@frontbear the link is about disabling csrf, which I followed to disable csrf and am able to submit the form. However I don't want to do that for security reason.

If downgrade back to 2.0.13 forms can be submitted. It's when updated to 2.0.14+ it forms can't be submitted and gets 'Unable to verify your data submission' error.

@rosancoderian
Copy link

its similiar to bug that i encounter, maybe related?

@cluwong
Copy link
Author

cluwong commented Feb 27, 2018

@rosancoderian I had a look at your issue and it seems to related to performance. I've been upgrading Yii fairly regularly and haven't noticed any performance issues. My only issue with the latest release is unable to submit forms.

@SilverFire
Copy link
Member

SilverFire commented Feb 27, 2018

Failed to reproduce. Please, supply more info, including request component config and action source code

@yii-bot
Copy link

yii-bot commented Feb 27, 2018

Thanks for posting in our issue tracker.
In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

@SilverFire SilverFire added this to the 2.0.15 milestone Feb 27, 2018
@cluwong
Copy link
Author

cluwong commented Feb 27, 2018

@SilverFire, thanks for looking into this. I'd say this is not easily reproduced as it works in 2.0.13 but not 2.0.14+. Here are info as per request. Please let me know if you need any more info.

In frontend/config/main.php:

'components' => [
        'request' => [
            'csrfParam' => 'csrf-frontend',
        ],
        'session' => [
            'name' => 'xxx-frontend',
        ],
],

As mentioned in original ticket it happens to all actions handling post data. Here's one that saves a record:

public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post())) {

            if ($model->save()) {
                return $this->redirect(['index']);
            }
        }
        return $this->render('update', ['model' => $model]);
    }

@SilverFire
Copy link
Member

Could you try to reproduce it on basic app template?

@sartor
Copy link
Contributor

sartor commented Feb 27, 2018

I have the same issue since I have upgraded to 2.0.14.1 from 2.0.13. It happens rarely but for loaded project it is significant amount of bad requests apeared

@schmunk42
Copy link
Contributor

Could you check if this is related to output created by echos instead of returning the content/data of the controller? Ie. during AJAX validation.

Possibly related: #15782

@sartor
Copy link
Contributor

sartor commented Feb 27, 2018

I can't reproduce it on my local developer machine. It is happened rarely on production. I'll keep trying to find

@sartor
Copy link
Contributor

sartor commented Feb 27, 2018

The problem with "remember me". Commit with breaking changes is 6c0540a

Steps to reproduce:

  1. Login with default yii2 auth functionality
  2. Load a page with any AJAX post request
  3. Remove cookie PHPSESSID
  4. Submit post request

Problem because of regenerating csrf token while restoring session from "remember me" token.

@samdark
Copy link
Member

samdark commented Feb 28, 2018

@sartor yes, that seems valid but I'm not sure how to solve that since not regenerating causes possible security issues.

@sartor
Copy link
Contributor

sartor commented Feb 28, 2018

May be it is possible to not regenerate session if it is recovered from "remember me" token? Is it a security breach?

@samdark
Copy link
Member

samdark commented Feb 28, 2018

Possibly not. Need to review it in detail.

@cluwong
Copy link
Author

cluwong commented Mar 1, 2018

My issue isn't related to just AJAX. It's any post - AJAX, form or even via links.

Thanks @sartor who mentioned 'remember me'. I stepped through my user model (which extends \yii\web\User). I resolved by extending login function:

public function login(yii\web\IdentityInterface$identity, $duration = 3600) {
        return parent::login($identity, $duration);
    }

Simply set $duration to any value > 0 and post now works.

This is probably not the correct solution but it resolves my issue.

@cleippi
Copy link

cleippi commented Mar 3, 2018

I'm also seeing a higher than normal amount of "yii\web\BadRequestHttpException: Unable to verify your data submission" errors today after upgrading to 2.0.14.1. Is there anything I can provide that might help you dig into this?

If it helps, I'm using the advanced template, each app with their own CSFR token.

'components' => [
        'request' => [
            'csrfParam' => '_publisher_csrf',
            'baseUrl' => '/publisher',
        ],

@twisted1919
Copy link

I subscribe to this, upgrading to latest version simply had me disable csrf token validation because of the high number of errors(Unable to verify your data submission) i get when submitting the forms.
There is def. something wrong.

@samdark
Copy link
Member

samdark commented Mar 3, 2018

The problem is well described in #15783 (comment)

@samdark samdark added type:bug Bug and removed status:to be verified Needs to be reproduced and validated. labels Mar 4, 2018
@samdark
Copy link
Member

samdark commented Mar 4, 2018

Verified that not regenerating token when prolonging via "remember me" cookie is OK security-wise.

@iurijacob
Copy link

I'm having this problem in a form which has a field decorated with a Select2 widget that performs an ajax to search and retrieve the select options through a webservice in the same app. It seems that the ajax response updates the CSRF cookie, but not the CSRF param of meta tag neither the CSRF hidden input. So that when I submit the form through a normal POST the CSRF validation fails because the CSRF state has changed since the page was rendered.

I tried to manually update the CSRF using Yii client API (yii.setCsrfToken()), but it didn't work.

Do you know any workaround to such case?

@xutl
Copy link
Contributor

xutl commented May 3, 2018

Take a look at this article https://segmentfault.com/q/1010000004450797

@samdark
Copy link
Member

samdark commented May 4, 2018

@xutl I can't reach it.

@feiyangzhang
Copy link

feiyangzhang commented Sep 7, 2018

\yii\web\User\login regenerateCsrfToken(). Since 2.0.14.2

@php-wizard
Copy link

@feiyangzhang I'm having this issue on 2.0.16.
So i better always call regenerateCsrfToken() just before showing the login forms ?

@joeyblack835
Copy link

@samdark Users are reporting about such case.

  1. Open login form (when logged out).
  2. Open login form in another tab (suppose they were doing something in different tabs and then appeared to be logged out in both tabs).
  3. Enter credentials in the first tab and submit the form -- logged in OK.
  4. Do the same in the second tab -- Unable to verify your data submission error. Suppose they expect to be logged in successfully.
    Is this an official security behavior of the framework? What is a better workaround? Something more informative? Of course, except showing a 403 forbidden page?

@samdark
Copy link
Member

samdark commented Jun 10, 2021

Yes. That's official security behavior. It is CSRF token validation.

@samdark
Copy link
Member

samdark commented Jun 10, 2021

The thing is that token is generated in the form then it's used in another tab but the form still contains old one.

@joeyblack835
Copy link

@samdark Thank you. Just trying to customize the error message (by something like "Something went wrong. Please try closing and re-opening your browser window", etc.), because "Unable to verify your data submission" doesn't make any sense for the user. The only way I found is relying on the text (of course, if no translations are used), because the framework doesn't provide any specific error code or other states for this case.

@samdark
Copy link
Member

samdark commented Jul 8, 2021

@joeyblack835 normally user won't ever receive this message.

@joeyblack835
Copy link

@samdark But this is what normal users are reporting and the client asked to make user friendly messages. 😊 Anyway, thank you for clarifying.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests