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
36f6ebab
Commit
36f6ebab
authored
Jun 15, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #539: Yii2 Csrf protection broken
parent
5a8e4b64
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
10 deletions
+15
-10
CaptchaValidator.php
framework/yii/validators/CaptchaValidator.php
+3
-0
CaptchaAction.php
framework/yii/web/CaptchaAction.php
+1
-1
Request.php
framework/yii/web/Request.php
+11
-9
No files found.
framework/yii/validators/CaptchaValidator.php
View file @
36f6ebab
...
@@ -21,6 +21,9 @@ use yii\helpers\Html;
...
@@ -21,6 +21,9 @@ use yii\helpers\Html;
*/
*/
class
CaptchaValidator
extends
Validator
class
CaptchaValidator
extends
Validator
{
{
/**
* @var boolean whether to skip this validator if the input is empty.
*/
public
$skipOnEmpty
=
false
;
public
$skipOnEmpty
=
false
;
/**
/**
* @var boolean whether the comparison is case sensitive. Defaults to false.
* @var boolean whether the comparison is case sensitive. Defaults to false.
...
...
framework/yii/web/CaptchaAction.php
View file @
36f6ebab
...
@@ -173,7 +173,7 @@ class CaptchaAction extends Action
...
@@ -173,7 +173,7 @@ class CaptchaAction extends Action
{
{
$code
=
$this
->
getVerifyCode
();
$code
=
$this
->
getVerifyCode
();
$valid
=
$caseSensitive
?
(
$input
===
$code
)
:
strcasecmp
(
$input
,
$code
)
===
0
;
$valid
=
$caseSensitive
?
(
$input
===
$code
)
:
strcasecmp
(
$input
,
$code
)
===
0
;
$session
=
Yii
::
$app
->
session
;
$session
=
Yii
::
$app
->
getSession
()
;
$session
->
open
();
$session
->
open
();
$name
=
$this
->
getSessionKey
()
.
'count'
;
$name
=
$this
->
getSessionKey
()
.
'count'
;
$session
[
$name
]
=
$session
[
$name
]
+
1
;
$session
[
$name
]
=
$session
[
$name
]
+
1
;
...
...
framework/yii/web/Request.php
View file @
36f6ebab
...
@@ -27,7 +27,7 @@ class Request extends \yii\base\Request
...
@@ -27,7 +27,7 @@ class Request extends \yii\base\Request
* You may use [[\yii\web\Html::beginForm()]] to generate his hidden input.
* You may use [[\yii\web\Html::beginForm()]] to generate his hidden input.
* @see http://en.wikipedia.org/wiki/Cross-site_request_forgery
* @see http://en.wikipedia.org/wiki/Cross-site_request_forgery
*/
*/
public
$enableCsrfValidation
=
fals
e
;
public
$enableCsrfValidation
=
tru
e
;
/**
/**
* @var string the name of the token used to prevent CSRF. Defaults to 'YII_CSRF_TOKEN'.
* @var string the name of the token used to prevent CSRF. Defaults to 'YII_CSRF_TOKEN'.
* This property is effectively only when {@link enableCsrfValidation} is true.
* This property is effectively only when {@link enableCsrfValidation} is true.
...
@@ -771,7 +771,10 @@ class Request extends \yii\base\Request
...
@@ -771,7 +771,10 @@ class Request extends \yii\base\Request
$this
->
_cookieValidationKey
=
$value
;
$this
->
_cookieValidationKey
=
$value
;
}
}
private
$_csrfToken
;
/**
* @var Cookie
*/
private
$_csrfCookie
;
/**
/**
* Returns the random token used to perform CSRF validation.
* Returns the random token used to perform CSRF validation.
...
@@ -781,16 +784,15 @@ class Request extends \yii\base\Request
...
@@ -781,16 +784,15 @@ class Request extends \yii\base\Request
*/
*/
public
function
getCsrfToken
()
public
function
getCsrfToken
()
{
{
if
(
$this
->
_csrfToken
===
null
)
{
if
(
$this
->
_csrfCookie
===
null
)
{
$cookies
=
$this
->
getCookies
();
$this
->
_csrfCookie
=
$this
->
getCookies
()
->
get
(
$this
->
csrfTokenName
);
if
((
$this
->
_csrfToken
=
$cookies
->
getValue
(
$this
->
csrfTokenName
))
===
null
)
{
if
(
$this
->
_csrfCookie
===
null
)
{
$cookie
=
$this
->
createCsrfCookie
();
$this
->
_csrfCookie
=
$this
->
createCsrfCookie
();
$this
->
_csrfToken
=
$cookie
->
value
;
Yii
::
$app
->
getResponse
()
->
getCookies
()
->
add
(
$this
->
_csrfCookie
);
$cookies
->
add
(
$cookie
);
}
}
}
}
return
$this
->
_csrf
Token
;
return
$this
->
_csrf
Cookie
->
value
;
}
}
/**
/**
...
...
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