Skip to content

Commit 3398ae0

Browse files
phil-davisDeepDiver1975
authored andcommitted
Merge pull request #40856 from owncloud/fix/header-evaluation
fix: use empty() to check if header exists
1 parent 2d6c6bf commit 3398ae0

File tree

6 files changed

+712
-45
lines changed

6 files changed

+712
-45
lines changed

apps/files_sharing/lib/Controller/Share20OcsController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ protected function formatShare(IShare $share, $received = false) {
281281
* Get a specific share by id
282282
*
283283
* @NoAdminRequired
284+
* @NoCSRFRequired
284285
*
285286
* @param string $id
286287
* @return Result
@@ -664,6 +665,7 @@ private function getSharedWithMe($node = null, $includeTags, $requestedShareType
664665
* the function will return an empty list.
665666
*
666667
* @NoAdminRequired
668+
* @NoCSRFRequired
667669
*
668670
* - Get shares by the current user
669671
* - Get shares by the current user and reshares (?reshares=true)

changelog/unreleased/40856

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Bugfix: Request header can hold an empty string if not set
2+
3+
Due to Apache rewrite rules originally not existing headers can hold an empty
4+
string.
5+
6+
https://github.com/owncloud/core/pull/40856

core/Controller/OcsController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function checkPerson($login, $password) {
110110
* test: curl http://login:passwd@oc/core/ocs/v1.php/privatedata/getattribute
111111
*
112112
* @NoAdminRequired
113+
* @NoCSRFRequired
113114
*
114115
* @return Result
115116
*/

lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ public function beforeController($controller, $methodName) {
143143
// CSRF check - also registers the CSRF token since the session may be closed later
144144
Util::callRegister();
145145
if (!$this->reflector->hasAnnotation('NoCSRFRequired')) {
146-
if (!$this->request->passesCSRFCheck() && $this->request->getHeader("Authorization") === null) {
146+
$hasNoAuthHeader = ($this->request->getHeader("Authorization") === null || trim($this->request->getHeader("Authorization")) === '');
147+
if (!$this->request->passesCSRFCheck() && $hasNoAuthHeader) {
147148
throw new CrossSiteRequestForgeryException();
148149
}
149150
}

tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,33 @@ protected function setUp(): void {
7979

8080
$this->controller = $this->getMockBuilder(Controller::class)
8181
->disableOriginalConstructor()
82-
->getMock();
82+
->getMock();
8383
$this->reader = new ControllerMethodReflector();
8484
$this->logger = $this->getMockBuilder(
8585
ILogger::class
8686
)
87-
->disableOriginalConstructor()
88-
->getMock();
87+
->disableOriginalConstructor()
88+
->getMock();
8989
$this->navigationManager = $this->getMockBuilder(
9090
INavigationManager::class
9191
)
92-
->disableOriginalConstructor()
93-
->getMock();
92+
->disableOriginalConstructor()
93+
->getMock();
9494
$this->urlGenerator = $this->getMockBuilder(
9595
IURLGenerator::class
9696
)
97-
->disableOriginalConstructor()
98-
->getMock();
97+
->disableOriginalConstructor()
98+
->getMock();
9999
$this->request = $this->getMockBuilder(
100100
IRequest::class
101101
)
102-
->disableOriginalConstructor()
103-
->getMock();
102+
->disableOriginalConstructor()
103+
->getMock();
104104
$this->contentSecurityPolicyManager = $this->getMockBuilder(
105105
ContentSecurityPolicyManager::class
106106
)
107-
->disableOriginalConstructor()
108-
->getMock();
107+
->disableOriginalConstructor()
108+
->getMock();
109109
$this->middleware = $this->getMiddleware(true, true);
110110
$this->secException = new SecurityException('hey', false);
111111
$this->secAjaxException = new SecurityException('hey', true);
@@ -252,8 +252,8 @@ public function testAjaxStatusAllGood() {
252252
*/
253253
public function testNoChecks() {
254254
$this->request->expects($this->never())
255-
->method('passesCSRFCheck')
256-
->will($this->returnValue(false));
255+
->method('passesCSRFCheck')
256+
->will($this->returnValue(false));
257257

258258
$sec = $this->getMiddleware(false, false);
259259

@@ -388,30 +388,30 @@ public function testAfterExceptionNotCaughtThrowsItAgain() {
388388
public function testAfterExceptionReturnsRedirectForNotLoggedInUser() {
389389
$this->request = new Request(
390390
[
391-
'server' =>
392-
[
393-
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
394-
'REQUEST_URI' => 'owncloud/index.php/apps/specialapp'
395-
]
396-
],
391+
'server' =>
392+
[
393+
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
394+
'REQUEST_URI' => 'owncloud/index.php/apps/specialapp'
395+
]
396+
],
397397
$this->createMock(ISecureRandom::class),
398398
$this->createMock(IConfig::class)
399399
);
400400
$this->middleware = $this->getMiddleware(false, false);
401401
$this->urlGenerator
402-
->expects($this->once())
403-
->method('linkToRoute')
404-
->with(
405-
'core.login.showLoginForm',
406-
[
407-
'redirect_url' => 'owncloud%2Findex.php%2Fapps%2Fspecialapp',
408-
]
409-
)
410-
->will($this->returnValue('http://localhost/index.php/login?redirect_url=owncloud%2Findex.php%2Fapps%2Fspecialapp'));
402+
->expects($this->once())
403+
->method('linkToRoute')
404+
->with(
405+
'core.login.showLoginForm',
406+
[
407+
'redirect_url' => 'owncloud%2Findex.php%2Fapps%2Fspecialapp',
408+
]
409+
)
410+
->will($this->returnValue('http://localhost/index.php/login?redirect_url=owncloud%2Findex.php%2Fapps%2Fspecialapp'));
411411
$this->logger
412-
->expects($this->once())
413-
->method('debug')
414-
->with('Current user is not logged in');
412+
->expects($this->once())
413+
->method('debug')
414+
->with('Current user is not logged in');
415415
$response = $this->middleware->afterException(
416416
$this->controller,
417417
'test',
@@ -447,20 +447,20 @@ public function exceptionProvider() {
447447
public function testAfterExceptionReturnsTemplateResponse(SecurityException $exception) {
448448
$this->request = new Request(
449449
[
450-
'server' =>
451-
[
452-
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
453-
'REQUEST_URI' => 'owncloud/index.php/apps/specialapp'
454-
]
455-
],
450+
'server' =>
451+
[
452+
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
453+
'REQUEST_URI' => 'owncloud/index.php/apps/specialapp'
454+
]
455+
],
456456
$this->createMock(ISecureRandom::class),
457457
$this->createMock(IConfig::class)
458458
);
459459
$this->middleware = $this->getMiddleware(false, false);
460460
$this->logger
461-
->expects($this->once())
462-
->method('debug')
463-
->with($exception->getMessage());
461+
->expects($this->once())
462+
->method('debug')
463+
->with($exception->getMessage());
464464
$response = $this->middleware->afterException(
465465
$this->controller,
466466
'test',
@@ -628,10 +628,10 @@ public function testAfterController() {
628628
->method('getDefaultPolicy')
629629
->willReturn($defaultPolicy);
630630
$this->contentSecurityPolicyManager
631-
->expects($this->once())
632-
->method('mergePolicies')
633-
->with($defaultPolicy, $currentPolicy)
634-
->willReturn($mergedPolicy);
631+
->expects($this->once())
632+
->method('mergePolicies')
633+
->with($defaultPolicy, $currentPolicy)
634+
->willReturn($mergedPolicy);
635635
$response->expects($this->once())
636636
->method('setContentSecurityPolicy')
637637
->with($mergedPolicy);

0 commit comments

Comments
 (0)