Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Kulya
OpnSense
Commits
f20640d0
Commit
f20640d0
authored
Feb 02, 2017
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
csrf, switch from token per request to token per session. solves issues when using multiple tabs.
parent
895e30d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
19 deletions
+15
-19
ControllerBase.php
...ense/mvc/app/controllers/OPNsense/Base/ControllerBase.php
+4
-5
csrf.inc
src/www/csrf.inc
+11
-14
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Base/ControllerBase.php
View file @
f20640d0
...
...
@@ -177,7 +177,7 @@ class ControllerBase extends ControllerRoot
}
// check for valid csrf on post requests
if
(
$this
->
request
->
isPost
()
&&
!
$this
->
security
->
checkToken
())
{
if
(
$this
->
request
->
isPost
()
&&
!
$this
->
security
->
checkToken
(
null
,
null
,
false
))
{
// post without csrf, exit.
$this
->
response
->
setStatusCode
(
403
,
"Forbidden"
);
return
false
;
...
...
@@ -195,10 +195,9 @@ class ControllerBase extends ControllerRoot
}
// include csrf for volt view rendering.
$this
->
view
->
setVars
([
'csrf_tokenKey'
=>
$this
->
security
->
getTokenKey
(),
'csrf_token'
=>
$this
->
security
->
getToken
()
]);
$csrf_token
=
$this
->
session
->
get
(
'$PHALCON/CSRF$'
);
$csrf_tokenKey
=
$this
->
session
->
get
(
'$PHALCON/CSRF/KEY$'
);
$this
->
view
->
setVars
([
'csrf_tokenKey'
=>
$csrf_tokenKey
,
'csrf_token'
=>
$csrf_token
]);
// link menu system to view, append /ui in uri because of rewrite
$menu
=
new
Menu\MenuSystem
();
...
...
src/www/csrf.inc
View file @
f20640d0
...
...
@@ -28,8 +28,6 @@
class
LegacyCSRF
{
private
$securityToken
=
null
;
private
$securityTokenKey
=
null
;
private
$di
=
null
;
private
$security
=
null
;
private
$session
=
null
;
...
...
@@ -58,16 +56,13 @@ class LegacyCSRF
{
$result
=
false
;
// default, not valid
$this
->
Session
();
// do not destroy token after successfull validation, some pages use ajax type requests
$this
->
securityTokenKey
=
$_SESSION
[
'$PHALCON/CSRF/KEY$'
];
$this
->
securityToken
=
!
empty
(
$_POST
[
$this
->
securityTokenKey
])
?
$_POST
[
$this
->
securityTokenKey
]
:
""
;
if
(
empty
(
$this
->
securityToken
))
{
$securityTokenKey
=
$_SESSION
[
'$PHALCON/CSRF/KEY$'
];
if
(
empty
(
$_POST
[
$securityTokenKey
]))
{
if
(
!
empty
(
$_SERVER
[
'HTTP_X_CSRFTOKEN'
]))
{
$this
->
securityToken
=
$_SERVER
[
'HTTP_X_CSRFTOKEN'
];
$result
=
$this
->
security
->
checkToken
(
null
,
$this
->
securityToken
,
false
);
$result
=
$this
->
security
->
checkToken
(
null
,
$_SERVER
[
'HTTP_X_CSRFTOKEN'
],
false
);
}
}
else
{
$result
=
$this
->
security
->
checkToken
(
$
this
->
securityTokenKey
,
$this
->
securityToken
,
false
);
$result
=
$this
->
security
->
checkToken
(
$
securityTokenKey
,
$_POST
[
$securityTokenKey
]
,
false
);
}
// close session after validation
session_write_close
();
...
...
@@ -77,12 +72,14 @@ class LegacyCSRF
private
function
newToken
()
{
$this
->
Session
();
// only request new token when checkToken() hasn't saved one
if
(
$this
->
securityToken
==
null
)
{
$this
->
securityToken
=
$this
->
security
->
getToken
();
$this
->
securityTokenKey
=
$this
->
security
->
getTokenKey
();
// only request new token when session has none
$securityTokenKey
=
$_SESSION
[
'$PHALCON/CSRF/KEY$'
];
$securityToken
=
$_SESSION
[
'$PHALCON/CSRF$'
];
if
(
empty
(
$securityToken
)
||
empty
(
$securityTokenKey
))
{
$securityToken
=
$this
->
security
->
getToken
();
$securityTokenKey
=
$this
->
security
->
getTokenKey
();
}
return
array
(
'token'
=>
$
this
->
securityToken
,
'key'
=>
$this
->
securityTokenKey
);
return
array
(
'token'
=>
$
securityToken
,
'key'
=>
$
securityTokenKey
);
}
public
function
csrfRewriteHandler
(
$buffer
)
...
...
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