Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize raw strings #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AmazonPay/IpnHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ private void LogRequestDetails(NameValueCollection headers, string message)

for (int i = 0; i < headers.Count; i++)
{
sb.AppendLine("[Key: " + headers.GetKey(i) + ", Value: " + headers.GetValues(headers.GetKey(i))[0] + "]");
string key = headers.GetKey(i);
sb.AppendLine("[Key: " + key + ", Value: @#" + key +"#@" + headers.GetValues(headers.GetKey(i))[0] + "@#" + key +"#@]");
}
// Logging headers
LogMessage(sb.ToString(), AmazonPay.SanitizeData.DataType.Text);
Expand Down
17 changes: 15 additions & 2 deletions AmazonPay/SanitizeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,21 @@ public static string SanitizeGivenData(string data, DataType type)
}
// Text Data Type
else if (type == DataType.Text)
{
returnString = data;
{
foreach (var item in sanitizeList)
{
string maskedValue = "@#" + item + "#@";
int startIndex = data.IndexOf(maskedValue);
if (startIndex > 0)
{
int endIndex = data.LastIndexOf(maskedValue) + (maskedValue.Length);
int length = endIndex - startIndex;
string value = data.Substring(startIndex, length);
data = data.Replace(value, REMOVED_TEXT);
}
}
System.Text.RegularExpressions.Regex objRegEx = new System.Text.RegularExpressions.Regex("@#[^#@]*#@", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
returnString = objRegEx.Replace(data, "");
}
return returnString;
}
Expand Down