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

Feedback from Java Integration #8272

Merged
merged 6 commits into from
May 15, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ public class ModifiableRecordSession

public ModifiableRecordSession(SanitizerDictionary sanitizerRegistry, string sessionId)
{
this.AppliedSanitizers = sanitizerRegistry.SessionSanitizers.ToList();
lock(sanitizerRegistry.SessionSanitizerLock)
{
this.AppliedSanitizers = sanitizerRegistry.SessionSanitizers.ToList();
}
this.SessionId = sessionId;
}

public ModifiableRecordSession(RecordSession session, SanitizerDictionary sanitizerRegistry, string sessionId)
{
Session = session;
this.AppliedSanitizers = sanitizerRegistry.SessionSanitizers.ToList();
lock (sanitizerRegistry.SessionSanitizerLock)
{
this.AppliedSanitizers = sanitizerRegistry.SessionSanitizers.ToList();
}
this.SessionId = sessionId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,6 @@ public SanitizerDictionary() {
new BodyKeySanitizer("$..apiKey"),
"AZSDK3480"
),
new RegisteredSanitizer(
scbedd marked this conversation as resolved.
Show resolved Hide resolved
new BodyKeySanitizer("$..connectionString"),
"AZSDK3481"
),
new RegisteredSanitizer(
new BodyKeySanitizer("$..password"),
"AZSDK3482"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,25 @@ public List<Tuple<string, Detection>> DiscoverSecrets(string assetRepoRoot, IEnu

Parallel.ForEach(relativePaths, options, (filePath) =>
{
var content = File.ReadAllText(Path.Combine(assetRepoRoot, filePath));
var fileDetections = DetectSecrets(content);
var path = Path.Combine(assetRepoRoot, filePath);

if (fileDetections != null && fileDetections.Count > 0)
if (File.Exists(path))
{
foreach (Detection detection in fileDetections)
var content = File.ReadAllText(path);
var fileDetections = DetectSecrets(content);

if (fileDetections != null && fileDetections.Count > 0)
{
detectedSecrets.Add(Tuple.Create(filePath, detection));
foreach (Detection detection in fileDetections)
{
detectedSecrets.Add(Tuple.Create(filePath, detection));
}
}
}

Interlocked.Increment(ref seen);
Interlocked.Increment(ref seen);

Console.Write($"\r\u001b[2KScanned {seen}/{total}.");
Console.Write($"\r\u001b[2KScanned {seen}/{total}.");
}
});

Console.WriteLine(string.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,40 @@ public override string SanitizeTextBody(string contentType, string body)
return body;
}


if (jsonO != null)
{
foreach (JToken token in jsonO.SelectTokens(_jsonPath))
try
{
// HasValues is false for tokens with children. We will not apply sanitization if that is the case.
if (!token.HasValues)
foreach (JToken token in jsonO.SelectTokens(_jsonPath))
{
var originalValue = token.Value<string>();

// regex replacement does not support null
if (originalValue == null)
// HasValues is false for tokens with children. We will not apply sanitization if that is the case.
if (!token.HasValues)
{
continue;
}
var originalValue = token.Value<string>();

var replacement = StringSanitizer.SanitizeValue(originalValue, _newValue, _regexValue, _groupForReplace);
// regex replacement does not support null
if (originalValue == null)
{
continue;
}

// this sanitizer should only apply to actual values
// if we attempt to apply a regex update to a jtoken that has a more complex type, throw
token.Replace(JToken.FromObject(replacement));
var replacement = StringSanitizer.SanitizeValue(originalValue, _newValue, _regexValue, _groupForReplace);

if (originalValue != replacement)
{
sanitized = true;
// this sanitizer should only apply to actual values
// if we attempt to apply a regex update to a jtoken that has a more complex type, throw
token.Replace(JToken.FromObject(replacement));

if (originalValue != replacement)
{
sanitized = true;
}
}
}
}
catch(Exception e)
{
DebugLogger.LogError($"Ran into exception \"{e.Message}\" while attempting to run regex \"{_regexValue}\" against body value \"{body}\"");
return body;
}
}

Expand Down