Skip to content

Commit 9001693

Browse files
Merge pull request #176 from MITLibraries/headers
Update security headers
2 parents 3e23162 + 4020669 commit 9001693

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ wp-cli.local.yml
7373
web/app/mu-plugins/*/
7474
!web/app/mu-plugins/mitlib-post
7575
!web/app/mu-plugins/mitlib-secrets-widget
76+
!web/app/mu-plugins/mitlib-security
7677

7778
# Plugins
7879
# Ignore the plugins directory by default. WordPress plugins should be managed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Plugin Name: MITlib Security
4+
* Plugin URI: https://github.com/MITLibraries/mitlib-wp-network/tree/master/web/app/mu-plugins/mitlib-security/
5+
* Description: A plugin to extend the security headers across the WordPress network.
6+
* Version: 0.0.1
7+
* Author: Matt Bernhardt
8+
* Author URI: https://github.com/matt-bernhardt
9+
* License: GPL2
10+
*
11+
* @package MITlib Security
12+
* @author Matt Bernhardt
13+
* @link https://github.com/MITLibraries/mitlib-wp-network/tree/master/web/app/mu-plugins/mitlib-security/
14+
*/
15+
16+
/**
17+
* MITlib Security is free software: you can redistribute it and/or modify
18+
* it under the terms of the GNU General Public License as published by
19+
* the Free Software Foundation, either version 2 of the License, or
20+
* any later version.
21+
*
22+
* MITlib Security is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with MITlib Security. If not, see {URI to Plugin License}.
29+
*/
30+
31+
namespace Mitlib\Security;
32+
33+
// Don't call the file directly!
34+
if ( ! defined( 'ABSPATH' ) ) {
35+
exit;
36+
}
37+
38+
/**
39+
* Additional_security_headers should be self-explanatory. It extends the
40+
* $headers array to include some additional security-related parameters that
41+
* are not included by default by Pantheon or WordPress.
42+
*
43+
* @param array $headers Associative array of headers to be sent.
44+
* @link https://docs.pantheon.io/guides/wordpress-developer/wordpress-best-practices#security-headers
45+
*/
46+
function additional_security_headers( $headers ) {
47+
$headers['Permissions-Policy'] = 'geolocation=(), microphone=(), camera=()';
48+
$headers['Referrer-Policy'] = 'no-referrer-when-downgrade';
49+
$headers['X-Content-Type-Options'] = 'nosniff';
50+
$headers['X-Frame-Options'] = 'SAMEORIGIN';
51+
52+
return $headers;
53+
}
54+
add_filter( 'wp_headers', 'Mitlib\Security\additional_security_headers' );

0 commit comments

Comments
 (0)