From ea717a1e307eaafc22288d36147007acd8a9c2cc Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Mon, 1 Jun 2026 11:59:07 -0700 Subject: [PATCH 1/3] Add maskSensitiveJsonString method --- lib/net/authorize/util/Log.php | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/net/authorize/util/Log.php b/lib/net/authorize/util/Log.php index 28d13e21..ced13314 100644 --- a/lib/net/authorize/util/Log.php +++ b/lib/net/authorize/util/Log.php @@ -80,6 +80,40 @@ private function maskSensitiveXmlString($rawString){ return $maskedString; } + /** + * Takes a JSON string and masks the sensitive fields. + * + * @param string $rawString The JSON as a string. + * + * @return string The JSON as a string after masking sensitive fields + */ + private function maskSensitiveJsonString($rawString){ + $patterns=array(); + $replacements=array(); + + foreach ($this->sensitiveXmlTags as $i => $sensitiveTag){ + $tag = $sensitiveTag->tagName; + $inputPattern = "(.+)"; + $inputReplacement = "xxxx"; + + if(trim($sensitiveTag->pattern)) { + $inputPattern = $sensitiveTag->pattern; + } + $pattern = '"' . $tag . '"\s*:\s*"(?:.*)' . $inputPattern . '(?:.*)"'; + $pattern = $this->addDelimiterFwdSlash($pattern); + + if(trim($sensitiveTag->replacement)) { + $inputReplacement = $sensitiveTag->replacement; + } + $replacement = '"' . $tag . '":"' . $inputReplacement . '"'; + + $patterns[$i] = $pattern; + $replacements[$i] = $replacement; + } + $maskedString = preg_replace($patterns, $replacements, $rawString); + return $maskedString; + } + /** * Takes a string and masks credit card regex matching parts. * @@ -241,6 +275,7 @@ private function getMasked($raw) $maskedXml = $primtiveTypeAsString; if($messageType == "string") { $maskedXml = $this->maskSensitiveXmlString($primtiveTypeAsString); + $maskedXml = $this->maskSensitiveJsonString($maskedXml); } //mask credit card numbers $message = $this->maskCreditCards($maskedXml); From e737a5ed40075e97502dd4a4daee0df608038fda Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Mon, 1 Jun 2026 12:21:37 -0700 Subject: [PATCH 2/3] Fix agressive pattern matching --- lib/net/authorize/util/Log.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/net/authorize/util/Log.php b/lib/net/authorize/util/Log.php index ced13314..ac5e876d 100644 --- a/lib/net/authorize/util/Log.php +++ b/lib/net/authorize/util/Log.php @@ -93,13 +93,13 @@ private function maskSensitiveJsonString($rawString){ foreach ($this->sensitiveXmlTags as $i => $sensitiveTag){ $tag = $sensitiveTag->tagName; - $inputPattern = "(.+)"; + $inputPattern = "([^\"]+)"; $inputReplacement = "xxxx"; if(trim($sensitiveTag->pattern)) { $inputPattern = $sensitiveTag->pattern; } - $pattern = '"' . $tag . '"\s*:\s*"(?:.*)' . $inputPattern . '(?:.*)"'; + $pattern = '"' . $tag . '"\s*:\s*"(?:[^"]*)' . $inputPattern . '(?:[^"]*)"'; $pattern = $this->addDelimiterFwdSlash($pattern); if(trim($sensitiveTag->replacement)) { From b2bb16bf0a480ab3220a34a8e1f6bf378ad6c29e Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Mon, 1 Jun 2026 12:24:33 -0700 Subject: [PATCH 3/3] Add comment for $inputPattern --- lib/net/authorize/util/Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net/authorize/util/Log.php b/lib/net/authorize/util/Log.php index ac5e876d..65211bb3 100644 --- a/lib/net/authorize/util/Log.php +++ b/lib/net/authorize/util/Log.php @@ -93,7 +93,7 @@ private function maskSensitiveJsonString($rawString){ foreach ($this->sensitiveXmlTags as $i => $sensitiveTag){ $tag = $sensitiveTag->tagName; - $inputPattern = "([^\"]+)"; + $inputPattern = "([^\"]+)"; //no need to mask null data $inputReplacement = "xxxx"; if(trim($sensitiveTag->pattern)) {