Repository navigation
Conversation
1 task done
…WE-426) queries with tests Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add new query for SSRF, reflection, and command injection
[NEW QUERY] C#: cs/unsafe-reflection (CWE-470) and cs/untrusted-search-path (CWE-426)
Oct 31, 2026
There was a problem hiding this comment.
🟡 Changes recommended
The queries can miss real vulnerabilities because method-name-only allowlist matching suppresses unsafe-reflection alerts and the extension filter excludes PATH-resolved Unix executables.
2 open issues
What changed in this PR
Adds two medium-precision C# security queries to the custom CodeQL pack, addressing issue #291’s gaps in detecting user-controlled reflection and process launches through the search path.
Changes:
- Adds
cs/unsafe-reflectionwith threat-model sources and allowlist barriers. - Adds
cs/untrusted-search-pathto track bare program names into process-launch APIs. - Includes documentation, positive and negative test cases, and expected path results.
| File | Description |
|---|---|
languages/csharp/custom/test/UntrustedSearchPath/UntrustedSearchPath.qlref |
Connects the query to inline-expectation tests. |
languages/csharp/custom/test/UntrustedSearchPath/UntrustedSearchPath.expected |
Records expected search-path alerts and flow paths. |
languages/csharp/custom/test/UntrustedSearchPath/Test.cs |
Covers bare names, qualified paths, and helper calls. |
languages/csharp/custom/test/UntrustedSearchPath/options |
Adds process API references for test extraction. |
languages/csharp/custom/test/UnsafeReflection/UnsafeReflection.qlref |
Connects the reflection query to inline-expectation tests. |
languages/csharp/custom/test/UnsafeReflection/UnsafeReflection.ext.yml |
Enables local threat-model sources in tests. |
languages/csharp/custom/test/UnsafeReflection/UnsafeReflection.expected |
Records expected reflection alerts and flow paths. |
languages/csharp/custom/test/UnsafeReflection/Tests.cs |
Covers reflection APIs and allowlist examples. |
languages/csharp/custom/test/UnsafeReflection/Program.cs |
Reproduces command-line-controlled type selection. |
languages/csharp/custom/test/UnsafeReflection/options |
Adds framework references for test extraction. |
languages/csharp/custom/src/UntrustedSearchPath/UntrustedSearchPath.ql |
Implements bare-program-name flow analysis. |
languages/csharp/custom/src/UntrustedSearchPath/UntrustedSearchPath.md |
Documents search-path risks and safer launches. |
languages/csharp/custom/src/UnsafeReflection/UnsafeReflection.ql |
Implements reflection taint tracking and barriers. |
languages/csharp/custom/src/UnsafeReflection/UnsafeReflection.md |
Documents reflection risks and safe type mappings. |
Review effort: Balanced
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

📝 Query Information
cs/unsafe-reflection,cs/untrusted-search-path@precision medium; security-severity 6.5 and 6.7)cs/unsafe-reflection); CWE-426 and CWE-427 (cs/untrusted-search-path)🎯 Description
An AI scan found two C# patterns that baseline CodeQL does not report. The first resolves and instantiates a type named by the user. The second starts a program by its bare name, so the OS looks it up through the search path. I reproduced both in test databases. The stock
security-extendedsuite, run with--threat-model local, reports neither pattern. Its only result is an unrelatedcs/command-line-injectionalert on one of the safe examples. These queries are medium precision, so they are aimed at Community Packs rather than github/codeql.What This Query Detects
cs/unsafe-reflection(taint tracking)Type.GetType,Type.GetTypeFromProgID,Assembly.GetType/Module.GetType,Assembly.CreateInstance,Activator.CreateInstance/CreateInstanceFrom(string overloads) andAppDomain.CreateInstance*.Contains/ContainsKey, or==/!=/Equalsagainst a string constant. Dictionary lookups break the flow on their own.localsource. It is reported only when thelocalthreat model is enabled.Type.GetType(...)), not the laterActivator.CreateInstance(type)that the AI scan flagged.cs/untrusted-search-path(data flow)readme.txt, are excluded. Names ending in.exe,.com,.bator.cmdare kept.ProcessStartInfo.FileName, including object initializers, plus thefileNameargument ofnew ProcessStartInfo(...)and of staticProcess.Start(...).if/else(the JulietBad()case) or passed through a helper method produces one path per literal.gitordotnet, will be flagged.Example Vulnerable Code
Example Safe Code
🧪 Testing
Tests use inline expectations (
// $ Alert/// $ Source).UnsafeReflection.ext.ymlturns on thelocalthreat model, which covers argv, environment variables and stdin.optionsfile that adds references the test compiler is missing, such asSystem.Diagnostics.Process.dll.Main.📋 Checklist
.mdand.qhelp):.mdonly, no.qhelpadded🔗 References
cs/untrusted-search-pathtest reproduces JulietCWE426_Untrusted_Search_Path__Process_01.Note: This query was developed using Test-Driven Development methodology.