Skip to content

Commit 866a23f

Browse files
author
Phil Sturgeon
committed
Merge pull request bcit-ci#24 from joelcox/issue-165c
CSRF field for internal POST only. Issue bcit-ci#165
2 parents 8a02247 + 3177533 commit 866a23f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

system/helpers/form_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ function form_open($action = '', $attributes = '', $hidden = array())
6464

6565
$form .= '>';
6666

67-
// CSRF
68-
if ($CI->config->item('csrf_protection') === TRUE)
67+
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
68+
if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->site_url()) === FALSE OR strpos($form, 'method="get"')))
6969
{
7070
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
7171
}

user_guide/changelog.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ <h2>Version 2.0.3</h2>
8080
<li>Helpers
8181
<ul>
8282
<li>Added an optional third parameter to <samp>heading()</samp> which allows adding html attributes to the rendered heading tag.</li>
83+
<li class="reactor"><kbd>form_open()</kbd> now only adds a hidden (Cross-site Reference Forgery) protection field when the form's action is internal and is set to the post method. (Reactor #165)</li>
8384
</ul>
8485
</li>
8586
<li>Libraries

0 commit comments

Comments
 (0)