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
a2262eaf
Commit
a2262eaf
authored
Feb 23, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix mvc sample (csrf protection was broken after a forward)
parent
f1bbc919
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
30 deletions
+29
-30
ControllerBase.php
...ense/mvc/app/controllers/OPNsense/Base/ControllerBase.php
+26
-26
IndexController.php
...c/app/controllers/OPNsense/Sample/Api/IndexController.php
+2
-2
index.volt
src/opnsense/mvc/app/views/OPNsense/Sample/index.volt
+1
-2
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Base/ControllerBase.php
View file @
a2262eaf
...
...
@@ -68,35 +68,35 @@ class ControllerBase extends Controller
*/
public
function
beforeExecuteRoute
(
$dispatcher
)
{
// Authentication
// - use authentication of legacy OPNsense.
if
(
$this
->
session
->
has
(
"Username"
)
==
false
)
{
$this
->
response
->
redirect
(
"/"
,
true
);
}
// check for valid csrf on post requests
if
(
$this
->
request
->
isPost
()
&&
!
$this
->
security
->
checkToken
())
{
// post without csrf, exit.
return
false
;
}
// only handle input validation on first request.
if
(
!
$dispatcher
->
wasForwarded
())
{
// Authentication
// - use authentication of legacy OPNsense.
if
(
$this
->
session
->
has
(
"Username"
)
==
false
)
{
$this
->
response
->
redirect
(
"/"
,
true
);
}
// check for valid csrf on post requests
if
(
$this
->
request
->
isPost
()
&&
!
$this
->
security
->
checkToken
())
{
// post without csrf, exit.
return
false
;
}
// REST type calls should be implemented by inheriting ApiControllerBase.
// because we don't check for csrf on these methods, we want to make sure these aren't used.
if
(
$this
->
request
->
isHead
()
||
$this
->
request
->
isPut
()
||
$this
->
request
->
isDelete
()
||
$this
->
request
->
isPatch
()
||
$this
->
request
->
isOptions
())
{
throw
new
\Exception
(
'request type not supported'
);
// REST type calls should be implemented by inheriting ApiControllerBase.
// because we don't check for csrf on these methods, we want to make sure these aren't used.
if
(
$this
->
request
->
isHead
()
||
$this
->
request
->
isPut
()
||
$this
->
request
->
isDelete
()
||
$this
->
request
->
isPatch
()
||
$this
->
request
->
isOptions
())
{
throw
new
\Exception
(
'request type not supported'
);
}
}
// include csrf for GET requests.
if
(
$this
->
request
->
isGet
())
{
// inject csrf information
$this
->
view
->
setVars
([
'csrf_tokenKey'
=>
$this
->
security
->
getTokenKey
(),
'csrf_token'
=>
$this
->
security
->
getToken
()
]);
}
// include csrf for volt view rendering.
$this
->
view
->
setVars
([
'csrf_tokenKey'
=>
$this
->
security
->
getTokenKey
(),
'csrf_token'
=>
$this
->
security
->
getToken
()
]);
// Execute before every found action
$this
->
view
->
setVar
(
'lang'
,
$this
->
getTranslator
());
...
...
src/opnsense/mvc/app/controllers/OPNsense/Sample/Api/IndexController.php
View file @
a2262eaf
...
...
@@ -41,8 +41,8 @@ class IndexController extends ApiControllerBase
*/
public
function
indexAction
()
{
if
(
$this
->
request
->
hasP
u
t
(
"message"
))
{
$message
=
$this
->
request
->
getP
u
t
(
"message"
);
if
(
$this
->
request
->
hasP
os
t
(
"message"
))
{
$message
=
$this
->
request
->
getP
os
t
(
"message"
);
}
else
{
$message
=
" "
;
}
...
...
src/opnsense/mvc/app/views/OPNsense/Sample/index.volt
View file @
a2262eaf
...
...
@@ -19,14 +19,13 @@ API call result : <div id="msgid"></div>
$( "#restcall" ).click( function() {
$.ajax({
type: "P
U
T",
type: "P
OS
T",
url: "/api/sample/",
success: function(data){
$("#msgid").html( data.message );
},
data:{message:$("#msg").val()}
});
});
</script>
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