WordPress Plugin – Security Header Generator

Wordpress Plugin - Security Header Generator

Posted:  October 13, 2021

Wordpress Plugin - Security Header Generator

Managing the hosting for thousands of websites is no easy feat. WordPress makes that a tad more difficult because it currently runs over 1/3 of the websites on the internet. Keeping an application with this kind of global coverage secure should be the number 1 priority of every web hosting company, however, this is not always the case.

This plugin attempts to implement the necessary server response headers to help mitigate the most common website attacks, and allows the site managers greater and quicker control over the those headers, which would normally entail a great deal of back-and-forth discussions with their hosting companies support teams.

Why bother going this route?

Well, I have over 17 years development and server management experience and in all that time I can proudly say, I have never had one of my websites hacked.

Couple this with the fact that not every hosting company will allow you to set these headers for your site on your own, some will not even implement them if you ask them to.


This plugin attempts to automatically implement the server response headers necessary to mitigate the most common website attacks, in an easy to use management interface suitable for most website managers.

It allows you to configure the headers you need and attempts to automatically generate some of the more complicated ones.

It then generates the proper server software configurations for the most common server types, just in case the hosting company your site resides on removes the ability to set the headers programatically.

Please click the More Info links below for explanations of the headers implemented.


Directions & Settings


  • Download the plugin, unzip it, and upload to your sites `/wp-content/plugins/` directory
    • You can also upload it directly to your Plugins admin
  • Activate the plugin through the ‘Plugins’ menu in WordPress


Head over to the admin section of your site and click “Security Headers”, configure how you need it to be configured. The configured headers will automatically be implemented. Please be aware that some web hosts do not allow the header implementation utilized in this plugin (PHP), if you find this is the case for your site, head over to the “Implementation” page to see how you can accomplish this with other methods.

Once configured you can try to have the content security policy automatically generated by getting into CLI on your sites server and running the following command: wp csp generate

That will attempt to parse your entire website and gather up all external domains tied to the resource it is attached to, then create a custom post to store the results in.

You may need to run this more than once, and you will need to have some patience while it runs.

NOTE: If you are running this in a multi-site environment, you must pass the --url flag to the WP CLI command. Making the full command: wp csp generate --url=YOUR_SITES_FULL_URL


If your hosting environment is already setting these headers, most likely your settings in this plugin will NOT get overwritten with the values you specify.

If this is indeed the case, please check with your hosting company if they are, or check your server configuration for the headers getting set. The plugin will do it’s best to override them, but in some environments this is just not possible.

You can also check the Implementation tab to see if your hosting will implement the applicable configuration for you.


  • Standard Security Tabstandard headers

    • Apply to Admin
      • Select yes or no to apply these same headers to the admin side of your site.
    • WordPress Defaults
      • Select Yes or No to have the plugin automatically include WordPress specific external resources in the Content Security Policy
        • I have left this as an unconditional field. There may be a point in we browsers futures where it may have a use other than just the CSP
          • img-src: *.googletagmanager.com *.w.org *.gravatar.com *.google.com *.google-analytics.com *.gstatic.com
          • script-src: *.g.doubleclick.net *.google-analytics.com *.google.com *.googletagmanager.com *.gstatic.com
          • style-src: *.googleapis.com *.gstatic.com
          • font-src: *.gstatic.com *.bootstrapcdn.com
          • frame-src: *.g.doubleclick.net *.google.com *.fls.doubleclick.net
          • connect-src: *.google-analytics.com *.wpengine.com yoast.com *.google.com *.g.doubleclick.net
    • Strict Transport Security
    • Frame Sources
    • XSS Protection
    • Prevent MimeType Sniffing
    • Origin Referrers
      • Select Yes or No to have the plugin add a header to allow only origin referrers
      • Select Referrer Policy to send
        • No Referrer: The Referer header will be omitted entirely. No referrer information is sent along with requests.
        • Origin Only: Only send the origin of the document as the referrer.
        • Same Origin: A referrer will be sent for same-site origins, but cross-origin requests will send no referrer information.
        • Strict Origin on Cross Domain: Send the origin, path, and querystring when performing a same-origin request, only send the origin when the protocol security level stays the same while performing a cross-origin request
        • No Referrer on Downgrade: The origin, path, and querystring of the URL are sent as a referrer when the protocol security level stays the same
        • Origin on Cross Domain: Send the origin, path, and query string when performing a same-origin request, but only send the origin of the document for other cases.
        • Strict Origin: Only send the origin of the document as the referrer when the protocol security level stays the same
        • Full Referrer: Send the origin, path, and query string when performing any request, regardless of security.
    • Force Downloads
    • Cross Domain Origins
    • Upgrade Insecure Requests
    • Decline FLoC
  • Content Security Policy Tabcsp settings

    • Content Security Policy
      • Select Yes or No to have the plugin attempt to automatically generate a Content Security Policy. Selecting Yes, will open up a handful of text fields that you can add additional domains to. Please only include the FQDN, and please organize them accordingly.
        • Use a space-delimited list if you need add more than one additional domain.
      • This will parse the enqueued styles and scripts for the front-end of your site automatically, provided your theme has properly done this.
      • This will add 2 additional headers to your site. Content-Security-Policy and X-Content-Security-Policy, configured with the detected and custom added domains to their respective content types.
      • See here for more information: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
  • Permissions Policy Tabpermissions policy

    • Select Yes or No to have the plugin attempt to automatically generate a Permissions Policy. Selecting Yes, will open up a handful of directives and the sources for them. If you select “Source” for any of them you will be allowed to enter a space-delimited list of URL’s to be allowed as sources.
      • Please make sure to use full URL’s for the sources including the protocol used. (example: https://kevinpirnie.com)
    • See here for more information: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
  • Implementation Tabimplementation

    • This tab will generate and show you the most common server type configurations for your configured security headers. If your hosting company does not allow PHP to set the headers, you will need to copy the config for your server, and send it to your hosting company to have implemented for you in order for them to work.


= 3.0.22 =
* Fix: more array checks

= 3.0.10 =
* Fix: Array issue
* Fix: Strict typing issue

= 3.0.09 =
* Feature: Implement post update hook to try to properly migrate existing settings to the new format
* Update: Change exportable/importable settings names, more legible
    * While I will do my best to automate this, please note it may not be perfect... I am only human after all ;)
    * If you export your settings before updating, you can import them again after updating and the below will be 
      taken care of for you.
    * Just in case it does not work 100%, please export your settings before updating to this version and 
      perform a search and replace for the string to remove it:
        * Search: "kp_cspgen_"
        * Replace: null|nothing|empty
    * NOTE: If you do not export your settings I will not guarantee that you will not have to reconfigure the plugin.
      Although... I did take a backup ;) You will need to hop into your database to grab it though, it will be in your
      options table, and it is called: `wpsh_TEMP_settings`.  I will have this automatically removed in a future update
* Add: Option to remove server advertising.
* Add: Expect-CT header
    * The Expect-CT header lets sites opt in to reporting and/or enforcement of Certificate Transparency requirements, 
      to prevent the use of misissued certificates for that site from going unnoticed.
    * Doc: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT
    * Hook: `wpsh_expectct_header`
* Updated: Feature Policies.
    * Removed the following: battery, layout-animations, legacy-image-formats, oversized-images, screen-wake-lock, 
      unoptimized-images, unsized-media, web-share
    * The above no longer have any browser support.
    * Added: Descriptive descriptions for each directive
* Updated: Content Security Policy
    * Added: the following fetch directives: 
        * child-src, manifest-src, object-src, prefetch-src, script-src-elem, 
          script-src-attr, style-src-elem, style-src-attr, worker-src, navigate-to
    * Added: Unsafe Inline and Unsafe Eval settings on each CSP directive
    * Added: Descriptive descriptions for each directive
    * Reworked: Settings for the entire section, which of course caused me to rewrite the way they are implemented.

= 2.2.15 =
* Implement: The 2 new headers documentation and implementation tabs SMH

= 2.2.13 =
* Deprecated: The X-XSS-Protection header has been deprecated by modern browsers. 
    * As a result we are marking the setting, hook, and functionality to set it as deprecated and 
      will be removed in future versions of this plugin.
    * Doc: https://owasp.org/www-project-secure-headers/#x-xss-protection
    * Set to log as deprecated
* Rework: Settings Fields
    * found it was causing a conflict with another plugin
* Add: 2 new Headers
    * Cross-Origin-Embedder-Policy
        * This response header (also named COEP) prevents a document from loading any cross-origin resources that don’t 
          explicitly grant the document permission
        * https://owasp.org/www-project-secure-headers/#cross-origin-embedder-policy
        * Hook: `wpsh_coep_header`
    * Cross-Origin-Opener-Policy
        * This response header (also named COOP) allows you to ensure a top-level document does not share a browsing 
          context group with cross-origin documents. COOP will process-isolate your document and potential attackers can’t 
          access to your global object if they were opening it in a popup, preventing a set of cross-origin attacks dubbed XS-Leaks
        * https://owasp.org/www-project-secure-headers/#cross-origin-opener-policy
        * Hook: `wpsh_coop_header`
* NOTE: There is no full browser support yet for Cross-Origin-Resource-Policy, so for now it is going to be left out.  As a result,
  the only option for the Embedder Policy is "unsafe-none".  Once it is fully cross-browser this header will be implemented.

= 2.1.09 =
* Fixed: Admin bar menu show in for non-admin capabilities.
* Improved: Usage anywhere framework fields.
* Updated: JS libraries (codemirror, leaflet, etc).
* Improved: Some js and css coding.

= 2.0.97 =
* Verify: Core 5.9 Compatibility
* Feature: Add some hooks.  All pretty self-explanatory, so here is the list and arguments if there are any:
    * `wpsh_pre_headers`, `wpsh_send_frontend_headers`, `wpsh_send_admin_headers`, `wpsh_post_headers`
    * `wpsh_sts_header` - Arg: The "Strict-Transport-Security" header content for the generated options
    * `wpsh_ofs_header` - Arg: The "X-Frame-Options" header content for the generated options
    * `wpsh_xss_header` - Arg: The "X-Xss-Protection" header content for the generated options
    * `wpsh_mimesniffing_header` - Arg: The "X-Content-Type-Options" header content for the generated options
    * `wpsh_referrer_header` - Arg: The "Referrer-Policy" header content for the generated options
    * `wpsh_dlopt_header` - Arg: The "X-Download-Options" header content for the generated options
    * `wpsh_crossdomain_header` - Arg: The "X-Permitted-Cross-Domain-Policies" header content for the generated options
    * `wpsh_csp_header` - Arg: The "Content-Security-Policy" header content for the generated options
    * `wpsh_upgradesecure_header` - Arg: The "Content-Security-Policy" header content for the generated options
    * `wpsh_floc_header` - Arg: The "Permissions-Policy" header content for the generated options
    * `wpsh_permissions_header` - Arg: The "Permissions-Policy" header content for the generated options
    * `wpsh_pre_csp_generate` - fires off before the Content Security Policy is generated
    * `wpsh_post_csp_generate` - Arg: The generated Content Security Policy string

= 2.0.36 =
* Tweak admin permissions
    * found an issue where a subsite admin could not administer
      the settings if the super-admin disabled Plugins in settings

= 2.0.08 =
* Convert all major comments to phpdoc
* Fix `OR DIE` on direct file access
* Removed double PHP version check (whoops!)
* move the plugins stylesheet
* Core 5.8.1 Compliance

= 1.9.51 =
* Update: Rewrite Field Framework

= 1.9.47 =
* Update: Field Framework

= 1.9.44 =
* fixed minor issue setting FLoC header

= 1.9.43 =
* Removed sticky header for settings
    * it was not working properly in all browsers anyways
* Implemented Permissions-Policy header
    * See Here for more information: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
* Organize header settings into separate tabs
* Fixed issue where setting would automatically collapse
* Re-implement uninstall

= 1.9.27 =
* WordPress Core 5.8 compliance
    * Tested
* **feature** re-implement WP CLI functionality
    * Attempts to spider the site gathering up only external resources like imagery, stylesheets, scripts, fonts, frames, etc...
    * Creates a custom post type to hold the output of the parsed external resources
    * Adds the domains only to the Content-Security-Policy header

= 1.9.23 =
* Fix issue where admin menu would not show for some
* Force PHP 7.3 minimum on actviation

= 1.9.18 =
* Publishing
    * slight issue in readme was preventing updating to 1.9.17

= 1.9.17 =
* Remove the remote header checks implemented in v1.9.11
* Update Documentation

= 1.9.11 =
* New class to attempt server-side header Implementation
* If server-side headers do exist, show a note in Settings
* Attempt to override existing headers
    * only headers set by plugin
* Cache the above check for 1 day
* Temprorarily remove the CLI functionality

= 1.8.23 =
* Update settings framework
* Updated minimum PHP requirement to PHP 7.3

= 1.8.14 =
* Update for WP Core 5.7.2
* Update methods to force output type

= 1.8.11 =
* implement FLoC decline setting and headers

= 1.7.03 =
* full field framework update

= 1.7.02 = 
* field framework update
* little styling tweak for it

= 1.6.10 = 
* fix path issue

= 1.6.09 =
* replace field framework
    * big thanks to Codestar: https://codecanyon.net/user/codestar
* rebuild the settings and retrieval
* rework admin sending of headers
* clear cache on settings save

= 1.5.22 =
* update field framework
* 5.7 compliance
* check for existing functionality

= 1.4.11 =
* fix uninstall to remove all options, including for multisite

= 1.4.09 =
* Implement true autoloader
    * rename class files accordingly
* Implement true autoloader for CLI
    * rename class files accordingly

= 1.3.13 =
* First public release



Kevin Pirnie

Kevin Pirnie

20+ Years of PC and server maintenance & over 15+ years of web development/design experience; you can rest assured that I take every measure possible to ensure your computers are running to their peak potentials. I treat them as if they were mine, and I am quite a stickler about keeping my machines up to date and optimized to run as well as they can.

Our Privacy Policy

Revised: June 8, 2021

Thank you for choosing to be part of my website at https://kevinpirnie.com (“Company”, “I”, “me”, “mine”). I am committed to protecting your personal information and your right to privacy. If you have any questions or concerns about this privacy notice, or my practices with regards to your personal information, please contact me at .

When you visit my website https://kevinpirnie.com (the “Website”), and more generally, use any of my services (the “Services”, which include the Website), I appreciate that you are trusting me with your personal information. I take your privacy very seriously. In this privacy notice, I seek to explain to you in the clearest way possible what information we collect, how I use it and what rights you have in relation to it. I hope you take some time to read through it carefully, as it is important. If there are any terms in this privacy notice that you do not agree with, please discontinue use of my Services immediately.

This privacy notice applies to all information collected through my Services (which, as described above, includes our Website), as well as, any related services, sales, marketing or events.

Please read this privacy notice carefully as it will help you understand what I do with the information that I collect.


Information automatically collected

In Short: Some information – such as your Internet Protocol (IP) address and/or browser and device characteristics – is collected automatically when you visit my Website.

I automatically collect certain information when you visit, use or navigate the Website. This information does not reveal your specific identity (like your name or contact information) but may include device and usage information, such as your IP address, browser and device characteristics, operating system, language preferences, referring URLs, device name, country, location, information about how and when you use our Website and other technical information. This information is primarily needed to maintain the security and operation of our Website, and for our internal analytics and reporting purposes.

Like many businesses, I also collect information through cookies and similar technologies.

The information I collect includes:
Log and Usage Data. Log and usage data is service-related, diagnostic, usage and performance information our servers automatically collect when you access or use our Website and which we record in log files. Depending on how you interact with us, this log data may include your IP address, device information, browser type and settings and information about your activity in the Website (such as the date/time stamps associated with your usage, pages and files viewed, searches and other actions you take such as which features you use), device event information (such as system activity, error reports (sometimes called ‘crash dumps’) and hardware settings).

Device Data. I collect device data such as information about your computer, phone, tablet or other device you use to access the Website. Depending on the device used, this device data may include information such as your IP address (or proxy server), device and application identification numbers, location, browser type, hardware model Internet service provider and/or mobile carrier, operating system and system configuration information.

Location Data. I collect location data such as information about your device’s location, which can be either precise or imprecise. How much information I collect depends on the type and settings of the device you use to access the Website. For example, I may use GPS and other technologies to collect geolocation data that tells me your current location (based on your IP address). You can opt out of allowing me to collect this information either by refusing access to the information or by disabling your Location setting on your device. Note however, if you choose to opt out, you may not be able to use certain aspects of the Services.


In Short: I process your information for purposes based on legitimate business interests, the fulfillment of my contract with you, compliance with my legal obligations, and/or your consent.

I use personal information collected via my Website for a variety of business purposes described below. I process your personal information for these purposes in reliance on my legitimate business interests, in order to enter into or perform a contract with you, with your consent, and/or for compliance with my legal obligations. I indicate the specific processing grounds I rely on next to each purpose listed below.

For other business purposes. I may use your information for other business purposes, such as data analysis, identifying usage trends, determining the effectiveness of our promotional campaigns and to evaluate and improve my Website, products, marketing and your experience. I may use and store this information in aggregated and anonymized form so that it is not associated with individual end users and does not include personal information. I will not use identifiable personal information without your consent.


In Short: I only share information with your consent, to comply with laws, to provide you with services, to protect your rights, or to fulfill business obligations.


In Short: I may use cookies and other tracking technologies to collect and store your information.

I may use cookies and similar tracking technologies (like web beacons and pixels) to access or store information. Specific information about how I use such technologies and how you can refuse certain cookies is set out in our Cookie Notice.


In Short: We may transfer, store, and process your information in countries other than your own.

My servers are located in the United States of America, unless otherwise requested by my clients. If you are accessing my Website from outside, please be aware that your information may be transferred to, stored, and processed by me in my facilities and by those third parties with whom I may share your personal information (see “WILL YOUR INFORMATION BE SHARED WITH ANYONE?” above), in and other countries.

If you are a resident in the European Economic Area, then these countries may not necessarily have data protection laws or other similar laws as comprehensive as those in your country. I will however take all necessary measures to protect your personal information in accordance with this privacy notice and applicable law.


In Short: I keep your information for as long as necessary to fulfill the purposes outlined in this privacy notice unless otherwise required by law.

I will only keep your personal information for as long as it is necessary for the purposes set out in this privacy notice, unless a longer retention period is required or permitted by law (such as tax, accounting or other legal requirements). No purpose in this notice will require me keeping your personal information for longer than 6 months.

When I have no ongoing legitimate business need to process your personal information, I will either delete or anonymize such information, or, if this is not possible (for example, because your personal information has been stored in backup archives), then I will securely store your personal information and isolate it from any further processing until deletion is possible.


In Short: I aim to protect your personal information through a system of organizational and technical security measures.

I have implemented appropriate technical and organizational security measures designed to protect the security of any personal information I process. However, despite our safeguards and efforts to secure your information, no electronic transmission over the Internet or information storage technology can be guaranteed to be 100% secure, so I cannot promise or guarantee that hackers, cybercriminals, or other unauthorized third parties will not be able to defeat my security, and improperly collect, access, steal, or modify your information. Although I will do my best to protect your personal information, transmission of personal information to and from my Website is at your own risk. You should only access the Website within a secure environment.


In Short: I do not knowingly collect data from or market to children under 18 years of age.

I do not knowingly solicit data from or market to children under 18 years of age. By using the Website, you represent that you are at least 18 or that you are the parent or guardian of such a minor and consent to such minor dependent’s use of the Website. If I learn that personal information from users less than 18 years of age has been collected, I will deactivate the account and take reasonable measures to promptly delete such data from my records. If you become aware of any data I may have collected from children under age 18, please contact me at .


In Short: You may review, change, or terminate your account at any time.

If you are a resident in the European Economic Area and you believe I am unlawfully processing your personal information, you also have the right to complain to your local data protection supervisory authority. You can find their contact details here: http://ec.europa.eu/justice/data-protection/bodies/authorities/index_en.htm.

If you are a resident in Switzerland, the contact details for the data protection authorities are available here: http://ec.europa.eu/justice/data-protection/bodies/authorities/index_en.htm.

Cookies and similar technologies: Most Web browsers are set to accept cookies by default. If you prefer, you can usually choose to set your browser to remove cookies and to reject cookies. If you choose to remove cookies or reject cookies, this could affect certain features or services of my Website.


Most web browsers and some mobile operating systems and mobile applications include a Do-Not-Track (“DNT”) feature or setting you can activate to signal your privacy preference not to have data about your online browsing activities monitored and collected. At this stage no uniform technology standard for recognizing and implementing DNT signals has been finalized. As such, I do not currently respond to DNT browser signals or any other mechanism that automatically communicates your choice not to be tracked online. If a standard for online tracking is adopted that I must follow in the future, I will inform you about that practice in a revised version of this privacy notice.


In Short: Yes, if you are a resident of California, you are granted specific rights regarding access to your personal information.

California Civil Code Section 1798.83, also known as the “Shine The Light” law, permits my users who are California residents to request and obtain from me, once a year and free of charge, information about categories of personal information (if any) I disclosed to third parties for direct marketing purposes and the names and addresses of all third parties with which I shared personal information in the immediately preceding calendar year. If you are a California resident and would like to make such a request, please submit your request in writing to me using the contact information provided below.

If you are under 18 years of age, reside in California, and have a registered account with the Website, you have the right to request removal of unwanted data that you publicly post on the Website. To request removal of such data, please contact us using the contact information provided below, and include the email address associated with your account and a statement that you reside in California. I will make sure the data is not publicly displayed on the Website, but please be aware that the data may not be completely or comprehensively removed from all my systems (e.g. backups, etc.).


In Short: Yes, I will update this notice as necessary to stay compliant with relevant laws.

I may update this privacy notice from time to time. The updated version will be indicated by an updated “Revised” date and the updated version will be effective as soon as it is accessible. If I make material changes to this privacy notice, I may notify you either by prominently posting a notice of such changes or by directly sending you a notification. We encourage you to review this privacy notice frequently to be informed of how I am protecting your information.


If you have questions or comments about this notice, you may email me at or by post to:

Kevin C. Pirnie

22 Orlando St.
Feeding Hills, MA 01030
United States of America


Based on the applicable laws of your country, you may have the right to request access to the personal information I collect from you, change that information, or delete it in some circumstances. To request to review, update, or delete your personal information, you may email me at or by post to:

Kevin C. Pirnie

22 Orlando St.
Feeding Hills, MA 01030
United States of America