-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C# : Add query to detect SSRF #5110
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
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.
Thank you for implementing this check. I added some comments inline.
Also, in general, all HTTP request making APIs seem vulnerable to this attack. I think the most common ones are System.Net.Http.HttpClient
, System.Net.HttpWebRequest
( WebRequest.Create()
), and System.Net.WebClient
; and maybe handling the base classes would also be good, such as System.Net.Http.HttpMessageInvoker
. Finally, HttpClient
and WebClient
allow setting the BaseAddress
property, so flow into that should also be covered.
@tamasvajk I have added new sinks for the methods we discussed above. I have also squashed and rebased as the main had diverged quite a bit. |
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.
I think the check got a lot better, and could provide value. Here's a real use case that's found by it. However at the moment it's quite noisy:
- Most of the HTTP clients accept relative URLs too, and when data flows into a relative URL that should be fine. Maybe an option to overcome this would be to check if there's any assignment to the base address, such as here.
- There are some cases when data flows into the sinks through string concatenation, and not in the base address part of the string: https://lgtm.com/query/1044480058280809211/ or string interpolation.
- The implemented sanitizer is quite specific, there could be other ways to filter too. Let's see if the LGTM analysis shows any other recurring patterns.
@tamasvajk Sorry for the delay. I tried adding that. But now I get the following error message. Can you please help me figure this out? I have rebased this pr to the latest main and added the wip changes temporarily to help debugging.
|
@porcupineyhairs There are multiple issues here:
In fact, I gave the latter a quick try, and simplified your test to the below:
|
@tamasvajk Thanks a lot. The tests work fine now. I have pushed the new changes. PTAL. |
@porcupineyhairs I removed a test case above for simplicity. Could you please add the case with the sanitizer? Also, I'm unsure if you've already seen/covered the comments in #5110 (review). |
@tamasvajk I have made the changes now. I have also started a new run on the 61 projects which threw an alert in the earlier run. There are 12 independent projects. All of them appear to be TP. PTAL. |
@tamasvajk I have squashed and rebased to the latest main while this is pending review. |
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.
I've restarted the LGTM analysis: https://lgtm.com/query/5526907158523374183/
@tamasvajk Changes done! |
@hvitved Could you please also have a final look at this PR? |
@hvitved Sorry for the delay is responding to your comments. I have made some changes now. PTAL. |
The tests are failing:
|
@tamasvajk Changes done! PTAL. |
@porcupineyhairs I think you might have forgotten to push your changes. The last commit in this PR is from July, and since then @hvitved also provided some feedback. Could you please double check? |
@tamasvajk @hvitved Yes, indeed, that was the case, I didn't push the changes here properly. I have rebased to the latest main and forced pushed the changes now. PTAL. |
The
|
@hvitved It seems like the |
@tamasvajk Changes done! |
@tamasvajk Any updates here? |
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.
@porcupineyhairs Thank you for this contribution.
This query adds support for detecting Server Side Request Forgery(SSRF) vulnerabilities in C#. This has at least one valid detection in chhans/Kurs19_Public.
I am working on adding a few more sinks. I am new to C#. Can someone tell me which libraries would be good to include here?