Lets just consider the trust that the server have with the user.
Session fixation: To avoid the fixation I use session_regenerate_id()
ONLY in authentication (login.php)
Session sidejacking: SSL encryption for the entire site.
Am I safe ?
Lets just consider the trust that the server have with the user.
Session fixation: To avoid the fixation I use session_regenerate_id()
ONLY in authentication (login.php)
Session sidejacking: SSL encryption for the entire site.
Am I safe ?
Read OWASP A3-Broken Authentication and Session Management. Also read about OWASP A5-CSRF, which is sometimes called "session riding".
You should use this code in a php header file:
ini_set('session.cookie_secure',1);
ini_set('session.cookie_httponly',1);
ini_set('session.use_only_cookies',1);
session_start();
This code prevents session fixation. It also helps protect against xss from access document.cookie
which is one way that Session Hijacking can occur. Enforcing HTTPS only cookies is a good way of addressing OWASP A9-Insufficient Transport Layer Protection. This way of using HTTPS is sometimes called "secure cookies", which is a terrible name for it. Also STS is a very cool security feature, but not all browsers support it (yet).
cookie_secure
would enforce me to work always on https when in session, wouldn't it?! 2) What does cookie_httponly
do? I read PHP explanation, but I don't get when it says that prevents JS form reading cookies, actually cookies should be read by JS in many circumstancies. Thanks, and FYI: since PHP 5.3.0 session.use_only_cookies
is 1 by default it.php.net/manual/en/… –
Sidelong I would also suggest storing the user agent and ip information in the session, and verifying it on each request. It's not bullet-proof, but it is a fairly significant increase in robustness. While UA forging is really easy, IP forging, while possible, is MUCH harder... But you may have issues with users who are behind a round-robin IP system such as AOL users...
the best practice i have ever found is save the session data to database or a text file. the database will have user agent, and IP record and check it every request for ensure that the session never been hijacked by other.
for example how session saved at database you can see the implementation at codeigntier session library. in my opinion this way fairly save to prevent someone to hijact session.
© 2022 - 2024 — McMap. All rights reserved.