diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-01-15 22:05:06 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-02-08 10:16:38 +0100 |
commit | f1cd334281a4ae70b7ca77b48e9263b80ee03e85 (patch) | |
tree | 3810d8f2f6d555ac121f6682e7baac594efc07a0 | |
parent | 202dd6295143f7cadb249ac8368cb59bfcbf3217 (diff) | |
download | nextcloud-server-f1cd334281a4ae70b7ca77b48e9263b80ee03e85.tar.gz nextcloud-server-f1cd334281a4ae70b7ca77b48e9263b80ee03e85.zip |
Don't perform CSRF check on OCS routes with Bearer auth
Fixes #5694
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r-- | lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php index c147b5b2475..c19834b462b 100644 --- a/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php @@ -170,10 +170,16 @@ class SecurityMiddleware extends Middleware { * Only allow the CSRF check to fail on OCS Requests. This kind of * hacks around that we have no full token auth in place yet and we * do want to offer CSRF checks for web requests. + * + * Additionally we allow Bearer authenticated requests to pass on OCS routes. + * This allows oauth apps (e.g. moodle) to use the OCS endpoints */ if(!$this->request->passesCSRFCheck() && !( - $controller instanceof OCSController && - $this->request->getHeader('OCS-APIREQUEST') === 'true')) { + $controller instanceof OCSController && ( + $this->request->getHeader('OCS-APIREQUEST') === 'true' || + strpos($this->request->getHeader('Authorization'), 'Bearer ') === 0 + ) + )) { throw new CrossSiteRequestForgeryException(); } } |