Skip to content

Commit

Permalink
Changed form_open() to compare $action against base_url()
Browse files Browse the repository at this point in the history
Checking for strpos($action, $CI->config->site_url()) === FALSE causes
CSRF token to not be added in form_open() output. When site_url()'s
first parameter ($uri) is empty, site_url's return value is the base
URL plus the $CI->config->item('index_page') value. form_open() and
CodeIgniter's URI routing do not require index.php to be in the URL, so
any call to form_open() in which the $action parameter does not have
index.php will always return false for the strpos() call.
  • Loading branch information
very-meanly committed Nov 24, 2011
1 parent b8188f6 commit 9a05d2b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/helpers/form_helper.php
Expand Up @@ -65,7 +65,7 @@ function form_open($action = '', $attributes = '', $hidden = array())
$form .= '>';

// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->site_url()) === FALSE OR strpos($form, 'method="get"')))
if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->base_url()) === FALSE OR strpos($form, 'method="get"')))
{
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
Expand Down
1 change: 1 addition & 0 deletions user_guide/changelog.html
Expand Up @@ -71,6 +71,7 @@ <h2>Version 2.1.1</h2>
<h3>Bug fixes for 2.1.1</h3>
<ul>
<li>Fixed a bug (#697) - A wrong array key was used in the Upload library to check for mime-types.</li>
<li>Fixed a bug - form_open() compared $action against site_url() instead of base_url()</li>
</ul>


Expand Down

0 comments on commit 9a05d2b

Please sign in to comment.