![]() |
CSRF token in post response - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: CSRF token in post response (/showthread.php?tid=61039) |
CSRF token in post response - El Forum - 09-03-2014 [eluser]Unknown[/eluser] I have a login form and I want to secure it against csrf attacks. Using the suggested pattern in the form helper page, I check the validity of the data (That the user/password combination is correct), then, if it is valid, I redirect the use to the real site. But if the data is not valid, I display a form with an error message. The problem I have is that, when I re-display the form, the csrf token does not appear. The form: Code: <form method="post" accept-charset="utf-8"> The controller authentication method: Code: $request_method = $this->input->server('REQUEST_METHOD'); When I return the form in the error case, the form appears, but the hidden field does not have the token. Is there a way to get the token in the post response? Thanks [EDIT]Nevermind, it does work, I just forgot a line in the controller[/EDIT] CSRF token in post response - El Forum - 09-09-2014 [eluser]LuckyFella73[/eluser] Nice you solved your problem - just a hint to make your code clearer: Userguide: Quote:If you use the form helper the form_open() function will automatically insert a hidden csrf field in your forms. Code: echo form_open('controller_name/method_name'); Then you don't need this one anymore: Code: <input type="hidden" name="<?=$this->security->get_csrf_token_name()?>" value="<?=$this->security->get_csrf_hash()?>" /> CSRF token in post response - El Forum - 09-09-2014 [eluser]Unknown[/eluser] Thanks, I overlook the form_open function when I was reading the Docs. |