-
Notifications
You must be signed in to change notification settings - Fork 1
fix(security): prevent log forging and add workflow permissions #51
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,12 +1,37 @@ | ||||||
| using System.Linq.Expressions; | ||||||
| using System.Reflection; | ||||||
| using System.Text.RegularExpressions; | ||||||
| using JsonApiToolkit.Models.Querying.Filtering; | ||||||
| using Microsoft.Extensions.Logging; | ||||||
|
|
||||||
| namespace JsonApiToolkit.Extensions.Querying; | ||||||
|
|
||||||
| internal static class NestedPropertyNavigator | ||||||
| internal static partial class NestedPropertyNavigator | ||||||
| { | ||||||
| private const int MaxLogValueLength = 100; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Sanitizes user input for safe logging by removing control characters | ||||||
| /// and truncating long values to prevent log forging attacks. | ||||||
| /// </summary> | ||||||
| private static string SanitizeForLog(string? value) | ||||||
|
||||||
| private static string SanitizeForLog(string? value) | |
| internal static string SanitizeForLog(string? value) |
Copilot
AI
Jan 24, 2026
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.
The user-provided field name filter.Field is being logged without sanitization in FilterExpressionBuilder.cs at lines 54, 68, and 152. While this PR adds sanitization for filter.Value in NestedPropertyNavigator.cs, it should also sanitize filter.Field wherever it's logged to fully address the log forging vulnerability. Consider adding the SanitizeForLog helper to FilterExpressionBuilder and applying it to these log statements as well.
Copilot
AI
Jan 24, 2026
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.
The SanitizeForLog method lacks comprehensive test coverage. Given that this is a critical security function preventing log forging attacks, it should have dedicated unit tests covering edge cases such as: empty strings, strings with only control characters, strings at the truncation boundary, strings with mixed control and normal characters, and null values. Consider adding tests in the JsonApiToolkit.Tests project to verify this function behaves correctly in all scenarios.
Copilot
AI
Jan 24, 2026
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.
The regex pattern [\x00-\x1F\x7F] removes ASCII control characters (0x00-0x1F and DEL), but doesn't handle Unicode control characters (e.g., U+0085 NEL, U+2028 Line Separator, U+2029 Paragraph Separator) that could also be used for log forging. Consider expanding the regex to [\x00-\x1F\x7F\u0080-\u009F\u2028\u2029] to cover additional control characters, or use [\p{Cc}] to match all Unicode control characters.
| [GeneratedRegex(@"[\x00-\x1F\x7F]")] | |
| [GeneratedRegex(@"[\x00-\x1F\x7F\u0080-\u009F\u2028\u2029]")] |
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.
The removal of the dotnet-ef tool from dotnet-tools.json appears unrelated to the stated purpose of this PR (preventing log forging and adding workflow permissions). While the project may be using EF Core (as evidenced by references in documentation), removing the Entity Framework tooling doesn't address any security issues. This change should either be reverted or explained in the PR description as a separate cleanup task.