-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C#: Improve some existing manual models. #19940
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
base: main
Are you sure you want to change the base?
Conversation
822992d
to
8256741
Compare
Click to show differences in coveragecsharpGenerated file changes for csharp
- System,"``System.*``, ``System``",47,12139,54,5
+ System,"``System.*``, ``System``",47,12165,54,5
- Totals,,107,14403,407,9
+ Totals,,107,14429,407,9
- System,54,47,12139,,6,5,5,,,4,1,,33,2,,6,15,17,4,3,,5903,6236
+ System,54,47,12165,,6,5,5,,,4,1,,33,2,,6,15,17,4,3,,5929,6236 |
8256741
to
c60a040
Compare
…the other models).
…Reader models to manual models.
…yReader.CreateBinaryReader.
c60a040
to
822486e
Compare
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.
Pull Request Overview
This PR enhances security test queries by converting deserialization tests to inline alert annotations and improves the library’s manual summary models to reduce false negatives.
- Converted multiple unsafe/unsafe-untrusted-deserialization tests to use inline
// $ Alert[...]
comments. - Renamed and expanded binary‐formatter test classes for broader coverage.
- Added and refined summary models for
XmlDictionaryReader.CreateBinaryReader
,Encoding.GetBytes
/GetChars
,MemoryStream
constructors, and serialization APIs.
Reviewed Changes
Copilot reviewed 22 out of 29 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
csharp/ql/test/query-tests/Security Features/CWE-502/UnsafeDeserializationUntrustedInputNewtonsoftJson/Test.cs | Moved JSON unsafe-deserialization alert to inline comment. |
csharp/ql/test/query-tests/Security Features/CWE-502/UnsafeDeserializationUntrustedInput/XmlSerializerUntrustedInputBad.cs | Added inline alert annotation after the return call. |
csharp/ql/test/query-tests/Security Features/CWE-502/UnsafeDeserializationUntrustedInput/BinaryFormatterUntrustedInputBad.cs | Renamed BadBinaryFormatter class and added a second test class. |
csharp/ql/src/change-notes/2025-07-01-improve-summary-models.md | Documented the new and updated summary models. |
csharp/ql/lib/ext/System.Xml.model.yml | Added summary models for all XmlDictionaryReader.CreateBinaryReader overloads. |
csharp/ql/lib/ext/System.Text.model.yml | Updated taint mappings for Encoding.GetBytes /GetChars . |
csharp/ql/lib/ext/System.Runtime.Serialization.model.yml | Added models for SerializationInfo and SerializationInfoEnumerator . |
csharp/ql/lib/ext/System.IO.model.yml | Adjusted MemoryStream taint model to use .Element for byte arrays. |
Files not reviewed (7)
- csharp/ql/test/library-tests/dataflow/library/FlowSummaries.expected: Language not supported
- csharp/ql/test/library-tests/dataflow/library/FlowSummariesFiltered.expected: Language not supported
- csharp/ql/test/query-tests/Security Features/CWE-502/DeserializedDelegate/DeserializedDelegate.qlref: Language not supported
- csharp/ql/test/query-tests/Security Features/CWE-502/UnsafeDeserialization/UnsafeDeserialization.qlref: Language not supported
- csharp/ql/test/query-tests/Security Features/CWE-502/UnsafeDeserializationUntrustedInput/UnsafeDeserializationUntrustedInput.expected: Language not supported
- csharp/ql/test/query-tests/Security Features/CWE-502/UnsafeDeserializationUntrustedInput/UnsafeDeserializationUntrustedInput.qlref: Language not supported
- csharp/ql/test/query-tests/Security Features/CWE-502/UnsafeDeserializationUntrustedInputNewtonsoftJson/UnsafeDeserializationUntrustedInput.qlref: Language not supported
Comments suppressed due to low confidence (2)
csharp/ql/test/query-tests/Security Features/CWE-502/UnsafeDeserializationUntrustedInputNewtonsoftJson/Test.cs:17
- The
$ Alert
annotation is placed on theJsonSerializerSettings
line rather than on theDeserializeObject
invocation itself. Move the inline comment to the line starting withreturn JsonConvert.DeserializeObject(...)
to ensure the test framework picks up the alert.
return JsonConvert.DeserializeObject(data.Text, new JsonSerializerSettings // $ Alert[cs/unsafe-deserialization-untrusted-input]
csharp/ql/test/query-tests/Security Features/CWE-502/UnsafeDeserializationUntrustedInput/BinaryFormatterUntrustedInputBad.cs:7
- The test harness expects a class named
BadBinaryFormatter
, but this has been renamed toBadBinaryFormatter1
. Rename it back toBadBinaryFormatter
to maintain compatibility with the test matcher.
class BadBinaryFormatter1
In this PR we improve the models as data modelling across multiple classes.
System.Xml.XmlDictionaryReader.CreateBinaryReader
.System.Runtime.Serialization.SerializationInfo
andSystem.Runtime.Serialization.SerializationInfoEnumerator
.System.Text.Encoding.GetBytes
,System.Text.Encoding.GetChars
and the constructor forSystem.IO.MemoryStream
.Also convert the deserialization tests to inline expectations.
The new findings in
mono/mono
forcs/cleartext-storage-of-sensitive-information
andcs/exposure-of-sensitive-information
are both related to the improved models forGetBytes
(where taint is propagated to another parameter instead of the return).