Fr3nch13/CakePHP Utilities

SecurityHeadersMiddleware
in package
implements MiddlewareInterface

Handles common security headers in a convenient way

Tags
link
https://book.cakephp.org/4/en/controllers/middleware.html#security-header-middleware

Table of Contents

Interfaces

MiddlewareInterface
Participant in processing a server request and response.

Constants

ALL  = 'all'
ALLOW_FROM  = 'allow-from'
BY_CONTENT_TYPE  = 'by-content-type'
BY_FTP_FILENAME  = 'by-ftp-filename'
DENY  = 'deny'
MASTER_ONLY  = 'master-only'
NO_REFERRER  = 'no-referrer'
NO_REFERRER_WHEN_DOWNGRADE  = 'no-referrer-when-downgrade'
NONE  = 'none'
NOOPEN  = 'noopen'
NOSNIFF  = 'nosniff'
ORIGIN  = 'origin'
ORIGIN_WHEN_CROSS_ORIGIN  = 'origin-when-cross-origin'
SAME_ORIGIN  = 'same-origin'
SAMEORIGIN  = 'sameorigin'
STRICT_ORIGIN  = 'strict-origin'
STRICT_ORIGIN_WHEN_CROSS_ORIGIN  = 'strict-origin-when-cross-origin'
UNSAFE_URL  = 'unsafe-url'
XSS_BLOCK  = 'block'
XSS_DISABLED  = '0'
XSS_ENABLED  = '1'
XSS_ENABLED_BLOCK  = '1; mode=block'

Properties

$headers  : array<string, mixed>
Security related headers to set

Methods

noOpen()  : $this
X-Download-Options
noSniff()  : $this
X-Content-Type-Options
process()  : ResponseInterface
Serve assets if the path matches one.
setCrossDomainPolicy()  : $this
X-Permitted-Cross-Domain-Policies
setReferrerPolicy()  : $this
Referrer-Policy
setXFrameOptions()  : $this
X-Frame-Options
setXssProtection()  : $this
X-XSS-Protection
checkValues()  : void
Convenience method to check if a value is in the list of allowed args

Constants

BY_CONTENT_TYPE

public string BY_CONTENT_TYPE = 'by-content-type'

X-Permitted-Cross-Domain-Policy by-content-type

BY_FTP_FILENAME

public string BY_FTP_FILENAME = 'by-ftp-filename'

X-Permitted-Cross-Domain-Policy by-ftp-filename

NO_REFERRER_WHEN_DOWNGRADE

public string NO_REFERRER_WHEN_DOWNGRADE = 'no-referrer-when-downgrade'

Referrer-Policy no-referrer-when-downgrade

ORIGIN_WHEN_CROSS_ORIGIN

public string ORIGIN_WHEN_CROSS_ORIGIN = 'origin-when-cross-origin'

Referrer-Policy origin-when-cross-origin

STRICT_ORIGIN_WHEN_CROSS_ORIGIN

public string STRICT_ORIGIN_WHEN_CROSS_ORIGIN = 'strict-origin-when-cross-origin'

Referrer-Policy strict-origin-when-cross-origin

Properties

Methods

setReferrerPolicy()

Referrer-Policy

public setReferrerPolicy([string $policy = self::SAME_ORIGIN ]) : $this
Parameters
$policy : string = self::SAME_ORIGIN

Policy value. Available Value: 'no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin', 'same-origin', 'strict-origin', 'strict-origin-when-cross-origin', 'unsafe-url'

Tags
link
https://w3c.github.io/webappsec-referrer-policy
Return values
$this

checkValues()

Convenience method to check if a value is in the list of allowed args

protected checkValues(string $value, array<string|int, string> $allowed) : void
Parameters
$value : string

Value to check

$allowed : array<string|int, string>

List of allowed values

Tags
throws
InvalidArgumentException

Thrown when a value is invalid.


        
On this page

Search results