Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
da81b71f
Unverified
Commit
da81b71f
authored
5 years ago
by
Roeland Jago Douma
Browse files
Options
Downloads
Patches
Plain Diff
Only allow requesting new CSRF tokens if it passes the SameSite Cookie test
Signed-off-by:
Roeland Jago Douma
<
roeland@famdouma.nl
>
parent
7976cb7e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/Controller/CSRFTokenController.php
+5
-0
5 additions, 0 deletions
core/Controller/CSRFTokenController.php
tests/Core/Controller/CSRFTokenControllerTest.php
+12
-1
12 additions, 1 deletion
tests/Core/Controller/CSRFTokenControllerTest.php
with
17 additions
and
1 deletion
core/Controller/CSRFTokenController.php
+
5
−
0
View file @
da81b71f
...
...
@@ -28,6 +28,7 @@ namespace OC\Core\Controller;
use
OC\Security\CSRF\CsrfTokenManager
;
use
OCP\AppFramework\Controller
;
use
OCP\AppFramework\Http
;
use
OCP\AppFramework\Http\JSONResponse
;
use
OCP\IRequest
;
...
...
@@ -54,6 +55,10 @@ class CSRFTokenController extends Controller {
* @return JSONResponse
*/
public
function
index
():
JSONResponse
{
if
(
!
$this
->
request
->
passesStrictCookieCheck
())
{
return
new
JSONResponse
([],
Http
::
STATUS_FORBIDDEN
);
}
$requestToken
=
$this
->
tokenManager
->
getToken
();
return
new
JSONResponse
([
...
...
This diff is collapsed.
Click to expand it.
tests/Core/Controller/CSRFTokenControllerTest.php
+
12
−
1
View file @
da81b71f
...
...
@@ -54,7 +54,9 @@ class CSRFTokenControllerTest extends TestCase {
$this
->
tokenManager
);
}
public
function
testGetToken
()
{
public
function
testGetToken
():
void
{
$this
->
request
->
method
(
'passesStrictCookieCheck'
)
->
willReturn
(
true
);
$token
=
$this
->
createMock
(
CsrfToken
::
class
);
$this
->
tokenManager
->
method
(
'getToken'
)
->
willReturn
(
$token
);
$token
->
method
(
'getEncryptedValue'
)
->
willReturn
(
'toktok123'
);
...
...
@@ -68,4 +70,13 @@ class CSRFTokenControllerTest extends TestCase {
],
$response
->
getData
());
}
public
function
testGetTokenNoStrictSameSiteCookie
():
void
{
$this
->
request
->
method
(
'passesStrictCookieCheck'
)
->
willReturn
(
false
);
$response
=
$this
->
controller
->
index
();
$this
->
assertInstanceOf
(
JSONResponse
::
class
,
$response
);
$this
->
assertSame
(
Http
::
STATUS_FORBIDDEN
,
$response
->
getStatus
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment