Skip to content

Commit 2830a43

Browse files
committed
Don't perform CSRF check on OCS routes with Bearer auth
Fixes #5694 Signed-off-by: Roeland Jago Douma <[email protected]>
1 parent 2997bb9 commit 2830a43

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,16 @@ public function beforeController($controller, $methodName) {
170170
* Only allow the CSRF check to fail on OCS Requests. This kind of
171171
* hacks around that we have no full token auth in place yet and we
172172
* do want to offer CSRF checks for web requests.
173+
*
174+
* Additionally we allow Bearer authenticated requests to fail on OCS routes.
175+
* This allows oauth apps (e.g. moodle) to use the OCS endpoints
173176
*/
174177
if(!$this->request->passesCSRFCheck() && !(
175-
$controller instanceof OCSController &&
176-
$this->request->getHeader('OCS-APIREQUEST') === 'true')) {
178+
$controller instanceof OCSController && (
179+
$this->request->getHeader('OCS-APIREQUEST') === 'true' ||
180+
strpos($this->request->getHeader('Authorization'), 'Bearer ') === 0
181+
)
182+
)) {
177183
throw new CrossSiteRequestForgeryException();
178184
}
179185
}

0 commit comments

Comments
 (0)