PHP code example of hyperia / yii2-secure-headers

1. Go to this page and download the library: Download hyperia/yii2-secure-headers 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/ */

    

hyperia / yii2-secure-headers example snippets


'bootstrap'  => [..., 'headers'],
'components' => [
    ...
    'headers' => [
        'class' => '\hyperia\security\Headers',
        'upgradeInsecureRequests' => true,
        'blockAllMixedContent' => true,
        '
            'preload' => false
        ],
        'xFrameOptions' => 'DENY',
        'xPoweredBy' => 'Hyperia',
        'referrerPolicy' => 'no-referrer',
        'reportOnlyMode' => false
        'reportUri' => 'https://company.report-uri.com/r/d/csp/enforce',
        'reportTo' => [
            [
                'group' => 'groupName',
                'max_age' => 10886400,
                'endpoints' => [
                    [
                        'name' => 'endpointName',
                        'url' => 'https://example.com',
                        'failures' => 1
                    ]
                ]
            ]
        ]
        'cspDirectives' => [
            'connect-src' => "'self'",
            'font-src' => "'self'",
            'frame-src' => "'self'",
            'img-src' => "'self' data:",
            'manifest-src' => "'self'",
            'object-src' => "'self'",
            'prefetch-src' => false,
            'script-src' => "'self' 'unsafe-inline'",
            'style-src' => "'self' 'unsafe-inline'",
            'media-src' => "'self'",
            'form-action' => "'self'",
            'worker-src' => "'self'",
            'report-to' => 'groupname'
        ],
        // Deprecated. Use Permissions Policy instead.
        'featurePolicyDirectives' => [
            'accelerometer' => "'self'",
            'ambient-light-sensor' => "'self'",
            'autoplay' => "'self'",
            'battery' => "'self'",
            'camera' => "'self'",
            'display-capture' => "'self'",
            'document-domain' => "'self'",
            'encrypted-media' => "'self'",
            'fullscreen' => "'self'",
            'geolocation' => "'self'",
            'gyroscope' => "'self'",
            'layout-animations' => "'self'",
            'magnetometer' => "'self'",
            'microphone' => "'self'",
            'midi' => "'self'",
            'oversized-images' => "'self'",
            'payment' => "'self'",
            'picture-in-picture' => "*",
            'publickey-credentials-get' => "'self'",
            'sync-xhr' => "'self'",
            'usb' => "'self'",
            'wake-lock' => "'self'",
            'xr-spatial-tracking' => "'self'"
        ],
        'permissionsPolicyDirectives' => [
            'accelerometer' => "self",
            'ambient-light-sensor' => "self",
            'autoplay' => "self",
            'battery' => "self",
            'camera' => "self",
            'display-capture' => "self",
            'document-domain' => "self",
            'encrypted-media' => "self",
            'fullscreen' => "self",
            'geolocation' => "self",
            'gyroscope' => "self",
            'layout-animations' => "self",
            'magnetometer' => "self",
            'microphone' => "self",
            'midi' => "self",
            'oversized-images' => "self",
            'payment' => "self",
            'picture-in-picture' => "*",
            'publickey-credentials-get' => "self",
            'sync-xhr' => "self",
            'usb' => "self",
            'wake-lock' => "self",
            'xr-spatial-tracking' => "self"
        ]
    ]
]