1. Go to this page and download the library: Download altis/browser-security library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
altis / browser-security example snippets
// Setting hashes for scripts.
use Altis\Security\Browser;
wp_enqueue_script( 'my-handle', 'https://...' );
Browser\set_hash_for_script( 'my-handle', 'sha384-...' );
// Setting hashes for styles.
use Altis\Security\Browser;
wp_enqueue_style( 'my-handle', 'https://...' );
Browser\set_hash_for_style( 'my-handle', 'sha384-...' );
add_filter( 'altis.security.browser.content_security_policies', function ( array $policies ) : array {
// Policies can be set as strings.
$policies['object-src'] = 'none';
$policies['base-uri'] = 'self';
// Policies can also be set as arrays.
$policies['font-src'] = [
'https://fonts.gstatic.com',
'https://cdnjs.cloudflare.com',
];
// Special directives (such as `unsafe-inline`) are handled for you.
$policies['script-src'] = [
'https:',
'unsafe-inline',
];
return $policies;
} );
// You can filter specific keys via the filter name.
add_filter( 'altis.security.browser.filter_policy_value.font-src', function ( array $values ) : array {
$values[] = 'https://fonts.gstatic.com';
return $values;
} );
// A filter is also available with the directive name in a parameter.
add_filter( 'altis.security.browser.filter_policy_value', function ( array $values, string $name ) : array {
if ( $name === 'font-src' ) {
$values[] = 'https://cdnjs.cloudflare.com';
}
return $values;
} );