-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C#: Add implicit System.Collections.Generic.KeyValuePair2.Value reads at taint sinks
#21024
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
C#: Add implicit System.Collections.Generic.KeyValuePair2.Value reads at taint sinks
#21024
Conversation
System.Collections.Generic.KeyValuePair2.Value` at taint sinksSystem.Collections.Generic.KeyValuePair2.Value` reads at taint sinks
System.Collections.Generic.KeyValuePair2.Value` reads at taint sinksSystem.Collections.Generic.KeyValuePair2.Value reads at taint sinks
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 adds implicit reads of System.Collections.Generic.KeyValuePair<TKey,TValue>.Value property at taint sinks in C# to align taint tracking behavior with Java's MapValueContent handling. This change makes it easier to write cross-language queries and ensures consistent behavior when taint tracking encounters dictionary-like collections at sinks.
Key Changes:
- Added implicit taint read for
KeyValuePair.Valueproperty at sinks - Refactored test infrastructure to share common configuration
- Added test case demonstrating the new implicit read behavior
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
csharp/ql/lib/semmle/code/csharp/dataflow/internal/TaintTrackingPrivate.qll |
Core implementation adding KeyValuePair.Value to implicit taint reads |
csharp/ql/test/library-tests/dataflow/collections/CollectionFlowCommon.qll |
New shared test configuration module |
csharp/ql/test/library-tests/dataflow/collections/CollectionTaintFlow.ql |
New test query for taint flow validation |
csharp/ql/test/library-tests/dataflow/collections/CollectionDataFlow.ql |
Refactored to use common configuration |
csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.cs |
Added test case for implicit map value read |
csharp/ql/test/library-tests/dataflow/collections/CollectionTaintFlow.expected |
Expected test results |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
C# needs to do it this way because C# maps implement |
Oh yeah no hate towards the way C# does it. The strategy totally makes sense. I'm just saying this additional quirk makes it harder for people to write "the same" query for both Java and C#. |
hvitved
left a comment
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.
LGTM (assuming DCA is good).
|
DCA looked uneventful |
Java includes
MapValueContentin the set of implicit taint reads (see here), but C# doesn't.This leads to some developer confusion when trying to write the same query for both Java and C#. Additionally, C# uses the
System.Collections.Generic.KeyValuePair.Valueproperty (+ anElementContent) to model the equivalent of aMapValueContentin Java which makes it even more mysterious when translating a query from Java to C#.This PR fixes this problem by adding implicit reads of
System.Collections.Generic.KeyValuePair.Value. This means that C# and Java behaves (hopefully) similarly when taint-tracking ends up with a "map-like" collection at a sink.cc @hvitved