Enable HSTS on cPanel & WHM interface?

carock

Well-Known Member
Sep 25, 2002
270
9
168
St. Charles, MO
Is it possible to enable HSTS for the cPanel and WHM interfaces?

Security auditors whining about not having HSTS set in these.

Thanks,
Chuck
 

httpdocs

Well-Known Member
Mar 9, 2018
59
10
83
United States
cPanel Access Level
Root Administrator
Yes.
Include this to .htaccess file:
# Security header Enable HSTS
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
 
  • Like
Reactions: Rajeeva Lochana

carock

Well-Known Member
Sep 25, 2002
270
9
168
St. Charles, MO
Where is that at? I did not find a .htaccess file here: /usr/local/cpanel/whostmgr/docroot

or the base directory. The only place in the cpanel tree I find .htaccess files are in the 3rdparty stuff and horde.

Thanks,
Chuck
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
Hi @carock

cPanel/WHM doesn't use HSTS but you can force a secure connection using Tweak Settings -> Security:

Require SSL for cPanel Services

This option forces the server to redirect unencrypted cPanel, Webmail, WHM, and DAV requests to secure ports according to the SSL redirection settings. If “Choose the closest matched domain for which that the system has a valid certificate when redirecting from non-SSL to SSL URLs” is enabled, the system will redirect to the best matched certificate for the domain. If “Choose the closest matched domain for which that the system has a valid certificate when redirecting from non-SSL to SSL URLs” is disabled, the system will redirect to the https:// URL for the domain, even if no valid certificate exists for the domain.
 

omgwalt

Registered
Dec 1, 2019
3
0
1
Connecticut
cPanel Access Level
Root Administrator
cPanel/WHM doesn't use HSTS
Is this something that cPanel might consider adding? I ask because Mozilla now suggests it among their web security recommendations for creating secure web applications.


In fact, it would be great if cPanel would provide tools to implement all of their recommendations.
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
Hello @omgwalt

For all the domains including the hostname you can add some variation of the following for HSTS at WHM>>Service Configuration>>Apache Configuration -> Include Editor -> PreMain Include

Code:
Header always set Strict-Transport-Security "max-age=300; includeSubDomains; preload"
Because cPanel/WHM runs using cPSrvd which is separate from your domains it does not have this capability at this time. I checked for open feature requests on this as well and I didn't find anything. I would strongly urge you to open one using the link in my signature. Once it's open feel free to update here with the link so others can easily find it and vote on it as well.


Thanks!
 
  • Wow
Reactions: Rajeeva Lochana

Rajeeva Lochana

Well-Known Member
Community Guide Contributor
May 27, 2019
122
38
28
India
cPanel Access Level
Root Administrator
Hi @carock

cPanel/WHM doesn't use HSTS but you can force a secure connection using Tweak Settings -> Security:

Require SSL for cPanel Services

This option forces the server to redirect unencrypted cPanel, Webmail, WHM, and DAV requests to secure ports according to the SSL redirection settings. If “Choose the closest matched domain for which that the system has a valid certificate when redirecting from non-SSL to SSL URLs” is enabled, the system will redirect to the best matched certificate for the domain. If “Choose the closest matched domain for which that the system has a valid certificate when redirecting from non-SSL to SSL URLs” is disabled, the system will redirect to the https:// URL for the domain, even if no valid certificate exists for the domain.
I also just want to inform that HSTS should only be present in https. So, I use the following for the, it works with apache in a cpanel server. You can either add this to the .htaccess or, you can add the to the main config file i.e., by following my 2nd way. Adding it to the .htaccess file of a website will only affect the particular website, and the folder the .htaccess file is placed in. mod_headers should be enabled in apache.
1st way:
Apache config:
Header always set Strict-Transport-Security "max-age=300; includeSubDomains; preload" "expr=%{HTTPS} == 'on'"
Use 63072000 instead of 300, if needed to preload. And, also, to preload, go to HSTS Preload List Submission and follow those instructions.

2nd way:
Add the same to the following:
WHM>>Service Configuration>>Apache Configuration -> Include Editor -> PreMain Include

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
The env=HTTPS doesn't work sometimes on subdomains with https e.g. https://subdomain.example.com. Am I missing something?

For more security, use the headers also, by adding these to the apache conf or .htaccess file:
Apache config:
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-XSS-Protection "1; mode=block"
Header always set X-Content-Type-Options nosniff
Thanks.
 
Last edited:

AnonymousBR

Registered
Apr 5, 2020
2
1
3
Brasil
cPanel Access Level
Root Administrator
Good afternoon.

Sorry if I use any wrong words. Possible language conflict.

I need help to configure the HSTS correctly.

On a consultation website, I received the following error.

Warning: Unnecessary HSTS header over HTTP

The HTTP page at http: //domain.com sends an HSTS header. This has no effect over HTTP, and should be removed.

Does anybody know how to solve this?
 
Last edited:

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
You might want to read these threads for information - the one you're in here:


as well as


The reason you received that error is because you're attempting to view the site over HTTP:// not https://
 

divemasterza

Active Member
Feb 2, 2013
32
2
58
South Africa
cPanel Access Level
Root Administrator
Twitter
Good afternoon.

Sorry if I use any wrong words. Possible language conflict.

I need help to configure the HSTS correctly.

On a consultation website, I received the following error.

Warning: Unnecessary HSTS header over HTTP

The HTTP page at http: //domain.com sends an HSTS header. This has no effect over HTTP, and should be removed.

Does anybody know how to solve this?
depending how you implemented you want to add the end bit env=HTTPS

Code:
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
 

AnonymousBR

Registered
Apr 5, 2020
2
1
3
Brasil
cPanel Access Level
Root Administrator
depending how you implemented you want to add the end bit env=HTTPS

Code:
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS

Thank you for your help. I managed to solve my problem.

I added the following code at the beginning of .htaccess and Apache.

Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" "expr=%{HTTPS} == 'on'"

A tip for those who had difficulty adding this feature:

1 - The domain must have a valid SSL certificate.

2 - After adding this code, the first redirect must be to https: //domain.com and not to https: //www.domain.com

3 - Depending on the server configuration, it may be necessary to add this code in the .htaccess file and in the apache settings within WHM.

Home / Service Configuration / Apache Configuration / Include Editor / Pre Main Include

Select the All Versions option and enter the code. Click Update and then restart the Apache services.
 
Last edited:
  • Like
Reactions: masterross

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,405
2,256
363
cPanel Access Level
Root Administrator
That's an excellent question, especially since the HSTS documentation says this about that value:


Code:
Preloading

When using preload, the max-age directive must be at least 31536000 (1 year), and the includeSubDomains directive must be present. Not part of the specification.
I'll reach out to the web development team to see if there is an explanation for this, or if we should update our documentation to make that time longer. I won't have details tonight, but hopefully I'll hear back from them tomorrow.
 
  • Like
Reactions: clopezi

clopezi

Active Member
Mar 17, 2013
41
13
58
cPanel Access Level
Root Administrator
That's an excellent question, especially since the HSTS documentation says this about that value:


Code:
Preloading

When using preload, the max-age directive must be at least 31536000 (1 year), and the includeSubDomains directive must be present. Not part of the specification.
I'll reach out to the web development team to see if there is an explanation for this, or if we should update our documentation to make that time longer. I won't have details tonight, but hopefully I'll hear back from them tomorrow.
Thanks a lot!