Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
ContentSecurity Class Reference

Creates a Content Security Policy object. More...

Public Member Functions

 __construct (?bool $reportOnly=null)
 ContentSecurity constructor.
 
 addPolicy (string $directive, string ... $values)
 Adds new values to a directive.
 
 removePolicy (string $directive, string ... $values)
 
 addPolicyDefault (string $directive, string ... $values)
 Adds new values to a directive, re-using default-src actual values.
 
 addNonce (string $nonce, string ... $directives)
 Adds a nonce to the directives.
 
 addHash (string $hash, string ... $directives)
 Adds a hash to the directives.
 
 addNonceDefault (string $nonce, string ... $directives)
 Adds a nonce to a directive, re-using default-src actual values.
 
 addHashDefault (string $hash, string ... $directives)
 Adds a hash to a directive, re-using default-src actual values.
 
 setDefaultSrc (string ... $policies)
 Defines the policies for default-src directive.
 
 generate ()
 Generates the header string.
 
 display (callable $directiveCall, callable $policyCall)
 Display a ContentSecurity object.
 
 reportOnly (?bool $reportOnly=true)
 Sets reportOnly.
 
 addHeaderToResponse (?bool $reportOnly=null)
 Adds headers to the response.
 
 getPolicies ()
 Returns the actual policies.
 

Static Public Member Functions

static nonce ($nonce, string ... $directives)
 Creates a nonce and add it to some directives.
 
static all ()
 Creates a new ContentSecurity object, with self in default-src.
 
static defaultUbiquity ()
 Creates a new ContentSecurity object for Ubiquity Webtools.
 
static defaultUbiquityDebug (string $livereloadServer='127.0.0.1:35729')
 Creates a new ContentSecurity object for Ubiquity Webtools in debug mode.
 

Data Fields

const HEADER = 'Content-Security-Policy'
 
const DEBUG_HEADER = 'Content-Security-Policy-Report-Only'
 

Private Attributes

array $policies = []
 
 $header = self::HEADER
 

Detailed Description

Creates a Content Security Policy object.

Ubiquity\security\csp$ContentSecurity This class is part of Ubiquity

Author
jc
Version
1.0.0

Definition at line 16 of file ContentSecurity.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ?bool  $reportOnly = null)

ContentSecurity constructor.

Parameters
bool | null$reportOnly

Definition at line 31 of file ContentSecurity.php.

Member Function Documentation

◆ addHash()

addHash ( string  $hash,
string ...  $directives 
)

Adds a hash to the directives.

Parameters
string$hash
string...$directives
Returns
$this

Definition at line 104 of file ContentSecurity.php.

◆ addHashDefault()

addHashDefault ( string  $hash,
string ...  $directives 
)

Adds a hash to a directive, re-using default-src actual values.

Parameters
string$hash
string...$directives
Returns
$this

Definition at line 132 of file ContentSecurity.php.

◆ addHeaderToResponse()

addHeaderToResponse ( ?bool  $reportOnly = null)

Adds headers to the response.

Parameters
bool | null$reportOnly

Definition at line 197 of file ContentSecurity.php.

◆ addNonce()

addNonce ( string  $nonce,
string ...  $directives 
)

Adds a nonce to the directives.

Parameters
string$nonce
string...$directives
Returns
$this

Definition at line 90 of file ContentSecurity.php.

◆ addNonceDefault()

addNonceDefault ( string  $nonce,
string ...  $directives 
)

Adds a nonce to a directive, re-using default-src actual values.

Parameters
string$nonce
string...$directives
Returns
$this

Definition at line 118 of file ContentSecurity.php.

◆ addPolicy()

addPolicy ( string  $directive,
string ...  $values 
)

Adds new values to a directive.

Parameters
string$directive
string...$values
Returns
$this

Definition at line 44 of file ContentSecurity.php.

◆ addPolicyDefault()

addPolicyDefault ( string  $directive,
string ...  $values 
)

Adds new values to a directive, re-using default-src actual values.

Parameters
string$directive
string...$values
Returns
$this

Definition at line 76 of file ContentSecurity.php.

◆ all()

static all ( )
static

Creates a new ContentSecurity object, with self in default-src.

Returns
ContentSecurity

Definition at line 222 of file ContentSecurity.php.

◆ defaultUbiquity()

static defaultUbiquity ( )
static

Creates a new ContentSecurity object for Ubiquity Webtools.

Returns
ContentSecurity

Definition at line 241 of file ContentSecurity.php.

◆ defaultUbiquityDebug()

static defaultUbiquityDebug ( string  $livereloadServer = '127.0.0.1:35729')
static

Creates a new ContentSecurity object for Ubiquity Webtools in debug mode.

Parameters
string$livereloadServer
Returns
ContentSecurity

Definition at line 254 of file ContentSecurity.php.

◆ display()

display ( callable  $directiveCall,
callable  $policyCall 
)

Display a ContentSecurity object.

Parameters
callable$directiveCall
callable$policyCall
Returns
string

Definition at line 170 of file ContentSecurity.php.

◆ generate()

generate ( )

Generates the header string.

Returns
string

Definition at line 154 of file ContentSecurity.php.

◆ getPolicies()

getPolicies ( )

Returns the actual policies.

Returns
array

Definition at line 232 of file ContentSecurity.php.

◆ nonce()

static nonce (   $nonce,
string ...  $directives 
)
static

Creates a nonce and add it to some directives.

Parameters
$nonce
string...$directives
Returns
ContentSecurity

Definition at line 212 of file ContentSecurity.php.

◆ removePolicy()

removePolicy ( string  $directive,
string ...  $values 
)

Definition at line 56 of file ContentSecurity.php.

◆ reportOnly()

reportOnly ( ?bool  $reportOnly = true)

Sets reportOnly.

Parameters
bool | null$reportOnly
Returns
$this

Definition at line 185 of file ContentSecurity.php.

◆ setDefaultSrc()

setDefaultSrc ( string ...  $policies)

Defines the policies for default-src directive.

Parameters
string...$policies
Returns
$this

Definition at line 145 of file ContentSecurity.php.

Field Documentation

◆ $header

$header = self::HEADER
private

Definition at line 24 of file ContentSecurity.php.

◆ $policies

array $policies = []
private

Definition at line 22 of file ContentSecurity.php.

◆ DEBUG_HEADER

const DEBUG_HEADER = 'Content-Security-Policy-Report-Only'

Definition at line 20 of file ContentSecurity.php.

◆ HEADER

const HEADER = 'Content-Security-Policy'

Definition at line 18 of file ContentSecurity.php.


The documentation for this class was generated from the following file: