Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session cookies http & secure flag - how do you set these?

Just received the results of a security audit - everything clear apart from two things

Session cookie without http flag.

Session cookie without secure flag set.

The application is coded in php and the suggestions to fix are:

  1. set session cookie with http only flag
  2. set session cookie with secure flag

I have looked at examples but don't fully understand how to implement on a Linux server. I don't have access to the .ini file . Is it possible to set these in the htaccess file?

Alternatively, how and where do I implement in the code?

like image 812
Jeff Avatar asked Mar 06 '14 10:03

Jeff


People also ask

What is HTTP session cookie?

An HTTP cookie (web cookie, browser cookie) is a small piece of data that a server sends to a user's web browser. The browser may store the cookie and send it back to the same server with later requests.

How are cookies sent in HTTP?

Cookies are transmitted using header fields in the HTTP protocol. Cookie lifecycle: The first time a browser connects with a particular server, there are no cookies. The server creates a unique identifier, and returns a Set-Cookie: header in the response that contains the identifier.

How do I make HTTP cookies?

There are two ways to create HTTP cookies. Whether through Google Chrome or Mozilla Firefox, you can type in Javascript code to set the cookie into the console with any browser you access. The other option involves the web server sending one or more set-cookie headers.


1 Answers

You can set them before you send the header. Just add these line below in you code.

<?php // **PREVENTING SESSION HIJACKING** // Prevents javascript XSS attacks aimed to steal the session ID ini_set('session.cookie_httponly', 1);  // **PREVENTING SESSION FIXATION** // Session ID cannot be passed through URLs ini_set('session.use_only_cookies', 1);  // Uses a secure connection (HTTPS) if possible ini_set('session.cookie_secure', 1); 
like image 163
Perry Avatar answered Sep 17 '22 09:09

Perry