PHP 클래스 ParagonIE\CSPBuilder\CSPBuilder

파일 보기 프로젝트 열기: paragonie/csp-builder 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$supportOldBrowsers boolean

공개 메소드들

메소드 설명
__construct ( array $policy = [] )
addDirective ( string $key, mixed $value = null ) : self Add a directive if it doesn't already exist
addSource ( string $directive, string $path ) : self Add a source to our allow white-list
allowPluginType ( string $mime = 'text/plain' ) : self Add a plugin type to be added
compile ( ) : string Compile the current policies into a CSP header
disableOldBrowserSupport ( ) : self Disable old browser support (e.g. Safari)
enableOldBrowserSupport ( ) : self Enable old browser support (e.g. Safari)
fromData ( string $data = '' ) : self Factory method - create a new CSPBuilder object from a JSON data
fromFile ( string $filename = '' ) : self Factory method - create a new CSPBuilder object from a JSON file
getCompiledHeader ( ) : string Get the formatted CSP header
getHeaderArray ( boolean $legacy = true ) : array Get an associative array of headers to return.
hash ( string $directive = 'script-src', string $script = '', string $algorithm = 'sha384' ) : self Add a new hash to the existing CSP
injectCSPHeader ( Psr\Http\Message\MessageInterface $message, boolean $legacy = false ) : Psr\Http\Message\MessageInterface PSR-7 header injection
nonce ( string $directive = 'script-src', string $nonce = '' ) : string Add a new nonce to the existing CSP
preHash ( string $directive = 'script-src', string $hash = '', string $algorithm = 'sha384' ) : self Add a new (pre-calculated) base64-encoded hash to the existing CSP
saveSnippet ( string $outputFile, string $format = self::FORMAT_NGINX ) : boolean Save CSP to a snippet file
sendCSPHeader ( boolean $legacy = true ) : boolean Send the compiled CSP as a header()
setDirective ( string $key, mixed $value = null ) : self Set a directive

보호된 메소드들

메소드 설명
compileSubgroup ( string $directive, mixed $policies = null ) : string Compile a subgroup into a policy string
getHeaderKeys ( boolean $legacy = true ) : array Get an array of header keys to return
isHTTPSConnection ( ) : boolean Is this user currently connected over HTTPS?

메소드 상세

__construct() 공개 메소드

public __construct ( array $policy = [] )
$policy array

addDirective() 공개 메소드

If it already exists, do nothing
public addDirective ( string $key, mixed $value = null ) : self
$key string
$value mixed
리턴 self

addSource() 공개 메소드

Add a source to our allow white-list
public addSource ( string $directive, string $path ) : self
$directive string
$path string
리턴 self

allowPluginType() 공개 메소드

Add a plugin type to be added
public allowPluginType ( string $mime = 'text/plain' ) : self
$mime string
리턴 self

compile() 공개 메소드

Compile the current policies into a CSP header
public compile ( ) : string
리턴 string

compileSubgroup() 보호된 메소드

Compile a subgroup into a policy string
protected compileSubgroup ( string $directive, mixed $policies = null ) : string
$directive string
$policies mixed
리턴 string

disableOldBrowserSupport() 공개 메소드

Disable old browser support (e.g. Safari)
public disableOldBrowserSupport ( ) : self
리턴 self

enableOldBrowserSupport() 공개 메소드

This is enabled by default
public enableOldBrowserSupport ( ) : self
리턴 self

fromData() 공개 정적인 메소드

Factory method - create a new CSPBuilder object from a JSON data
public static fromData ( string $data = '' ) : self
$data string
리턴 self

fromFile() 공개 정적인 메소드

Factory method - create a new CSPBuilder object from a JSON file
public static fromFile ( string $filename = '' ) : self
$filename string
리턴 self

getCompiledHeader() 공개 메소드

Get the formatted CSP header
public getCompiledHeader ( ) : string
리턴 string

getHeaderArray() 공개 메소드

Get an associative array of headers to return.
public getHeaderArray ( boolean $legacy = true ) : array
$legacy boolean
리턴 array

getHeaderKeys() 보호된 메소드

Get an array of header keys to return
protected getHeaderKeys ( boolean $legacy = true ) : array
$legacy boolean
리턴 array

hash() 공개 메소드

Add a new hash to the existing CSP
public hash ( string $directive = 'script-src', string $script = '', string $algorithm = 'sha384' ) : self
$directive string
$script string
$algorithm string
리턴 self

injectCSPHeader() 공개 메소드

PSR-7 header injection
public injectCSPHeader ( Psr\Http\Message\MessageInterface $message, boolean $legacy = false ) : Psr\Http\Message\MessageInterface
$message Psr\Http\Message\MessageInterface
$legacy boolean
리턴 Psr\Http\Message\MessageInterface

isHTTPSConnection() 보호된 메소드

Is this user currently connected over HTTPS?
protected isHTTPSConnection ( ) : boolean
리턴 boolean

nonce() 공개 메소드

Add a new nonce to the existing CSP
public nonce ( string $directive = 'script-src', string $nonce = '' ) : string
$directive string
$nonce string (if empty, it will be generated)
리턴 string

preHash() 공개 메소드

Add a new (pre-calculated) base64-encoded hash to the existing CSP
public preHash ( string $directive = 'script-src', string $hash = '', string $algorithm = 'sha384' ) : self
$directive string
$hash string
$algorithm string
리턴 self

saveSnippet() 공개 메소드

Save CSP to a snippet file
public saveSnippet ( string $outputFile, string $format = self::FORMAT_NGINX ) : boolean
$outputFile string Output file name
$format string Which format are we saving in?
리턴 boolean

sendCSPHeader() 공개 메소드

Send the compiled CSP as a header()
public sendCSPHeader ( boolean $legacy = true ) : boolean
$legacy boolean Send legacy headers?
리턴 boolean

setDirective() 공개 메소드

Set a directive
public setDirective ( string $key, mixed $value = null ) : self
$key string
$value mixed
리턴 self

프로퍼티 상세

$supportOldBrowsers 보호되어 있는 프로퍼티

protected bool $supportOldBrowsers
리턴 boolean