-
-
Notifications
You must be signed in to change notification settings - Fork 2
fix: dynamic user-path sanitization in LogService and cache FontFamily in MarkdownTextBlock #444
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
In .NET on Windows, what exact values can Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) return for LocalSystem/NetworkService accounts, and can it be non-empty while not pointing to a standard multi-user root like X:\Users\ ?💡 Result:
In.NET on Windows, Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) returns the “user profile” path for whatever security context the current process is running under, and it can be empty if the corresponding folder does not physically exist. 1) Exact non-empty values for LocalSystem - For the LocalSystem service account, the returned UserProfile is typically: C:\Windows\System32\Config\SystemProfile This matches reports from.NET code running in a service context where Environment.GetFolderPath(UserProfile) yields C:\Windows\system32\config\systemprofile (and similarly used when building AppData paths). [1][2] 2) NetworkService / LocalService - The.NET/environment APIs compute the UserProfile path based on the running account’s profile. Microsoft’s LocalSystem documentation explains that LocalSystem is a special service account used by the SCM and notes the token/SID context, and it contrasts LocalSystem with LocalService/NetworkService as alternatives for services. [3] - However, in the sources retrieved here, I did not find a similarly explicit, authoritative “exact string” mapping for NetworkService specifically (e.g., the exact folder path string) comparable to the LocalSystem/SystemProfile mapping above. 3) Can it be non-empty while not pointing to a standard multi-user root like X:\Users? - Yes, at least for LocalSystem: the returned path is not under X:\Users\…; it is under the system profile directory (C:\Windows\System32\Config\SystemProfile). [1][2] - Empty-string behavior: Environment.GetFolderPath returns an empty string (“”) if the requested special-folder path does not physically exist on the computer. [4] Bottom line - LocalSystem: non-empty UserProfile path is expected to be C:\Windows\System32\Config\SystemProfile, i.e., non-X:\Users and therefore can meet your “non-empty while not pointing to a standard multi-user root” condition. [1][2] - NetworkService: non-empty is possible, but I cannot, from the sourced material gathered here, state the exact value it will return for NetworkService. If you tell me your exact OS version (e.g., Windows Server 2008 R2 vs newer) and whether the service is running under LocalSystem vs NetworkService vs a custom domain/service account, I can try one more targeted lookup to pin down the exact NetworkService UserProfile string for Windows Server +.NET version in your scenario.
Citations:
🏁 Script executed:
cat -n SysManager/SysManager/Services/LogService.cs | head -100Repository: laurentiu021/SystemManager
Length of output: 3009
🏁 Script executed:
rg "UserPathRegex|BuildUserPathRegex" SysManager/SysManager/Services/LogService.cs -A 3 -B 2Repository: laurentiu021/SystemManager
Length of output: 593
🏁 Script executed:
rg "Regex\.Replace" SysManager/ -A 1 -B 1 -t csRepository: laurentiu021/SystemManager
Length of output: 708
🌐 Web query:
.NET Regex.Replace named capture group replacement syntax ${groupname} C# documentation💡 Result:
In.NET, the syntax to reference a named capture group within a replacement string is ${name} [1][2]. When using the Regex.Replace method, you can include the substring matched by a named capturing group (defined in your pattern as (?...)) by placing the group name inside the ${} substitution element [1][2]. Key behaviors of this syntax include: - If the name corresponds to a valid named capturing group defined in the regular expression,.NET substitutes the last substring matched by that group [1][2]. - If the name consists only of digits and does not match a named group,.NET interprets it as a numbered backreference (e.g., ${1}) [1][2]. - If the name is neither a valid named group nor a valid numbered group, it is treated as a literal string [1][2]. Example usage: string input = "First Second"; string pattern = @"(?First) (?Second)"; string replacement = "${second} ${first}"; string result = Regex.Replace(input, pattern, replacement); // Result: "Second First" [3]
Citations:
Fallback pattern is bypassed when UserProfile is non-empty but non-standard—user paths can leak in logs.
When the service runs under LocalSystem (or other non-interactive accounts),
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)returns a non-empty path likeC:\Windows\System32\Config\SystemProfile. This causes an early return on line 33 with a pattern that only matches paths under that system directory, never reaching the fallback on line 37. If logs contain paths likeC:\Users\username\..., they won't be redacted.Combine both patterns using alternation and return a single regex:
Suggested fix
private static Regex BuildUserPathRegex() { var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + string pattern = @"(?i)(?<prefix>[A-Z]:\\Users\\)[^\\]+"; + if (!string.IsNullOrEmpty(userProfile)) { var usersDir = Path.GetDirectoryName(userProfile); if (!string.IsNullOrEmpty(usersDir)) { var escaped = Regex.Escape(usersDir + @"\"); - return new Regex($@"(?i)({escaped})[^\\]+", RegexOptions.Compiled); + pattern = $@"(?i)(?<prefix>{escaped}|[A-Z]:\\Users\\)[^\\]+"; } } - // Fallback: match any drive letter followed by \Users\<username> - return new Regex(@"(?i)([A-Z]:\\Users\\)[^\\]+", RegexOptions.Compiled); + + return new Regex(pattern, RegexOptions.Compiled); }Also update line 68:
📝 Committable suggestion
🤖 Prompt for AI Agents