RiptideTempora

Session Security for the Lazy

Dec 31st, 2012
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?
  2. /* In a nutshell, this is a quick way to ensure your sessions are difficult to attack. There may be
  3.  * ways to improve this configuration but it's a good starting point, I feel.
  4.  *
  5.  * Code released in accordance with the ZAP > http://tlwsd.info/LICENSE.txt
  6.  *
  7.  * Requirements: HTTPS (get a free cert from StartSSL.com if you have no money :P)
  8.  * A well-configured webserver (see: Calomel.org)
  9.  * Access to server config is a bonus because you can just change php.ini and not have to make a bunch of runtime calls to ini_set() thus boosting performance
  10.  */
  11. ini_set('session.cookie_httponly', true);
  12.   # Above: Tells the user's browser to not expose session cookie contents to Javascript
  13. ini_set('session.cookie_secure', true);
  14.   # Above: Tells the user's browser to not expose session cookie contents to unencrypted HTTP
  15. ini_set('session.entropy_file', '/dev/urandom'); // On BSD systems, you may wish to use use /dev/arandom
  16. ini_set('session.entropy_length', '32');
  17. ini_set('session.hash_function', 'sha256');
  18. ini_set('session.hash_bits_per_character', '6');
  19.  # Above: Use strong pseudorandom data in the session IDs to prevent session fixation
  20. ini_set('session.use_trans_sid', false);
  21. session_start();
  22.   // All configuration must be set before session_start();
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment