0
votes

My site was working just fine, no issues, then all of a sudden I receive error "An Error Was Encountered - The action you have requested is not allowed" during every form submit.

I am using Codeigniter 3 with SSL and I have CSRF protection turned on. I did not change anything lately so I have no idea why my site stopped working. If I turn CSRF off, form submission works fine.

Settings

$config['base_url'] = 'https://www.mywebsite.com';
$config['index_page'] = '';

$config['cookie_prefix']    = '';
$config['cookie_domain']    = '.mywebsite.com';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;

$config['csrf_protection']   = TRUE;
$config['csrf_token_name']   = 'msmm_tn';
$config['csrf_cookie_name']  = 'msmm_cn';
$config['csrf_expire']       = 7200;
$config['csrf_regenerate']   = TRUE;
$config['csrf_exclude_uris'] = array();

Form

<form action="https://www.mywebsite.com/" class="navbar-form navbar-left" id="search" method="post" accept-charset="utf-8">
<input type="hidden" name="msmm_tn" value="caeea1bc65c09f29691a1a692e09a30a" style="display:none;" />
<input type="hidden" name="token" value="ada2832a" style="display:none;" />
<input type="hidden" name="date-search-form" id="date-search-form" value="X">
<div class="form-group">
<input type="date" class="form-control input-md" name="from_date" id="from_date" value="2017-08-15" />
</div>
<div class="form-group">
<input type="date" class="form-control input-md" name="to_date" id="to_date" value="2017-08-16" />
</div>
<div class="form-group">
<input type="search" class="form-control input-md" name="search_text" id="search_text" placeholder="Search" value="">
</div>
<div class="form-group">
<button type="submit" class="btn btn-default btn-sm" name="go" id="go"><i class="fa fa-search" aria-hidden="true"></i>
</button>
</div>
</form>
</div>

Server side form code:

<?php 
        $attributes = array('class' => 'form-horizontal', 'id' => 'signup');
        echo form_open('', $attributes);
    ?>
    <?php 
    if( isset( $login_error_mesg ) )
    {
        echo '<div class="alert alert-danger input_bump" role="alert">';
        echo 'Invalid Username, Email Address, or Password.<br>Username, email address and password are all case sensitive.';
        echo '</div>';
    }
    if( $this->input->get('logout') )
    {
        echo '<div class="alert alert-success input_bump text-center" role="alert"><p>You have successfully logged out.</p></div>';
    }
    ?>

      <div class="form-group form-padding">
        <label class="form-label" for="login_name">User Name or Email</label>
        <input type="text" class="form-control form-fixer input-md" name="login_string" id="login_string" value="<?php echo $this->input->post('login_string'); ?>">
      </div>
      <div class="form-group form-padding">
        <label class="form-label" for="pwd">Password</label>
        <input type="password" class="form-control input-md" id="login_pass" name="login_pass" maxlength="<?php echo config_item('max_chars_for_password'); ?>" autocomplete="off" />
      </div>
      <div class="input_bump">
      <?php
        $link_protocol = USE_SSL ? 'https' : NULL;
      ?>
        <p>
            <a href="<?php echo site_url('recover', $link_protocol); ?>">Can't access your account?</a>
        </p>
      </div>
      <div class="form-group form-padding">
      <button type="submit" class="btn btn-success btn-full">Sign In</button>
      </div>
    <?php echo form_close(); ?>
1
I am using form_open and the token is present on the form, no AJAX is being used in the form and CSRF is set to true. - ReeseB
It gets weirder, my search form works in all browsers on my second laptop and I can log into my site in IE and FF but not Chrome. On my main laptop, I cannot use any form w/o receiving the error. Now, I tried Chrome on my main laptop and I can search and log in just fine. So Firefox on my main laptop is not allowing my site to work correctly. I guess this issue is closed as it cannot be CSRF. - ReeseB
Still cannot figure out why this only occurs in Firefox on my Windows 8 laptop. - ReeseB
May be it will solve your problem Read: stackoverflow.com/questions/34508646/… - Pawan Thakur

1 Answers

0
votes

Just add the Controller uri in:

$config['csrf_exclude_uris'] = array();

//e.g. $config['csrf_exclude_uris'] = array('register/add_member');

Where register is your controller and add_member is the method.