adrianmak Posted May 19, 2017 Share Posted May 19, 2017 I'm going to put CSRF form protection on a form. on what position on validating CSRF during form processing after submission ? Here are pesudo code if form submitted validating input fields if any one of fields is invlaid, stop processing and display field error if input fields passed validation validate CSRF if passed CSRF validation submit form data or save to database if not passed CSRF vlaidation generate form error anything wrong with this order ? Link to comment Share on other sites More sharing options...
rick Posted May 19, 2017 Share Posted May 19, 2017 I use this format: If form submitted { if CSRF is valid { // process form data } else { session redirect 401 } } // render form The reason I use this order is, First, I make sure the form was submitted. If it was not, then render the form. Second, I validate CSRF. If it passes, then process form data. // No sense processing form data if invalid. Lastly, if CSRF fails, I redirect to 401. 1 Link to comment Share on other sites More sharing options...
adrianmak Posted May 19, 2017 Author Share Posted May 19, 2017 29 minutes ago, rick said: I use this format: If form submitted { if CSRF is valid { // process form data } else { session redirect 401 } } // render form The reason I use this order is, First, I make sure the form was submitted. If it was not, then render the form. Second, I validate CSRF. If it passes, then process form data. // No sense processing form data if invalid. Lastly, if CSRF fails, I redirect to 401. How to generate a http 401 error to the client ? Link to comment Share on other sites More sharing options...
rick Posted May 19, 2017 Share Posted May 19, 2017 header("Status: 401", true, 401); 1 Link to comment Share on other sites More sharing options...
huseyin Posted June 10, 2020 Share Posted June 10, 2020 I wanted to test the CSRF Validation. Have PW 3.0.148 running on local XAMPP. Installed the LoginRegister Module. While Profile edit i changed the token and/or value of token on the form. After submit no error no exception. The edited value was accepted. On line 895 is coded : $session->CSRF->validate(); (Which should throw the exception, but did not) If change this line from "$session->CSRF->validate();" to "echo $session->CSRF->validate();" than i get the exception as admin errorpage (See attached) . Can someone test the same? Link to comment Share on other sites More sharing options...
huseyin Posted June 11, 2020 Share Posted June 11, 2020 Any comments about this CSRF problem. (see former message) Can anybody reproduce this? Link to comment Share on other sites More sharing options...
kongondo Posted June 11, 2020 Share Posted June 11, 2020 1 hour ago, huseyin said: Any comments about this CSRF problem. (see former message) Please start a new topic and show us some code ? Your question does not seem to be related to the current thread. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now