Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
4f555a57
Commit
4f555a57
authored
Sep 19, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed CSRF validation bug.
parent
f9b95755
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
Controller.php
framework/yii/web/Controller.php
+4
-1
Request.php
framework/yii/web/Request.php
+5
-6
No files found.
framework/yii/web/Controller.php
View file @
4f555a57
...
@@ -73,7 +73,10 @@ class Controller extends \yii\base\Controller
...
@@ -73,7 +73,10 @@ class Controller extends \yii\base\Controller
public
function
beforeAction
(
$action
)
public
function
beforeAction
(
$action
)
{
{
if
(
parent
::
beforeAction
(
$action
))
{
if
(
parent
::
beforeAction
(
$action
))
{
return
!
$this
->
enableCsrfValidation
||
Yii
::
$app
->
getRequest
()
->
validateCsrfToken
();
if
(
$this
->
enableCsrfValidation
&&
!
Yii
::
$app
->
getRequest
()
->
validateCsrfToken
())
{
throw
new
HttpException
(
400
,
Yii
::
t
(
'yii'
,
'Unable to verify your data submission.'
));
}
return
true
;
}
else
{
}
else
{
return
false
;
return
false
;
}
}
...
...
framework/yii/web/Request.php
View file @
4f555a57
...
@@ -1023,12 +1023,12 @@ class Request extends \yii\base\Request
...
@@ -1023,12 +1023,12 @@ class Request extends \yii\base\Request
* The method will compare the CSRF token obtained from a cookie and from a POST field.
* The method will compare the CSRF token obtained from a cookie and from a POST field.
* If they are different, a CSRF attack is detected and a 400 HTTP exception will be raised.
* If they are different, a CSRF attack is detected and a 400 HTTP exception will be raised.
* This method is called in [[Controller::beforeAction()]].
* This method is called in [[Controller::beforeAction()]].
* @
throws HttpException if the validation fails
* @
return boolean whether CSRF token is valid. If [[enableCsrfValidation]] is false, this method will return true.
*/
*/
public
function
validateCsrfToken
()
public
function
validateCsrfToken
()
{
{
if
(
!
$this
->
enableCsrfValidation
)
{
if
(
!
$this
->
enableCsrfValidation
)
{
return
;
return
true
;
}
}
$method
=
$this
->
getMethod
();
$method
=
$this
->
getMethod
();
if
(
$method
===
'POST'
||
$method
===
'PUT'
||
$method
===
'PATCH'
||
$method
===
'DELETE'
)
{
if
(
$method
===
'POST'
||
$method
===
'PUT'
||
$method
===
'PATCH'
||
$method
===
'DELETE'
)
{
...
@@ -1047,10 +1047,9 @@ class Request extends \yii\base\Request
...
@@ -1047,10 +1047,9 @@ class Request extends \yii\base\Request
$token
=
$this
->
getDelete
(
$this
->
csrfVar
);
$token
=
$this
->
getDelete
(
$this
->
csrfVar
);
}
}
$valid
=
!
empty
(
$token
)
&&
$token
===
$trueToken
||
$this
->
getCsrfTokenFromHeader
()
===
$trueToken
;
return
!
empty
(
$token
)
&&
$token
===
$trueToken
||
$this
->
getCsrfTokenFromHeader
()
===
$trueToken
;
if
(
!
$valid
)
{
}
else
{
throw
new
HttpException
(
400
,
Yii
::
t
(
'yii'
,
'Unable to verify your data submission.'
));
return
true
;
}
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment