![]() |
HTTP Strict Transport Security (HSTS) is a security policy component that assists with safeguarding sites against protocol for downsize attacks and cookies highjacking by forcing the HTTPS connections. Using HSTS on your Apache web server improves the security of your site. Prerequisites
Introduction to HSTSHTTP Strict Transport Security (HSTS) is a web security system that assists with safeguarding websites against conventional DDoS assaults and cookie hijacking. It permits a web server to tell web browsers (or other consenting users) to interface with it using secure HTTPS systems, and never by method of the insecure HTTP systems. Importance of HSTS in web securityHTTP Strict Transport Security (HSTS) is a critical component in web security intended to improve the security of user information and some particular sorts of attacks. It works by telling web browsers to just cooperate with a website over a secure HTTPS association, regardless of whether the user wants to get to it through an insecure HTTP connection. This guarantees that important data, for example, login certifications or money transactions, remains encoded and safeguarded from hackers. Why Use HSTS?HSTS keeps hackers from driving a user’s browser to minimize a secure HTTPS association with an insecure HTTP association. In a regular minimization hacking situation, a hacker captures correspondence between a user and a website and controls it to drive the use of HTTP rather than HTTPS. This minimization can open delicate data to block attempts or alteration. HSTS handles this by training consistent web browsers to just use a website over HTTPS, whether or not the user at first enters an HTTP or HTTPS URL. When a user visits a website that has empowered HSTS, their browser recalls this mandate for a predetermined period (constrained by the “maximum age” order), guaranteeing all resulting associations with that webpage are consequently secured with HTTPS. How to check if Apache is installed and running?Checking whether the Apache is installed and running can be done using the following command: apache2 -v
This command will tell the Apache version if it is correctly installed in the system, after confirming the installation, to check whether it is running or not use the following command: sudo systemctl status apache2 # for Debian-based system How to ensure SSL/TLS is correctly configured on Apache?To check whether SSL is correctly configured on Apache, you will have to enable and run the mod_ssl package, for refer to the article mentioned below:
Steps to enable HTTP Strict Transport Security (HSTS) for ApacheStep 1: Open the default SSL fileOpen the directory where the site’s files are stored, and open the 000-default-le-ssl.conf, for this use the following command: vim sites-available/000-default-le-ssl.conf
Note: The directory can vary depending on where you have kept your local host files. ![]() Open the default SSL file. Step 2: Add HSTS HeaderThe next step is to insert the HSTS code between the SSL code, as you can see below, the empty area is where the code should be. ![]() Insert the HSTS code between the SSL file code. In the space enter the following code: Header always set Strict-Transport-Security max-age=31536000
![]() Header always set Strict-Transport-Security max-age=31536000 Examples of parameters which can be used in HSTS:
Step 3: Restart ApacheThe next step is to reload the Apache server, for this run the following command in the terminal: Linux (Debian/Ubuntu): sudo systemctl restart apache2
Linux (Red Hat/CentOS): sudo systemctl restart httpd
![]() systemctl reload apache2 Step 4: Open the site directory in VimThe next step is to open the site directory in the Vim editor, to do this type the following command into your terminal: vim sites-available/directory-name/
![]() Open the site directory in Vim. Step 5: Add security codeThe next step is to add the security code in this file similar to the one we added previously, so add the following code in the code: Header always set Strict-Transport-Security max-age=31536000
![]() Add security code. Step 6: Reload the serviceThe next step is to reload the service, for this run the following command in the terminal: systemctl reload nginx
![]() Reload the service. Step 7: Verify ConfigurationTo check whether the site is now secured by HSTS or not, open the site in the browser and open developer tools > network > select the site and see if the following security property is being displayed or not. If it’s displayed similarly to the image then it means that the HSTS is implemented successfully. ![]() Verify if HSTS is enabled. ConclusionIncluding HTTP Strict Transport Security (HSTS) for Apache is an important move towards improving web security by guaranteeing all data sent with the site and with your server are encoded over HTTPS. by adding HSTS headers, you can protect the site against attacks and also increase user privacy. make sure to carefully set the HSTS header parameters, including the max-age, etc. |
Reffered: https://www.geeksforgeeks.org
Web Technologies |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 17 |