Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
In Apache HTTP and Security Last updated: June 9, 2022
Share on:
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

Implement cookie HTTP header flag with HTTPOnly & Secure to protect a website from XSS attacks

Do you know you can mitigate most common XSS attacks using HttpOnly and Secure flag with your cookie?

XSS is dangerous. By looking at an increasing number of XSS attacks daily, you must consider securing your web applications.

Without having HttpOnly and Secure flag in the HTTP response header, it is possible to steal or manipulate web application sessions and cookies.

It’s better to manage this within the application code. However, due to developers’ unawareness, it comes to Web Server administrators.

I will not talk about how to set these at the code level. You can refer here.

Implementation Procedure in Apache

  • Ensure you have mod_headers.so enabled in Apache HTTP server
  • Add following entry in httpd.conf
Header always edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
  • Restart Apache HTTP server to test

Note: Header edit is not compatible with lower than Apache 2.2.4 version.

You can use the following to set the HttpOnly and Secure flag in lower than the 2.2.4 version. Thanks to Ytse for sharing this information.

Header set Set-Cookie HttpOnly;Secure

Verification

You can either leverage the browser’s inbuilt developer tools to check the response header or use an online tool.

Did it help?

This is one of the many hardening things to do in Apache.

  • Chandan Kumar
    Author
    As the founder of Geekflare, I’ve helped millions to excel in the digital realm. Passionate about technology, I’m on a mission to explore the world and amplify growth for professionals and businesses alike.
Thanks to our Sponsors
More great readings on Apache HTTP
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • Monday.com is an all-in-one work OS to help you manage projects, tasks, work, sales, CRM, operations, workflows, and more.
    Try Monday
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder