Skip to content

Commit cdd7377

Browse files
committed
masking edge cases fix
1 parent 52d293e commit cdd7377

File tree

1 file changed

+21
-0
lines changed
  • cybersource-rest-auth-netstandard/AuthenticationSdk/AuthenticationSdk/util

1 file changed

+21
-0
lines changed

cybersource-rest-auth-netstandard/AuthenticationSdk/AuthenticationSdk/util/LogUtility.cs

+21
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ public string MaskSensitiveData(string str)
4949
{
5050
foreach (KeyValuePair<string, string> tag in sensitiveTags)
5151
{
52+
//removing the space and hypen from PAN details before masking
53+
if (tag.Key.StartsWith("\\\"number\\\"") || tag.Key.StartsWith("\\\"cardNumber\\\"") || tag.Key.StartsWith("\\\"account\\\"")
54+
|| tag.Key.StartsWith("\\\"prefix\\\"") || tag.Key.StartsWith("\\\"bin\\\""))
55+
{
56+
string[] splittedStr = tag.Key.Split(':');
57+
string tagName = splittedStr[0];
58+
string specialPatternForPAN = "(((\\s*[s/-]*\\s*)+)\\p{N}((\\s*[s/-]*\\s*)+))+";
59+
60+
// match the patters for PAN number
61+
MatchCollection matches = Regex.Matches(str, $"{tagName}:\\\"{specialPatternForPAN}\\\"");
62+
63+
//remove space and dash from the all matched pattern
64+
foreach (Match match in matches)
65+
{
66+
String strr = match.ToString();
67+
strr = Regex.Replace(strr, "\\s*[s/-]*", "");
68+
69+
//replace original value in str with match
70+
str = str.Replace(match.ToString(), strr);
71+
}
72+
}
5273
str = Regex.Replace(str, tag.Key, tag.Value);
5374
}
5475
}

0 commit comments

Comments
 (0)