From 22eabfcf9af6552f2c20f9242f7b820aed1dcb32 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 4 May 2021 09:51:44 +0200 Subject: [PATCH] Add \wcf\SensitiveArgument attribute --- wcfsetup/install/files/lib/core.functions.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/wcfsetup/install/files/lib/core.functions.php b/wcfsetup/install/files/lib/core.functions.php index b414761add..f96e050e11 100644 --- a/wcfsetup/install/files/lib/core.functions.php +++ b/wcfsetup/install/files/lib/core.functions.php @@ -116,6 +116,11 @@ namespace wcf { function getMinorVersion(): string { return preg_replace('/^(\d+\.\d+)\..*$/', '\\1', WCF_VERSION); } + + #[Attribute(\Attribute::TARGET_PARAMETER)] + class SensitiveArgument + { + } } namespace wcf\functions\exception { @@ -710,6 +715,30 @@ EXPLANATION; if (!isset($item['class'])) $item['class'] = ''; if (!isset($item['type'])) $item['type'] = ''; if (!isset($item['args'])) $item['args'] = []; + + if ($item['class']) { + $f = new \ReflectionMethod($item['class'], $item['function']); + } + else { + $f = new \ReflectionFunction($item['function']); + } + + $parameters = $f->getParameters(); + $i = 0; + foreach ($parameters as $parameter) { + $isSensitive = false; + if ( + \method_exists($parameter, 'getAttributes') + && !empty($parameter->getAttributes(\wcf\SensitiveArgument::class)) + ) { + $isSensitive = true; + } + + if ($isSensitive && isset($item['args'][$i])) { + $item['args'][$i] = '[redacted]'; + } + $i++; + } // strip database credentials if (preg_match('~\\\\?wcf\\\\system\\\\database\\\\[a-zA-Z]*Database~', $item['class']) || $item['class'] === 'PDO') { -- 2.20.1