Giter VIP home page Giter VIP logo

Comments (5)

ikkez avatar ikkez commented on August 29, 2024

The Session class is a Cache-Based Session handler, which requires to have an activated Cache instance.

$f3->set('CACHE', true);
$s = new Session();
echo $s->csrf(); // z3sysduecint.p63g18fr7nvp

Though the Session handlers have some build in protection already, they only help you for Session-Hijacking attacks. You are right, for better security, this token should be used in forms or URIs that we want to protect.

if ($f3->exists('SESSION.csrf',$csrf))
    var_dump($csrf); // old token from last request, to validate forms
$s = new Session();
$newToken = $s->csrf(); // token for current request, use this in hidden form fields
var_dump($newToken);
$f3->set('SESSION.csrf',$newToken);

I currently have no such check in fabulog, but will consider to add this as feature. thanks ;)

edit: I've added this to the docs. http://fatfreeframework.com/session#csrf

from fabulog.

xmory avatar xmory commented on August 29, 2024

Thanks for your reply.

I know where I got error.

if I test code like this:

$f3=require('lib/base.php');
$f3->set('CACHE',true);
if (true) {
     /*do_login*/
    $session = new Session();
    $f3->set('SESSION.user_id',3);  //
    $f3->set('SESSION.csrf',$session->csrf());
    var_dump($f3->get('SESSION'));
}

every thing is right.
But this gets the error:

$f3=require('lib/base.php');
$f3->set('CACHE',true);
if (true) {
    /*do_login*/
    $f3->clear('SESSION');   //this line added
    $session = new Session();
    $f3->set('SESSION.user_id',3);  
    $f3->set('SESSION.csrf',$session->csrf());
    var_dump($f3->get('SESSION'));
    //csrf token is false
}

from fabulog.

xmory avatar xmory commented on August 29, 2024

When a user login, should clear session first? Then can't get csrf token?

from fabulog.

xmory avatar xmory commented on August 29, 2024

It seems that the token is created when the session instance is create. The Session class check if other session data has exists, if not, the token won't be saved.
I add a method to the Session class to generate the token, and save it. Call the method when needed.

from fabulog.

SaphiLC avatar SaphiLC commented on August 29, 2024

i keep getting this error
"session_start(): Failed to read session data: user"
the csrf code gets generated but then the website won't work because that error 500, it's driving me crazy :S

from fabulog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.