Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
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\Context\getCurrent
static getCurrent()
Definition
context.php:241
Bitrix\Main\Engine\ActionFilter\Base
Definition
base.php:15
Bitrix\Main\Engine\ActionFilter\Base\addError
addError(Error $error)
Definition
base.php:80
Bitrix\Main\Engine\ActionFilter\Csrf
Definition
csrf.php:14
Bitrix\Main\Engine\ActionFilter\Csrf\onBeforeAction
onBeforeAction(Event $event)
Definition
csrf.php:57
Bitrix\Main\Engine\ActionFilter\Csrf\ERROR_INVALID_CSRF
const ERROR_INVALID_CSRF
Definition
csrf.php:16
Bitrix\Main\Engine\ActionFilter\Csrf\HEADER_WITH_NEW_CSRF
const HEADER_WITH_NEW_CSRF
Definition
csrf.php:15
Bitrix\Main\Engine\ActionFilter\Csrf\__construct
__construct(bool $enabled=true, string $tokenName='sessid', bool $returnNew=true)
Definition
csrf.php:38
Bitrix\Main\Engine\ActionFilter\Csrf\listAllowedScopes
listAllowedScopes()
Definition
csrf.php:50
Bitrix\Main\Engine\Controller
Definition
controller.php:32
Bitrix\Main\Engine\Controller\SCOPE_AJAX
const SCOPE_AJAX
Definition
controller.php:34
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Main\Context
Definition
culture.php:9
Bitrix\Main\Engine\ActionFilter
Definition
authentication.php:4
modules
main
lib
engine
actionfilter
csrf.php
Создано системой
1.10.0