PHP Class lithium\template\helper\Security

See also: lithium\security\validation\RequestToken
Inheritance: extends lithium\template\Helper
Datei anzeigen Open project: unionofrad/lithium Class Usage Examples

Protected Properties

Property Type Description
$_classes
$_state

Public Methods

Method Description
__construct ( array $config = [] ) : void Constructor. Configures the helper with the default settings for interacting with security tokens.
requestToken ( array $options = [] ) : string Generates a request key used to protect your forms against CSRF attacks. See the RequestToken class for examples and proper usage.
sign ( object $form = null ) : void Binds the Security helper to the Form helper to create a signature used to secure form fields against tampering.

Method Details

__construct() public method

Constructor. Configures the helper with the default settings for interacting with security tokens.
public __construct ( array $config = [] ) : void
$config array
return void

requestToken() public method

Generates a request key used to protect your forms against CSRF attacks. See the RequestToken class for examples and proper usage.
See also: lithium\security\validation\RequestToken
public requestToken ( array $options = [] ) : string
$options array Options used as HTML when generating the field.
return string Returns a hidden `` field containing a request-specific CSRF token key.

sign() public method

First FormSignature must be provided with a secret unique to your app. This is best done in the bootstrap process. The secret key should be a random lengthy string. php use lithium\security\validation\FormSignature; FormSignature::config(array('secret' => 'a long secret key')); In the view call the sign() method before creating the form. php security->sign(); ?> form->create(...); ?> Form fields... form->end(); ?> In the corresponding controller action verify the signature. php if ($this->request->is('post') && !FormSignature::check($this->request)) { The key didn't match, meaning the request has been tampered with. } Calling this method before a form is created adds two additional options to the $options parameter in all form inputs: - 'locked' _boolean_: If true, _locks_ the value specified in the field when the field is generated, such that tampering with the value will invalidate the signature. Defaults to true for hidden fields, and false for all other form inputs. - 'exclude' _boolean_: If true, this field and all subfields of the same name will be excluded from the signature calculation. This is useful in situations where fields may be added dynamically on the client side. Defaults to false.
See also: lithium\template\helper\Form
See also: lithium\security\validation\FormSignature
public sign ( object $form = null ) : void
$form object Optional. Allows specifying an instance of the `Form` helper manually.
return void

Property Details

$_classes protected_oe property

protected $_classes

$_state protected_oe property

protected $_state