-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Enhanced LogForgingQuery to treat C# Enums as simple types. #17866
base: main
Are you sure you want to change the base?
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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,4 @@ | ||||||
--- | ||||||
category: fix | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is as such not a "fix" but rather a change in, how we perceive enums. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. |
||||||
--- | ||||||
* Enhanced LogForgingQuery to treat C# Enums as simple types. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Net; | ||
using System.Web; | ||
using Microsoft.Extensions.Logging; | ||
|
||
class ILogger | ||
{ | ||
public void Warn(string message) { } | ||
} | ||
|
||
enum TestEnum | ||
{ | ||
TestEnumValue | ||
} | ||
|
||
public class LogForgingSimpleTypes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test code doesn't compile. Consider adding the test code in https://github.com/github/codeql/blob/main/csharp/ql/test/query-tests/Security%20Features/CWE-117/LogForging.cs Compilation issues:
|
||
{ | ||
public void Execute(HttpContext ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test cases doesn't test the simple type sanitization as the input to the logger are hardcoded constants and not a data flow source for the log forging query (maybe use the same pattern as in https://github.com/github/codeql/blob/main/csharp/ql/test/query-tests/Security%20Features/CWE-117/LogForging.cs) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interestingly, I have seen hardcoded Enums trigger this, but I will address this to use a true data flow source. |
||
{ | ||
// GOOD: int | ||
logger.Warn("Logging simple type (int):" 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you intend to concatenate? |
||
|
||
// GOOD: long | ||
logger.Warn("Logging simple type (int):" 1L); | ||
|
||
// GOOD: float | ||
logger.Warn("Logging simple type (float):" 1.1); | ||
|
||
// GOOD: double | ||
logger.Warn("Logging simple type (double):" 1.1d); | ||
|
||
// GOOD: decimal | ||
logger.Warn("Logging simple type (double):" 1.1m); | ||
|
||
// GOOD: Enum | ||
logger.Warn("Logging simple type (Enum):" TestEnum.TestEnumVAlue); | ||
|
||
// GOOD: DateTime | ||
logger.Warn("Logging simple type (int):" new DateTime()); | ||
|
||
// GOOD: DateTimeOffset | ||
logger.Warn("Logging simple type (int):" DateTimeOffset.UtcNow); | ||
} | ||
} |
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.
@hvitved : Do you know of any historical reason why we haven't considered enums as being sanitizers (I think it looks very reasonable that they should be considered sanitizers - but just checkin with you as this change has a wide impact)?