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
dc644e69
Commit
dc644e69
authored
Feb 09, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2376 from dilip-vishwa/patch-2
Changed csrf-var to csrf-param
parents
23f8988b
aa669fab
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
15 deletions
+16
-15
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
yii.js
framework/assets/yii.js
+6
-6
BaseHtml.php
framework/helpers/BaseHtml.php
+1
-1
Request.php
framework/web/Request.php
+7
-7
View.php
framework/web/View.php
+1
-1
No files found.
framework/CHANGELOG.md
View file @
dc644e69
...
@@ -165,6 +165,7 @@ Yii Framework 2 Change Log
...
@@ -165,6 +165,7 @@ Yii Framework 2 Change Log
-
Chg: Removed implementation of
`Arrayable`
from
`yii\Object`
(qiangxue)
-
Chg: Removed implementation of
`Arrayable`
from
`yii\Object`
(qiangxue)
-
Chg: Renamed
`ActiveRecordInterface::createActiveRelation()`
to
`createRelation()`
(qiangxue)
-
Chg: Renamed
`ActiveRecordInterface::createActiveRelation()`
to
`createRelation()`
(qiangxue)
-
Chg: The scripts in asset bundles are now registered in
`View`
at the end of
`endBody()`
. It was done in
`endPage()`
previously (qiangxue)
-
Chg: The scripts in asset bundles are now registered in
`View`
at the end of
`endBody()`
. It was done in
`endPage()`
previously (qiangxue)
-
Chg: Renamed
`csrf-var`
to
`csrf-param`
as
`csrf-var`
is not a valid meta tag name (Dilip)
-
New #66:
[
Auth client library
](
https://github.com/yiisoft/yii2-authclient
)
OpenId, OAuth1, OAuth2 clients (klimov-paul)
-
New #66:
[
Auth client library
](
https://github.com/yiisoft/yii2-authclient
)
OpenId, OAuth1, OAuth2 clients (klimov-paul)
-
New #706: Added
`yii\widgets\Pjax`
and enhanced
`GridView`
to work with
`Pjax`
to support AJAX-update (qiangxue)
-
New #706: Added
`yii\widgets\Pjax`
and enhanced
`GridView`
to work with
`Pjax`
to support AJAX-update (qiangxue)
-
New #1393:
[
Codeception testing framework integration
](
https://github.com/yiisoft/yii2-codeception
)
(
Ragazzo
)
-
New #1393:
[
Codeception testing framework integration
](
https://github.com/yiisoft/yii2-codeception
)
(
Ragazzo
)
...
...
framework/assets/yii.js
View file @
dc644e69
...
@@ -60,8 +60,8 @@ yii = (function ($) {
...
@@ -60,8 +60,8 @@ yii = (function ($) {
/**
/**
* @return string|undefined the CSRF variable name. Undefined is returned if CSRF validation is not enabled.
* @return string|undefined the CSRF variable name. Undefined is returned if CSRF validation is not enabled.
*/
*/
getCsrf
Var
:
function
()
{
getCsrf
Param
:
function
()
{
return
$
(
'meta[name=csrf-
var
]'
).
prop
(
'content'
);
return
$
(
'meta[name=csrf-
param
]'
).
prop
(
'content'
);
},
},
/**
/**
...
@@ -130,9 +130,9 @@ yii = (function ($) {
...
@@ -130,9 +130,9 @@ yii = (function ($) {
if
(
!
method
.
match
(
/
(
get|post
)
/i
))
{
if
(
!
method
.
match
(
/
(
get|post
)
/i
))
{
$form
.
append
(
'<input name="_method" value="'
+
method
+
'" type="hidden">'
);
$form
.
append
(
'<input name="_method" value="'
+
method
+
'" type="hidden">'
);
}
}
var
csrf
Var
=
pub
.
getCsrfVar
();
var
csrf
Param
=
pub
.
getCsrfParam
();
if
(
csrf
Var
)
{
if
(
csrf
Param
)
{
$form
.
append
(
'<input name="'
+
csrf
Var
+
'" value="'
+
pub
.
getCsrfToken
()
+
'" type="hidden">'
);
$form
.
append
(
'<input name="'
+
csrf
Param
+
'" value="'
+
pub
.
getCsrfToken
()
+
'" type="hidden">'
);
}
}
$form
.
hide
().
appendTo
(
'body'
);
$form
.
hide
().
appendTo
(
'body'
);
}
}
...
@@ -199,7 +199,7 @@ yii = (function ($) {
...
@@ -199,7 +199,7 @@ yii = (function ($) {
function
initCsrfHandler
()
{
function
initCsrfHandler
()
{
// automatically send CSRF token for all AJAX requests
// automatically send CSRF token for all AJAX requests
$
.
ajaxPrefilter
(
function
(
options
,
originalOptions
,
xhr
)
{
$
.
ajaxPrefilter
(
function
(
options
,
originalOptions
,
xhr
)
{
if
(
!
options
.
crossDomain
&&
pub
.
getCsrf
Var
())
{
if
(
!
options
.
crossDomain
&&
pub
.
getCsrf
Param
())
{
xhr
.
setRequestHeader
(
'X-CSRF-Token'
,
pub
.
getCsrfToken
());
xhr
.
setRequestHeader
(
'X-CSRF-Token'
,
pub
.
getCsrfToken
());
}
}
});
});
...
...
framework/helpers/BaseHtml.php
View file @
dc644e69
...
@@ -244,7 +244,7 @@ class BaseHtml
...
@@ -244,7 +244,7 @@ class BaseHtml
$method
=
'post'
;
$method
=
'post'
;
}
}
if
(
$request
->
enableCsrfValidation
&&
!
strcasecmp
(
$method
,
'post'
))
{
if
(
$request
->
enableCsrfValidation
&&
!
strcasecmp
(
$method
,
'post'
))
{
$hiddenInputs
[]
=
static
::
hiddenInput
(
$request
->
csrf
Var
,
$request
->
getCsrfToken
());
$hiddenInputs
[]
=
static
::
hiddenInput
(
$request
->
csrf
Param
,
$request
->
getCsrfToken
());
}
}
}
}
...
...
framework/web/Request.php
View file @
dc644e69
...
@@ -95,10 +95,10 @@ class Request extends \yii\base\Request
...
@@ -95,10 +95,10 @@ class Request extends \yii\base\Request
* from the same application. If not, a 400 HTTP exception will be raised.
* from the same application. If not, a 400 HTTP exception will be raised.
*
*
* Note, this feature requires that the user client accepts cookie. Also, to use this feature,
* Note, this feature requires that the user client accepts cookie. Also, to use this feature,
* forms submitted via POST method must contain a hidden input whose name is specified by [[csrf
Var
]].
* forms submitted via POST method must contain a hidden input whose name is specified by [[csrf
Param
]].
* You may use [[\yii\web\Html::beginForm()]] to generate his hidden input.
* You may use [[\yii\web\Html::beginForm()]] to generate his hidden input.
*
*
* In JavaScript, you may get the values of [[csrf
Var]] and [[csrfToken]] via `yii.getCsrfVar
()` and
* In JavaScript, you may get the values of [[csrf
Param]] and [[csrfToken]] via `yii.getCsrfParam
()` and
* `yii.getCsrfToken()`, respectively. The [[\yii\web\YiiAsset]] asset must be registered.
* `yii.getCsrfToken()`, respectively. The [[\yii\web\YiiAsset]] asset must be registered.
*
*
* @see Controller::enableCsrfValidation
* @see Controller::enableCsrfValidation
...
@@ -109,7 +109,7 @@ class Request extends \yii\base\Request
...
@@ -109,7 +109,7 @@ class Request extends \yii\base\Request
* @var string the name of the token used to prevent CSRF. Defaults to '_csrf'.
* @var string the name of the token used to prevent CSRF. Defaults to '_csrf'.
* This property is used only when [[enableCsrfValidation]] is true.
* This property is used only when [[enableCsrfValidation]] is true.
*/
*/
public
$csrf
Var
=
'_csrf'
;
public
$csrf
Param
=
'_csrf'
;
/**
/**
* @var array the configuration of the CSRF cookie. This property is used only when [[enableCsrfValidation]] is true.
* @var array the configuration of the CSRF cookie. This property is used only when [[enableCsrfValidation]] is true.
* @see Cookie
* @see Cookie
...
@@ -1103,7 +1103,7 @@ class Request extends \yii\base\Request
...
@@ -1103,7 +1103,7 @@ class Request extends \yii\base\Request
public
function
getRawCsrfToken
()
public
function
getRawCsrfToken
()
{
{
if
(
$this
->
_csrfCookie
===
null
)
{
if
(
$this
->
_csrfCookie
===
null
)
{
$this
->
_csrfCookie
=
$this
->
getCookies
()
->
get
(
$this
->
csrf
Var
);
$this
->
_csrfCookie
=
$this
->
getCookies
()
->
get
(
$this
->
csrf
Param
);
if
(
$this
->
_csrfCookie
===
null
)
{
if
(
$this
->
_csrfCookie
===
null
)
{
$this
->
_csrfCookie
=
$this
->
createCsrfCookie
();
$this
->
_csrfCookie
=
$this
->
createCsrfCookie
();
Yii
::
$app
->
getResponse
()
->
getCookies
()
->
add
(
$this
->
_csrfCookie
);
Yii
::
$app
->
getResponse
()
->
getCookies
()
->
add
(
$this
->
_csrfCookie
);
...
@@ -1175,7 +1175,7 @@ class Request extends \yii\base\Request
...
@@ -1175,7 +1175,7 @@ class Request extends \yii\base\Request
protected
function
createCsrfCookie
()
protected
function
createCsrfCookie
()
{
{
$options
=
$this
->
csrfCookie
;
$options
=
$this
->
csrfCookie
;
$options
[
'name'
]
=
$this
->
csrf
Var
;
$options
[
'name'
]
=
$this
->
csrf
Param
;
$options
[
'value'
]
=
Security
::
generateRandomKey
();
$options
[
'value'
]
=
Security
::
generateRandomKey
();
return
new
Cookie
(
$options
);
return
new
Cookie
(
$options
);
}
}
...
@@ -1194,8 +1194,8 @@ class Request extends \yii\base\Request
...
@@ -1194,8 +1194,8 @@ class Request extends \yii\base\Request
if
(
!
$this
->
enableCsrfValidation
||
in_array
(
$method
,
[
'GET'
,
'HEAD'
,
'OPTIONS'
],
true
))
{
if
(
!
$this
->
enableCsrfValidation
||
in_array
(
$method
,
[
'GET'
,
'HEAD'
,
'OPTIONS'
],
true
))
{
return
true
;
return
true
;
}
}
$trueToken
=
$this
->
getCookies
()
->
getValue
(
$this
->
csrf
Var
);
$trueToken
=
$this
->
getCookies
()
->
getValue
(
$this
->
csrf
Param
);
$token
=
$this
->
getBodyParam
(
$this
->
csrf
Var
);
$token
=
$this
->
getBodyParam
(
$this
->
csrf
Param
);
return
$this
->
validateCsrfTokenInternal
(
$token
,
$trueToken
)
return
$this
->
validateCsrfTokenInternal
(
$token
,
$trueToken
)
||
$this
->
validateCsrfTokenInternal
(
$this
->
getCsrfTokenFromHeader
(),
$trueToken
);
||
$this
->
validateCsrfTokenInternal
(
$this
->
getCsrfTokenFromHeader
(),
$trueToken
);
}
}
...
...
framework/web/View.php
View file @
dc644e69
...
@@ -454,7 +454,7 @@ class View extends \yii\base\View
...
@@ -454,7 +454,7 @@ class View extends \yii\base\View
$request
=
Yii
::
$app
->
getRequest
();
$request
=
Yii
::
$app
->
getRequest
();
if
(
$request
instanceof
\yii\web\Request
&&
$request
->
enableCsrfValidation
&&
!
$request
->
getIsAjax
())
{
if
(
$request
instanceof
\yii\web\Request
&&
$request
->
enableCsrfValidation
&&
!
$request
->
getIsAjax
())
{
$lines
[]
=
Html
::
tag
(
'meta'
,
''
,
[
'name'
=>
'csrf-
var
'
,
'content'
=>
$request
->
csrfVar
]);
$lines
[]
=
Html
::
tag
(
'meta'
,
''
,
[
'name'
=>
'csrf-
param
'
,
'content'
=>
$request
->
csrfVar
]);
$lines
[]
=
Html
::
tag
(
'meta'
,
''
,
[
'name'
=>
'csrf-token'
,
'content'
=>
$request
->
getCsrfToken
()]);
$lines
[]
=
Html
::
tag
(
'meta'
,
''
,
[
'name'
=>
'csrf-token'
,
'content'
=>
$request
->
getCsrfToken
()]);
}
}
...
...
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