Secure Cookie Attributes Apache

Setting Secure Cookie Attributes in Apache

Securing your cookies is essential for protecting user data and preventing security vulnerabilities. Follow these steps to set secure cookie attributes in your Apache web server.

Step 1: Edit Apache Configuration

Edit your Apache configuration file, which is typically located at /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf.

sudo nano /etc/apache2/apache2.conf

Step 1: Add Cookie Attributes

Insert the following lines at the appropriate location in your Apache configuration file to set secure cookie attributes:

Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure

This configuration adds the 'HttpOnly' attribute, preventing JavaScript access to the cookie, and the 'Secure' attribute, ensuring the cookie is only sent over HTTPS connections.

Step 4: Save and Restart Apache

Save your changes and restart Apache to apply the new configuration:

sudo systemctl restart apache2