Adding SSL Security Headers

2020-12-11

Adding SSL Security Headers

Recently upgraded to WordPress 5.6, and I found that there is an SSL error in Site Health: Not all recommended security headers are installed. It can be resolved by adding a few lines to .htaccess.

Contents

SSL Error in Site Health of WordPress

If you found the below error, you can follow this tutorial to resolve it.

Not all recommended security headers are installed

Your .htaccess file does not contain all recommended security headers.

  • HTTP Strict Transport Security
  • Content Security Policy: Upgrade Insecure Requests
  • X-XSS protection
  • X-Content Type Options
  • Referrer-Policy
  • Expect-CT

The security headers are:

  • HSTS (HTTP Strict Transport Security) – a browser will do all requests to your site over HTTPS from then on when this header is set on your domain.
  • CSP: Upgrade Insecure Requests – directive instructs user agents to treat all of a site’s insecure URLs (those served over HTTP) as though they have been replaced with secure URLs (those served over HTTPS). This directive is intended for web sites with large numbers of insecure legacy URLs that need to be rewritten.
  • X-XSS protection – will stop pages from loading if a reflected cross-site scripting (XSS) attack is detected.
  • X-Content Type Options – will force the browser not to “guess” what kind of data is passed. If the extension is “.doc”, the browser should get a .doc file, not something else (a .exe).
  • Referrer-Policy – only sets a referrer when going from the same protocol and not when downgrading (HTTPS -> HTTP).
  • Expect-CT (Certificate Transparency) – a Certificate Authority (the issuer of the SSL certificate) needs to log the certificates that are issued in a separate log, the CT framework., preventing fraud.

Editing .htaccess

If you have FTP access, find the .htaccess under root directory and add the below Recommended security headers above # BEGIN WordPress.

# Recommended security headers
Header always set Strict-Transport-Security: "max-age=31536000" env=HTTPS
Header always set Content-Security-Policy "upgrade-insecure-requests;"
Header always set X-XSS-Protection "1; mode=block"
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy: "no-referrer-when-downgrade"
Header always set Expect-CT "max-age=7776000, enforce"
# End Recommended security headers

The final .htaccess:

# Recommended security headers
Header always set Strict-Transport-Security: "max-age=31536000" env=HTTPS
Header always set Content-Security-Policy "upgrade-insecure-requests;"
Header always set X-XSS-Protection "1; mode=block"
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy: "no-referrer-when-downgrade"
Header always set Expect-CT "max-age=7776000, enforce"
# End Recommended security headers

# BEGIN WordPress
...

Notes: To remove HSTS. Keep the line, but set max-age to zero. Or "max-age=0"

Scan the Site Health again.

Great job! Everything is running smoothly here.

References

免費按讚支持創作

喜歡我的文章,請在下面按讚 5 下,助我得到 LikeCoin 獎賞,支持我繼續創作免費內容。

行有餘力,可以成為我的讚賞公民,每月送我一杯咖啡,從此每份贊助,都會化成實質支持。

作者簡介

香港斜槓族,喜歡學習的宅女。打工時期做過行銷、教育及IT行業。自學技能包括:網站開發、網路行銷、影片製作、平面設計等。

希望透過內在自我認知及外在技能培養的分享,幫助網路創業者實現理想生活,共建和諧美好的世界。

Leave a comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.