diff --git a/lib/private/Security/CSRF/CsrfToken.php b/lib/private/Security/CSRF/CsrfToken.php index d9e27ff80e34bfbb67b76ecf07d1e3bd682a32e4..643e58e1d5334eb5877c43b97f389bcbc9c8324f 100644 --- a/lib/private/Security/CSRF/CsrfToken.php +++ b/lib/private/Security/CSRF/CsrfToken.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -40,7 +41,7 @@ class CsrfToken { /** * @param string $value Value of the token. Can be encrypted or not encrypted. */ - public function __construct($value) { + public function __construct(string $value) { $this->value = $value; } @@ -50,9 +51,9 @@ class CsrfToken { * * @return string */ - public function getEncryptedValue() { + public function getEncryptedValue(): string { if($this->encryptedValue === '') { - $sharedSecret = random_bytes(strlen($this->value)); + $sharedSecret = random_bytes(\strlen($this->value)); $this->encryptedValue = base64_encode($this->value ^ $sharedSecret) . ':' . base64_encode($sharedSecret); } @@ -65,9 +66,9 @@ class CsrfToken { * * @return string */ - public function getDecryptedValue() { + public function getDecryptedValue(): string { $token = explode(':', $this->value); - if (count($token) !== 2) { + if (\count($token) !== 2) { return ''; } $obfuscatedToken = $token[0]; diff --git a/lib/private/Security/CSRF/CsrfTokenGenerator.php b/lib/private/Security/CSRF/CsrfTokenGenerator.php index 85207956e1a305675e1dfaa4030ea35afe7c08e4..be628ea176cf6c409835a78af6c5910a0eb1889b 100644 --- a/lib/private/Security/CSRF/CsrfTokenGenerator.php +++ b/lib/private/Security/CSRF/CsrfTokenGenerator.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -47,7 +48,7 @@ class CsrfTokenGenerator { * @param int $length Length of the token in characters. * @return string */ - public function generateToken($length = 32) { + public function generateToken(int $length = 32): string { return $this->random->generate($length); } } diff --git a/lib/private/Security/CSRF/CsrfTokenManager.php b/lib/private/Security/CSRF/CsrfTokenManager.php index b43ca3d3679f61293fa2b76b265fa1c04d994a5b..deacd1f512cac8bbf67368e02c7d683ece39739d 100644 --- a/lib/private/Security/CSRF/CsrfTokenManager.php +++ b/lib/private/Security/CSRF/CsrfTokenManager.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -52,8 +53,8 @@ class CsrfTokenManager { * * @return CsrfToken */ - public function getToken() { - if(!is_null($this->csrfToken)) { + public function getToken(): CsrfToken { + if(!\is_null($this->csrfToken)) { return $this->csrfToken; } @@ -73,7 +74,7 @@ class CsrfTokenManager { * * @return CsrfToken */ - public function refreshToken() { + public function refreshToken(): CsrfToken { $value = $this->tokenGenerator->generateToken(); $this->sessionStorage->setToken($value); $this->csrfToken = new CsrfToken($value); @@ -94,7 +95,7 @@ class CsrfTokenManager { * @param CsrfToken $token * @return bool */ - public function isTokenValid(CsrfToken $token) { + public function isTokenValid(CsrfToken $token): bool { if(!$this->sessionStorage->hasToken()) { return false; } diff --git a/lib/private/Security/CSRF/TokenStorage/SessionStorage.php b/lib/private/Security/CSRF/TokenStorage/SessionStorage.php index 946330b0c8cb708e8fe58afd4306b8d1d2546793..b35e148c7cebca88f5c908b6c884214a7223147a 100644 --- a/lib/private/Security/CSRF/TokenStorage/SessionStorage.php +++ b/lib/private/Security/CSRF/TokenStorage/SessionStorage.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -54,7 +55,7 @@ class SessionStorage { * @return string * @throws \Exception */ - public function getToken() { + public function getToken(): string { $token = $this->session->get('requesttoken'); if(empty($token)) { throw new \Exception('Session does not contain a requesttoken'); @@ -68,7 +69,7 @@ class SessionStorage { * * @param string $value */ - public function setToken($value) { + public function setToken(string $value) { $this->session->set('requesttoken', $value); } @@ -83,7 +84,7 @@ class SessionStorage { * * @return bool */ - public function hasToken() { + public function hasToken(): bool { return $this->session->exists('requesttoken'); } } diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index c6b9719b32ae6aa62537d2e76de5a4d6f6dc5a13..a715eaa95993296559769ab17329bcd4abf640ed 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -1846,7 +1846,6 @@ class RequestTest extends \Test\TestCase { return [ ['InvalidSentToken'], ['InvalidSentToken:InvalidSecret'], - [null], [''], ]; }