]+)/i', '$1[redacted]'), // Authorization headers array('/(Authorization\s*:\s*(?:Bearer|Basic)\s+)\S+/i', '$1[redacted]'), ); } public static function text($value) { if (!is_scalar($value)) { return ''; } $value = self::secrets((string) $value); if (strlen($value) > self::MAX_LENGTH) { $value = substr($value, 0, self::MAX_LENGTH) . '…'; } return $value; } /** * Replace secrets without shortening the text (for example when showing file contents) */ public static function secrets($value) { $value = (string) $value; foreach (self::patterns() as $pattern) { $value = preg_replace($pattern[0], $pattern[1], $value); } // The configured vulnerability API key $key = AOWPCS_Settings::get('wordfence_api_key'); if (is_string($key) && strlen($key) >= 8) { $value = str_replace($key, '[redacted]', $value); } return $value; } /** * Redact every value of a (nested) evidence array */ public static function evidence($data, $depth = 0) { if ($depth > 4) { return array(); } $clean = array(); foreach ((array) $data as $key => $value) { $key = is_int($key) ? $key : substr(sanitize_text_field((string) $key), 0, 100); if (is_array($value)) { $clean[$key] = self::evidence(array_slice($value, 0, 100, true), $depth + 1); } elseif (is_bool($value)) { $clean[$key] = $value; } elseif (is_int($value) || is_float($value)) { $clean[$key] = $value; } elseif ($value === null) { $clean[$key] = null; } else { $clean[$key] = self::text($value); } } return $clean; } }