27 if (isset($_POST[$id])) {
56 $headers=
Startup::getHttpInstance ()->getAllHeaders ();
57 if(isset($headers[
'csrf-token'])){
58 list($id,$value)=explode(
':', $headers[
'csrf-token']);
59 return $id===CsrfManager::getSelector($name) && CsrfManager::isValidByName($name, $value);
70 return "<meta name='csrf-token' content='{$token->getId()}:{$token->getValue()}'>";
81 return "<input type='hidden' value='{$token->getValue()}' name='{$token->getId()}'>";
93 public static function addCookieToken(
string $name,
string $path =
'/',
bool $secure =
true,
bool $httpOnly =
true): bool {
95 return UCookie::set(self::COOKIE_KEY .
'[' . $token->getId() .
']', $token->getValue(),
null, $path, $secure, $httpOnly);
Ubiquity\security\csrf$CsrfManager This class is part of Ubiquity.
static isValid(string $id, string $value)
Returns whether the given CSRF token is valid, given his id.
Ubiquity\security\csrf$UCsrfHttp This class is part of Ubiquity.
static getTokenMeta(string $name)
Adds a token in headers.
static getTokenField(string $name)
Returns an input field with a generated token.
static isValidMeta(string $name)
Returns whether the given CSRF token is present and valid in header meta csrf-token,...
static addCookieToken(string $name, string $path='/', bool $secure=true, bool $httpOnly=true)
Adds a token in cookies.
static isValidPost(string $name)
Returns whether the given CSRF token is present and valid in POST values, given his name.
static isValidCookie(string $name)
Returns whether the given CSRF token is present and valid in cookies, given his name.
Http Cookies utilities Ubiquity\utils\http$UCookie This class is part of Ubiquity.
static get($name, $default=null)
Returns the Cookie with the name $name.