aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2025-02-17 18:06:45 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2025-02-17 18:08:23 +0100
commite757b649b7b6415ae5f77e59b5160052896b2c21 (patch)
tree21f63c87b66d8f316c5c2166e58dfb547db79b65 /lib
parent9edabfa21fa7e587c0ad95d2d230d215b060ade0 (diff)
downloadnextcloud-server-e757b649b7b6415ae5f77e59b5160052896b2c21.tar.gz
nextcloud-server-e757b649b7b6415ae5f77e59b5160052896b2c21.zip
fix: Fix psalm taint false-positives by small refactoringsfix/fix-psalm-taint-errors-2
Mostly make it clear that we trust admin input or that we correctly escape strings. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Config.php4
-rw-r--r--lib/private/Server.php1
-rw-r--r--lib/private/Session/CryptoWrapper.php49
3 files changed, 17 insertions, 37 deletions
diff --git a/lib/private/Config.php b/lib/private/Config.php
index 3ec21df9f7c..a9eb58a1866 100644
--- a/lib/private/Config.php
+++ b/lib/private/Config.php
@@ -266,7 +266,7 @@ class Config {
* @throws HintException If the config file cannot be written to
* @throws \Exception If no file lock can be acquired
*/
- private function writeData() {
+ private function writeData(): void {
$this->checkReadOnly();
if (!is_file(\OC::$configDir . '/CAN_INSTALL') && !isset($this->cache['version'])) {
@@ -276,7 +276,7 @@ class Config {
// Create a php file ...
$content = "<?php\n";
$content .= '$CONFIG = ';
- $content .= var_export($this->cache, true);
+ $content .= var_export(self::trustSystemConfig($this->cache), true);
$content .= ";\n";
touch($this->configFilePath);
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 968d469aa74..77759de30c5 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1109,7 +1109,6 @@ class Server extends ServerContainer implements IServerContainer {
);
return new CryptoWrapper(
- $c->get(\OCP\IConfig::class),
$c->get(ICrypto::class),
$c->get(ISecureRandom::class),
$request
diff --git a/lib/private/Session/CryptoWrapper.php b/lib/private/Session/CryptoWrapper.php
index aceb387ea74..380c699d32d 100644
--- a/lib/private/Session/CryptoWrapper.php
+++ b/lib/private/Session/CryptoWrapper.php
@@ -1,13 +1,15 @@
<?php
+declare(strict_types=1);
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
+
namespace OC\Session;
-use OCP\IConfig;
use OCP\IRequest;
use OCP\ISession;
use OCP\Security\ICrypto;
@@ -30,37 +32,19 @@ use OCP\Security\ISecureRandom;
* @package OC\Session
*/
class CryptoWrapper {
+ /** @var string */
public const COOKIE_NAME = 'oc_sessionPassphrase';
- /** @var IConfig */
- protected $config;
- /** @var ISession */
- protected $session;
- /** @var ICrypto */
- protected $crypto;
- /** @var ISecureRandom */
- protected $random;
- /** @var string */
- protected $passphrase;
+ protected string $passphrase;
- /**
- * @param IConfig $config
- * @param ICrypto $crypto
- * @param ISecureRandom $random
- * @param IRequest $request
- */
- public function __construct(IConfig $config,
- ICrypto $crypto,
+ public function __construct(
+ protected ICrypto $crypto,
ISecureRandom $random,
- IRequest $request) {
- $this->crypto = $crypto;
- $this->config = $config;
- $this->random = $random;
-
- if (!is_null($request->getCookie(self::COOKIE_NAME))) {
- $this->passphrase = $request->getCookie(self::COOKIE_NAME);
- } else {
- $this->passphrase = $this->random->generate(128);
+ IRequest $request,
+ ) {
+ $passphrase = $request->getCookie(self::COOKIE_NAME);
+ if ($passphrase === null) {
+ $passphrase = $random->generate(128);
$secureCookie = $request->getServerProtocol() === 'https';
// FIXME: Required for CI
if (!defined('PHPUNIT_RUN')) {
@@ -71,7 +55,7 @@ class CryptoWrapper {
setcookie(
self::COOKIE_NAME,
- $this->passphrase,
+ $passphrase,
[
'expires' => 0,
'path' => $webRoot,
@@ -83,13 +67,10 @@ class CryptoWrapper {
);
}
}
+ $this->passphrase = $passphrase;
}
- /**
- * @param ISession $session
- * @return ISession
- */
- public function wrapSession(ISession $session) {
+ public function wrapSession(ISession $session): ISession {
if (!($session instanceof CryptoSessionData)) {
return new CryptoSessionData($session, $this->crypto, $this->passphrase);
}