Conversation
Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
…DynamoModel.cs Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
|
| if (trustedLoc.StartsWith(programDataPath)) | ||
| { | ||
| Logger.Log(("An unsafe path has been detected in Trusted Locations: " + trustedLoc)); | ||
| Logger.Log($"An unsafe path has been detected in Trusted Locations: {trustedLoc}"); |
Check failure
Code scanning / CodeQL
Clear text storage of sensitive information High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 month ago
In general, to fix clear-text storage issues in logs, you either (a) avoid logging the sensitive value at all, or (b) log only a redacted/derived form (such as a hash, prefix, or generic tag) that is sufficient for diagnostics without exposing the original value. For filesystem paths coming from user-controlled configuration, you typically only need to indicate that a problematic path exists and maybe show a minimally identifying portion, not the entire absolute path.
For this specific case, the best fix that preserves existing functionality is to avoid logging the full trusted location path and instead log only a safe, truncated representation. We can transform trustedLoc before passing it to Logger.Log, e.g. by logging only the last directory segment or a redacted form such as "...\folder" or "[redacted]". This keeps the information that an unsafe path exists and roughly which entry it is, while no longer storing the full user path in clear text. We only need to change the logging line in DynamoModel.cs; the rest of the flow (loading and storing trusted locations in memory and XML) is outside the identified sink and should remain unchanged.
Concretely, in src/DynamoCore/Models/DynamoModel.cs, within the constructor (or initialization method) near lines 1038–1045, replace
Logger.Log($"An unsafe path has been detected in Trusted Locations: {trustedLoc}");with a version that uses a safe representation of trustedLoc. A simple approach that requires no new imports is to derive a short identifier, such as the last path component using Path.GetFileName(trustedLoc.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)), and log that instead. However, we must not add new imports other than standard ones, and System.IO is already imported at the top of the file, so we can safely use Path. We will compute a safeLocationDescription inline and use that in the log message. This change affects only DynamoModel.cs; no changes are required in PreferenceSettings.cs for this particular sink.
| @@ -1040,7 +1040,8 @@ | ||
| { | ||
| if (trustedLoc.StartsWith(programDataPath)) | ||
| { | ||
| Logger.Log($"An unsafe path has been detected in Trusted Locations: {trustedLoc}"); | ||
| var safeLocationDescription = Path.GetFileName(trustedLoc.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); | ||
| Logger.Log($"An unsafe path has been detected in Trusted Locations. Entry: {safeLocationDescription}"); | ||
| } | ||
| } | ||
| } |



Janitorial cleanup applying modern C# 12 language features to DynamoModel.cs for improved readability and maintainability. No functional changes.
Changes Applied
new List<T>()→[],new Dictionary<K,V>()→[]ornew()for field initializers (21 instances)var x = obj as Type; if (x != null)→if (obj is Type x)(5 instances)string.Formatwith$""syntax (9 instances)Example
Impact: 110 lines modified (53 insertions, 55 deletions), net -2 lines. All changes preserve existing semantics and maintain backward compatibility.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.