PHP Class ParagonIE\AntiCSRF\AntiCSRF

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . ****************************************************************************** The MIT License (MIT) Copyright (c) 2015 Paragon Initiative Enterprises Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. If you would like to use this library under different terms, please contact Resonant Core to inquire about a license exemption.
Datei anzeigen Open project: paragonie/anti-csrf Class Usage Examples

Public Properties

Property Type Description
$post Injected; defaults to references to superglobals
$server
$session

Protected Properties

Property Type Description
$expire_old boolean
$formIndex string
$formToken string
$hashAlgo string
$hmac_ip boolean
$recycle_after integer
$sessionIndex string

Public Methods

Method Description
__construct ( array &$post = null, array &$session = null, array &$server = null ) NULL is not a valid array type
getFormIndex ( ) : string
getFormToken ( ) : string
getSessionIndex ( ) : string
getTokenArray ( string $lockTo = '' ) : array Retrieve a token array for unit testing endpoints
insertToken ( string $lockTo = '', boolean $echo = true ) : string Insert a CSRF token to a form
reconfigure ( array $options = [] ) : self Use this to change the configuration settings.
validateRequest ( ) : boolean Validate a request based on $this->session and $this->post data

Protected Methods

Method Description
generateToken ( string $lockTo ) : array Generate, store, and return the index and token
noHTML ( string $untrusted ) : string Wrapper for htmlentities()
recycleTokens ( ) : self Enforce an upper limit on the number of tokens stored in session state by removing the oldest tokens first.

Method Details

__construct() public method

NULL is not a valid array type
public __construct ( array &$post = null, array &$session = null, array &$server = null )
$post array
$session array
$server array

generateToken() protected method

Generate, store, and return the index and token
protected generateToken ( string $lockTo ) : array
$lockTo string What URI endpoint this is valid for
return array

getFormIndex() public method

public getFormIndex ( ) : string
return string

getFormToken() public method

public getFormToken ( ) : string
return string

getSessionIndex() public method

public getSessionIndex ( ) : string
return string

getTokenArray() public method

Retrieve a token array for unit testing endpoints
public getTokenArray ( string $lockTo = '' ) : array
$lockTo string
return array

insertToken() public method

Insert a CSRF token to a form
public insertToken ( string $lockTo = '', boolean $echo = true ) : string
$lockTo string This CSRF token is only valid for this HTTP request endpoint
$echo boolean if true, echo instead of returning
return string

noHTML() protected static method

Wrapper for htmlentities()
protected static noHTML ( string $untrusted ) : string
$untrusted string
return string

reconfigure() public method

Only use this if you know what you are doing.
public reconfigure ( array $options = [] ) : self
$options array
return self

recycleTokens() protected method

Enforce an upper limit on the number of tokens stored in session state by removing the oldest tokens first.
protected recycleTokens ( ) : self
return self

validateRequest() public method

Validate a request based on $this->session and $this->post data
public validateRequest ( ) : boolean
return boolean

Property Details

$expire_old protected_oe property

protected bool $expire_old
return boolean

$formIndex protected_oe property

protected string $formIndex
return string

$formToken protected_oe property

protected string $formToken
return string

$hashAlgo protected_oe property

protected string $hashAlgo
return string

$hmac_ip protected_oe property

protected bool $hmac_ip
return boolean

$post public_oe property

Injected; defaults to references to superglobals
public $post

$recycle_after protected_oe property

protected int $recycle_after
return integer

$server public_oe property

public $server

$session public_oe property

public $session

$sessionIndex protected_oe property

protected string $sessionIndex
return string