1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
csrf.php
См. документацию.
1
<?php
2
3
4
namespace
Bitrix\Main\Engine\ActionFilter;
5
6
7
use Bitrix\Main\Context;
8
use Bitrix\Main\Engine\Controller;
9
use Bitrix\Main\Error;
10
use Bitrix\Main\Event;
11
use Bitrix\Main\EventResult;
12
13
final
class
Csrf
extends
Base
14
{
15
public
const
HEADER_WITH_NEW_CSRF
=
'X-Bitrix-New-Csrf'
;
16
public
const
ERROR_INVALID_CSRF
=
'invalid_csrf'
;
17
21
private
$enabled;
25
private
$tokenName;
29
private
$returnNew;
30
38
public
function
__construct
(
bool
$enabled =
true
,
string
$tokenName =
'sessid'
,
bool
$returnNew =
true
)
39
{
40
$this->enabled = $enabled;
41
$this->tokenName = $tokenName;
42
$this->returnNew = $returnNew;
43
parent::__construct();
44
}
45
50
public
function
listAllowedScopes
()
51
{
52
return
[
53
Controller::SCOPE_AJAX,
54
];
55
}
56
57
public
function
onBeforeAction
(
Event
$event
)
58
{
59
if
(!$this->enabled)
60
{
61
return
null
;
62
}
63
64
if
(!
check_bitrix_sessid
($this->tokenName))
65
{
66
$errorCustomData = [];
67
if
($this->returnNew)
68
{
69
$errorCustomData[
'csrf'
] =
bitrix_sessid
();
70
Context::getCurrent()->getResponse()->addHeader(
71
self::HEADER_WITH_NEW_CSRF, $errorCustomData[
'csrf'
]
72
);
73
}
74
75
$this->
addError
(
new
Error
(
76
'Invalid csrf token'
,
77
self::ERROR_INVALID_CSRF, $errorCustomData
78
));
79
80
return
new
EventResult
(EventResult::ERROR,
null
,
null
, $this);
81
}
82
83
return
null
;
84
}
85
}
Bitrix\Main\Engine\ActionFilter\Base
Определения
base.php:15
Bitrix\Main\Engine\ActionFilter\Base\addError
addError(Error $error)
Определения
base.php:80
Bitrix\Main\Engine\ActionFilter\Csrf
Определения
csrf.php:14
Bitrix\Main\Engine\ActionFilter\Csrf\onBeforeAction
onBeforeAction(Event $event)
Определения
csrf.php:57
Bitrix\Main\Engine\ActionFilter\Csrf\ERROR_INVALID_CSRF
const ERROR_INVALID_CSRF
Определения
csrf.php:16
Bitrix\Main\Engine\ActionFilter\Csrf\HEADER_WITH_NEW_CSRF
const HEADER_WITH_NEW_CSRF
Определения
csrf.php:15
Bitrix\Main\Engine\ActionFilter\Csrf\__construct
__construct(bool $enabled=true, string $tokenName='sessid', bool $returnNew=true)
Определения
csrf.php:38
Bitrix\Main\Engine\ActionFilter\Csrf\listAllowedScopes
listAllowedScopes()
Определения
csrf.php:50
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\Event
Определения
event.php:5
Bitrix\Main\EventResult
Определения
eventresult.php:5
check_bitrix_sessid
check_bitrix_sessid($varname='sessid')
Определения
tools.php:4686
bitrix_sessid
bitrix_sessid()
Определения
tools.php:4656
$event
$event
Определения
prolog_after.php:141
bitrix
modules
main
lib
engine
actionfilter
csrf.php
Создано системой
1.14.0