![]() |
crsf and ion_auth reset password - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: crsf and ion_auth reset password (/showthread.php?tid=70001) |
crsf and ion_auth reset password - dwlamb - 02-07-2018 I am having a challenge with the csrf token for resetting a password in ion_auth. I have read other posts here and on other sites about ion_auth & csrf. In a nutshell, it seems the csrf data stored in flashdata under $_SESSION does not survive from the form created and when the form is submitted. PHP Code: public function reset_password($code = NULL) Code: $this->data['csrf'] = $this->_get_csrf_nonce(); The steps involved to check the csrf token occur after "// do we have a valid request?". The function "_valid_csrf_nonce()" returns FALSE for the 'csrfkey' and 'csrfvalue' are no longer present. I have tried setting cookies by a file or sessions managed by a database, as recommended on Ben Edmunds' github page. Has anyone else encountered such a problem and can recommend a solution? Thanks for taking the time to read this. RE: crsf and ion_auth reset password - ChicagoPhil - 02-07-2018 Are you using the forms that came in ion auth? I'm still thinking of what is going wrong here but are you sure the problem stems from the controller? RE: crsf and ion_auth reset password - dwlamb - 02-07-2018 (02-07-2018, 02:02 PM)ChicagoPhil Wrote: Are you using the forms that came in ion auth? I'm still thinking of what is going wrong here but are you sure the problem stems from the controller? I did not foresee it as an issue but it turns out using forms improved from those provided with the ion_auth package are somehow responsible for the flashdata being deleted from the $_SESSION. So the question becomes what do I do to make the flashdata persist or what to look for in my forms that is causing the session to regenerate? I can't identify something in the form to cause the session to regenerate. All I changed was some of the semantic mark up of html, head and body tags so css or javascript can be incorporated. The forms in ion_auth are only the form. No other mark up. I did not change any of the semantics inside the form_open and form_close syntax. I tried the following syntax to make the session persist. It was inserted at the point form validation is FALSE and the form for submitting a new password is generated (second to last line): PHP Code: if ($this->form_validation->run() === FALSE) RE: crsf and ion_auth reset password - ChicagoPhil - 02-08-2018 This is copied from the user guide. Perhaps your form is missing this post data? Code: $csrf = array( RE: crsf and ion_auth reset password - dwlamb - 02-08-2018 (02-08-2018, 12:43 AM)ChicagoPhil Wrote: This is copied from the user guide. Perhaps your form is missing this post data? No, this is not the issue of missing data. The missing token name and token value are present in the DOM. It is the identical values in the $_SESSION that go *poof* somehow with rendering the view. RE: crsf and ion_auth reset password - dave friend - 02-08-2018 I suspect that session and or cookie configs are wrong. Care to share those config settings? RE: crsf and ion_auth reset password - dwlamb - 02-08-2018 (02-08-2018, 08:11 AM)dave friend Wrote: I suspect that session and or cookie configs are wrong. Care to share those config settings? Researching this further, there are some threads that mention the csrf programming in ion_auth can be dropped in favour of the csrf protection built-in to CI 3.x. If I enable csrf protection using settings below I get the following error when I submit a form: Code: An Error Was Encountered These are the config statements for csrf protection taken from application/config/config.php PHP Code: $config['csrf_protection'] = TRUE; These are the config statements for sessions taken from application/config/config.php PHP Code: $config['sess_driver'] = 'database'; These are the config statements for cookies taken from application/config/config.php PHP Code: $config['cookie_prefix'] = ''; RE: crsf and ion_auth reset password - dave friend - 02-08-2018 The error: "The action you have requested is not allowed." might be because you either 1) Did not use form_open() in your view or 2) Did not add a hidden field to the form with the CSRF token and hash. form_open() automatically adds the hidden field for you. Nothing jumps out at me as wrong in your config settings. I developed a simple controller and view to test if sessions are working. It's easy to install (and remove) from a project and should provide a definitive answer to the question, "Are sessions working?" The files are on github HERE Hope it is helpful. RE: crsf and ion_auth reset password - dwlamb - 02-12-2018 (02-08-2018, 11:02 AM)dave friend Wrote: The error: "The action you have requested is not allowed." might be because you either Thanks for the sessions testing package. I ran it and according to it, sessions are working. The csrf protection is not working despite using form_open. The hidden fields for csrf data are present in the form and the values present in $_POST at the time of form submission. I am shifting from trying to resolve csrf as implemented by ion_auth to using csrf as implemented by CI 3.x. I figure better to implement it site-wide and debug the challenges than getting it to work one way and then having to debug the ion_auth methods. With `$config['csrf_regenerate'] = TRUE;` and using html valid forms, csrf protection fails. Using the barebones forms supplied with ion_auth, csrf protection passes. Stepping through function csrf_verify() (line 206 of Security.php in CI ver. 3.1.6) there is a discrepancy between the crsf_hash in the cookie, $this->_csrf_hash and the hash within $_POST. It is as though somehow html valid forms are submitted twice, the second pass the new value of the csrf hash in $_POST is not updated to the cookie before the form is submitted. If this convoluted and confusing, I apologise. Trying to get a handle on this is proving a challenge. |