exception instanceof HttpException && $hint->exception->getStatusCode() < 500) { return null; } $request = $event->getRequest(); if ($request !== []) { $event->setRequest(array_merge($request, [ 'data' => self::scrubBody($request['data'] ?? []), 'headers' => self::scrubHeaders($request['headers'] ?? []), 'query_string' => self::scrubQueryString($request['query_string'] ?? ''), 'cookies' => self::SCRUBBED, ])); } return $event; } /** * @param mixed $data * @return mixed */ private static function scrubBody($data, int $depth = 0) { if (! is_array($data)) { return $data; } if ($depth > self::MAX_DEPTH) { return ['[max_depth]']; } foreach ($data as $key => $value) { if (is_string($key) && strtolower($key) === self::FORM_VALUES_KEY) { $data[$key] = self::FORM_VALUES_REPLACEMENT; continue; } if (is_string($key) && in_array(strtolower($key), self::SENSITIVE_BODY_KEYS, true)) { $data[$key] = self::SCRUBBED; continue; } if (is_array($value)) { $data[$key] = self::scrubBody($value, $depth + 1); } } return $data; } /** * @param array|string $headers * @return array|string */ private static function scrubHeaders($headers) { if (! is_array($headers)) { return $headers; } foreach (array_keys($headers) as $name) { if (in_array(strtolower((string) $name), self::SENSITIVE_HEADERS, true)) { $headers[$name] = self::SCRUBBED; } } return $headers; } private static function scrubQueryString(string $queryString): string { if ($queryString === '') { return ''; } parse_str($queryString, $parsed); foreach ($parsed as $key => $value) { if (is_string($key) && in_array(strtolower($key), self::SENSITIVE_QUERY_KEYS, true)) { $parsed[$key] = self::SCRUBBED; } } return http_build_query($parsed); } }