From: Tim Düsterhus Date: Tue, 4 May 2021 07:51:44 +0000 (+0200) Subject: Add \wcf\SensitiveArgument attribute X-Git-Tag: 5.4.0_Alpha_1~4^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=22eabfcf9af6552f2c20f9242f7b820aed1dcb32;p=GitHub%2FWoltLab%2FWCF.git Add \wcf\SensitiveArgument attribute --- 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') {