-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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#: update MaD for HttpRequestMessage and UriBuilder #18694
base: main
Are you sure you want to change the base?
Conversation
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.
PR Overview
This pull request updates taint flow modeling for HttpRequestMessage and UriBuilder in C#, ensuring that constructed or updated URIs are appropriately recognized as tainted for SSRF and path traversal checks.
- Fixes regression for HttpRequestMessage constructors taking a Uri parameter, aligning them with taint flow from string-based constructors
- Adds taint flow to newly modeled UriBuilder constructors and properties
Changes
File | Description |
---|---|
csharp/ql/lib/ext/System.model.yml | Adds UriBuilder taint flow for multiple constructors, properties, & ToString |
csharp/ql/lib/change-notes/2025-02-05-update-system.net.http.httprequestmessage-and-system.uribuilder-models.md | Documents the minor analysis changes for HttpRequestMessage & UriBuilder |
csharp/ql/lib/ext/System.Net.Http.model.yml | Fixes taint flow regression for HttpRequestMessage constructor with Uri |
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more
Click to show differences in coveragecsharpGenerated file changes for csharp
- System,"``System.*``, ``System``",47,10864,54,5
+ System,"``System.*``, ``System``",47,10896,54,5
- Totals,,108,12946,400,9
+ Totals,,108,12978,400,9
- System,54,47,10864,,6,5,5,,,4,1,,33,2,,6,15,17,4,3,,5547,5317
+ System,54,47,10896,,6,5,5,,,4,1,,33,2,,6,15,17,4,3,,5579,5317 |
DCA has been run for this PR (if we got the settings correct; not sure what you typically use). There were no changes to results. |
It looks like the regression happened after re-generating the models: #17666 |
If we want to model the URIBuilder class manually, I think we should go for a solution that uses the (1) properties of the builder or (2) a less precise solution which taints the entire object (as it was the case before with the generated models). Personally, I would favor (1) as we might risk false positives due to field conflation.
|
@michaelnebel UriBuilder is complicated in terms of modeling, since multiple properties are tainted by the constructor parameters. Taking the constructor with the most parameters as an example:
When I tried the suggested change to have the sink use the appropriate parameters and also tried both of the following for
Does MaD support modeling taint to multiple properties/sinks? If not, should I use |
Yes, it does get a bit involved to do the modelling - and you are right the models referring to the
The same pattern is then needed for the constructors that "taints" all properties, eg
The (other) simpler approach is simply to say that the entire object is tainted if any property is set. However, this carries the risk of false positives. Since, we didn't have a single example in our DCA codebase (and actually in our entire 5k repo suite, where we noticed this regressions), it is probably acceptable to go with the simpler solution (which will require less modelling). |
I think shorthand notation like this will work as well
|
@michaelnebel Excellent, did not realize multiple properties could be modeled like that! Updated PR using the shorthand notation (it worked for me @hvitved). Thank you! We may open-source parts of the Microsoft SSRF queries in the future, so I went ahead with the more detailed modeling. |
Update MaD for C# related to SSRF and URL path traversal scenarios. Some of these are regressions from 2.19.4 to 2.20.0 upgrade, some were missing models.
HttpRequestMessage
Change model so constructor for
Uri
parameter matchesstring
parameter, where the taint is to the object instead of an internal synthetic field (regression)Example:
UriBuilder
Change model for constructor so it flows to synthetic
_uri
field, which is used in theget_Uri
model, so there is taint flow from the constructor toget_Uri
Add missing variants of the constructor
Add get/set property methods to support dataflow for MemberInitializer in ObjectInitializer
Examples: