PluginProbe
NETSENSAI Shield / 1.3
NETSENSAI Shield v1.3
1.6.1 trunk 1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.6.0
netsensai-shield / includes / apply_security_headers.php

apply_security_headers.php in NETSENSAI Shield 1.3, at includes/apply_security_headers.php

34 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly.
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Apply security headers.
9 *
10 * This function applies several HTTP security headers to enhance site protection if the
11 * 'ns_shield_security_headers' option is enabled. The following headers are applied:
12 * - Strict-Transport-Security: Applied only if the connection is secure (HTTPS).
13 * - X-Frame-Options: SAMEORIGIN
14 * - X-Content-Type-Options: nosniff
15 * - Referrer-Policy: no-referrer-when-downgrade
16 * - Permissions-Policy: geolocation=(self), microphone=()
17 *
18 * @return void
19 */
20 function ns_shield_apply_security_headers() {
21 if ( get_option( 'ns_shield_security_headers' ) ) {
22 // Apply HSTS header only if connection is secure.
23 if ( is_ssl() ) {
24 header( "Strict-Transport-Security: max-age=31536000; includeSubDomains; preload" );
25 }
26 header( "X-Frame-Options: SAMEORIGIN" );
27 header( "X-Content-Type-Options: nosniff" );
28 header( "Referrer-Policy: no-referrer-when-downgrade" );
29 header( "Permissions-Policy: geolocation=(self), microphone=()" );
30 }
31 }
32 add_action( 'send_headers', 'ns_shield_apply_security_headers' );
33 ?>
34