Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7602757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:29:36+00:00 2026-05-30T23:29:36+00:00

I am using Codeigniter and i enabled CSRF via its config.php file… $config[‘csrf_protection’] =

  • 0

I am using Codeigniter and i enabled CSRF via its config.php file…

$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_token_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';

then on my ajax requests i get the cookie name

var cct = $.cookie('csrf_cookie_name');

and on parameters:

csrf_token_name : cct

My question: Do i need to do anything else or that’s it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:29:37+00:00Added an answer on May 30, 2026 at 11:29 pm

    Okay, most common case (or easiest to implement) of CSRF is something like this:

    <img src="http://bank.example.com/withdraw?account=bob&amount=1000000&for=Fred" />
    

    So if you’re assuming that you’re logged into bank.example.com you’re cookies are “alive” and will be send with request, so request will do what attacker want it to, so:

    Cookies won’t protect you from CSRF

    What can you do:

    Send as many request via POST as you can (without bothering the user), especially edits, creations and deletion. It’s easier to hide security into input type='hidden' than into URL.

    Check referrer (yeah, this little thing prevents you from almost every CSRF attack from external sites):

    $url = parse_url( isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
    if( isset( $url['host']) && ($url['host'] == $_SERVER['SERVER_NAME'])){
       // Request have a go
    }
    

    Add temporary security tokens to URLs like this /article/delete/25/axdefm…

    If you’ve spent some time generating nice URLs you’ll be send because this will just screw them up and this brings on some problems such as:

    • multiple actions at the time
    • flood of request for new security token
    • how long to let the token live

    Solution

    You may create table for security tokens, such as this one:

    tokens (
      id INT,
      user_id INT,
      created DATETIME,
      expires DATETIME, -- One of those two should be enough
      value CHAR(30),
      PRIMARY (id),
      FOREIGN KEY (user_id) ...
    );
    

    And when some action requires authorization token you’ll load last one from DB or create new one, let’s say you will create new token only if all available tokes are older than 15 minutes:

    function getToken( $userId, $eventIdentificator){
        // Hope this is self explanatory :)
        $db->deleteExpiredTokens();
    
        // Try to load token newer than 15 minutes
        $row = $db->fetchRow( 'SELECT value FROM tokens WHERE created >= ADD_INTERVAL( NOW(), -15 MINUTES) AND user_id = ?', array( $userId));
    
        // createToken will return `value` directly
        if( !$row){
            $row = createNewToken( $userId);
        } else {
            $row = $row['value'];
        }
    
        // Real token will be created as sha1( 'abacd' . 'delete_article_8');
        return sha1( $row . $eventIdentificator);
    }
    
    echo 'url?token=' . getToken( $userId, 'delete_article_' . $article['id']);
    

    How will this act:

    • if you’ll request security token for the same action within 15 minutes you’ll get the same token
    • you’ll get unique token for each action
    • if you’ll set token expiration for 4 hours, token will be active from 3:45 to 4:00
    • if attacker try to send you 200000 token requests in one minute you’ll still have just one row in database
    • each user will have maximally 16 records in the table at once

    How to check token?

    function checkToken( $userId, $eventIdentificator, $token){
        $db->deleteExpiredTokens();
    
        // Just find matching token with brute force
        $rs = $db->fetch_rowset( 'SELECT value FROM tokens WHERE created >= ADD_INTERVAL( NOW(), -15 MINUTES) AND user_id = ?', array( $userId));
        while( $row = $rs->fetch_row){
           if( $token == sha1( $row['value'] . $eventIdentificator)){
               return true;
           }
        }
        return false;
    }
    

    If you wan’t to make sure that action won’t happen twice (such as edit article, this works fine for deletion) just add revision_number or something similar to your $eventIdentificator).

    Try to think what will happen if:

    • attacker requests MANY tokens
    • user will write article for several hours
    • if you have a table with delete buttons for hundreds of articles

    I’d go with mentioned token system, it feels like a balanced solution between user comfort/implementation complexity and security, comments with ideas and notes are expected 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using CodeIgniter normally one has to specify the controllers in the config/routes.php file. This
I'm using Codeigniter a PHP framework and apache2. I have enabled Gzip and deflate
I have enabled csrf protection in Codeigniter. Using form_open() I'm able to produce a
I am using CodeIgniter to pass some parameters to my PHP page through $_POST
I'm using CodeIgniter (a PHP framework) to build an app, and I have an
I am using codeigniter and its pagination class. It works perfectly and it looks
I'm using CodeIgniter (because it's awesome) and I have something like: <?php echo anchor(/,
Just started using CodeIgniter, loving it. Having enabled the database to be one of
I'm using CodeIgniter for my php framework and TankAuth for my authorization/registration. By default,
I am using codeigniter's session class to handle my PHP sessions. One of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.