Skip to content

[Query Create]: CWE-426, CWE-470 MEDIUM - C#: new query for SSRF, reflection and command injection #291

Open

Description

@felickz

Target Language

csharp

Query Name (Optional)

SsrfReflectionInjection

Query Type

Security

Query Description

AI Scan reported 2 medium-severity CWE-426, CWE-470 (ssrf reflection injection) finding(s) in C# public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-query, query-absent. Existing queries considered: none.

Why CodeQL appears to have missed these (unverified until reproduced with a test database):

  • The installed security-extended suite has no C# query for attacker-selected reflection or Activator.CreateInstance targets.
  • Process started by bare executable name (untrusted search path) has no C# query; issue covers CWE-426 family.

Linked findings (gap-key: csharp/query-create/ssrf-reflection-injection)

Repo CWE Severity AI scan alert Summary
scan-testing CWE-470 medium https://github.com/codeql-forks-felickz/scan-testing/security/code-scanning/7 The program resolves a type name from a command-line argument and instantiates it with Activator.CreateInstance. This permits loading and constructing arbitrary available types, including constructor side effects, rather than enforcing an allowlist.
NIST-Juliet-CSharp-1.3 CWE-426 medium https://github.com/codeql-forks-felickz/NIST-Juliet-CSharp-1.3/security/code-scanning/4248 The application starts ls or cmd.exe by bare name rather than by a trusted absolute path. A local attacker who can place a same-named executable earlier in the service's search path can cause their binary to execute with the application's privileges.

Findings come from AI Scan on public synthetic apps. Hypotheses above are unverified until reproduced with a test database. Verify first whether CodeQL already covers a case (for example via a different query or threat model) before adding code.

Handling decision

  • Type: Query Create
  • Decision: Create a new CodeQL query. No existing query covers these patterns (most findings are gap type query-absent or missing-query). Because coverage of lower-severity patterns can be heuristic, target Community Packs unless precision is shown to be high enough for github/codeql.
  • Recommended actions across the findings: write-new-query (2)

Patterns in this gap

  • missing-query (1 finding), for example scan-testing Oopsies/CtorIsBoring/Program.cs
  • query-absent (1 finding), for example NIST-Juliet-CSharp-1.3 src/src/testcases/CWE426_Untrusted_Search_Path/CWE426_Untrusted_Search_Path__Process_01.cs

Finding details

Each finding below has its own context so the agent can work from this issue alone.

1. scan-testing Oopsies/CtorIsBoring/Program.cs:4 (CWE-470, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/scan-testing/security/code-scanning/7
  • AI Scan message: The program resolves a type name from a command-line argument and instantiates it with Activator.CreateInstance. This permits loading and constructing arbitrary available types, including constructor side effects, rather than enforcing an allowlist.
  • Why CodeQL appears to miss it: missing-query: The installed security-extended suite has no C# query for attacker-selected reflection or Activator.CreateInstance targets.
  • Recommended action from the comparison: write-new-query (classification confidence: high)
2. NIST-Juliet-CSharp-1.3 src/src/testcases/CWE426_Untrusted_Search_Path/CWE426_Untrusted_Search_Path__Process_01.cs:49 (CWE-426, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/NIST-Juliet-CSharp-1.3/security/code-scanning/4248
  • AI Scan message: The application starts ls or cmd.exe by bare name rather than by a trusted absolute path. A local attacker who can place a same-named executable earlier in the service's search path can cause their binary to execute with the application's privileges.
  • Context for the agent: In NIST-Juliet-CSharp-1.3 at src/src/testcases/CWE426_Untrusted_Search_Path/CWE426_Untrusted_Search_Path__Process_01.cs:49, The application starts ls or cmd.exe by bare name rather than by a trusted absolute path. A local attacker who can place a same-named executable earlier in the service's search path can cause their binary to execute with the application's privileges. CodeQL would need: Process started by bare executable name (untrusted search path) has no C# query; issue covers CWE-426 family.
  • Why CodeQL appears to miss it: query-absent: Process started by bare executable name (untrusted search path) has no C# query; issue covers CWE-426 family.
  • Recommended action from the comparison: write-new-query (classification confidence: low)

Expected Severity

Medium

Code Examples

See the linked alerts above for the vulnerable pattern; reduce each to a minimal test case with a safe counterpart that should not alert.

CWE/CVE Reference (Optional)

CWE-426, CWE-470

References (Optional)

https://cwe.mitre.org/data/definitions/426.html

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    enhancement
    severity:medium
    on Oct 31, 2026
  2. added
    precision:low
    tags:experimental
    on Nov 3, 2026
  3. felickz commented on Nov 3, 2026

    @felickz
    Author

    Upstream triage

    precision:low Audit-grade or weak signal. Community Packs, always tags:experimental. tags:experimental Goes to Community Packs: performance, false-positive or synthetic-only concerns.

    Community Packs, experimental. Recommended for the Community Packs repository, not github/codeql. The issue is labeled tags:experimental for this.

    Linked pull request: #341

    Why. Two new queries with no C# equivalent upstream (the Java reflection analog is still experimental). cs/untrusted-search-path reports every Process.Start of a bare tool name such as git or ping and picks sources by regexp over all string literals, so it is audit grade. cs/unsafe-reflection uses exact Type, Activator and Assembly sinks, but its tests only run under the local threat model. Both fit Community Packs as experimental.

    Change New query
    Target New C# queries cs/unsafe-reflection (CWE-470) and cs/untrusted-search-path (CWE-426)
    Precision assessed low (declared medium in the pull request). cs/untrusted-search-path flags every bare-name Process.Start or ProcessStartInfo literal (git, ping, netstat) via regexps on string literals: audit grade. cs/unsafe-reflection is nearer high (BCL sinks, allow-list barriers) but its tests only cover the local threat model.
    Real-world basis partial. Public APIs: System.Type.GetType, Assembly.CreateInstance, Activator.CreateInstance, AppDomain.CreateInstance*, System.Diagnostics.Process and ProcessStartInfo. Tests come from Juliet and a console sample; no remote-source reflection test.
    Stock overlap none. No C# CWE-470 or CWE-426 query upstream (code search). Closest is the Java UnsafeReflection query, still under experimental; Community Packs has a Java UnsafeReflection and no CWE-426 query.
    Concerns, overlap and next steps

    False-positive concerns

    • cs/untrusted-search-path reports every Process.Start of a bare tool name such as git or ping, whether or not the search path is attacker-influenced
    • Reflection allow-list barrier trusts any collection Contains or dictionary ContainsKey call, even on a list that is not a fixed allow list
    • With the local threat model enabled, plugin type names read from environment or stdin by design are reported

    Performance concerns

    • cs/untrusted-search-path runs regexpMatch on every string literal in the database to choose sources
    • Any identifier-like literal (keys, names, headers) becomes a global data flow source, giving a very large source set

    Heuristics used

    • Regexps on string values decide what is a bare executable name
    • Extension list exe, com, bat, cmd decides what counts as a program
    • BCL parameter names assemblyName, assemblyFile, typeName matched for sinks
    • Any Contains or ContainsKey on collection types treated as an allow list

    What an upstream change would look like. Community Packs csharp/src/security/CWE-470/UnsafeReflection.ql and csharp/src/audit/UntrustedSearchPath.ql (audit grade), each with qhelp and tests under csharp/test; submit as two PRs.

    Before opening an upstream pull request

    • Split into two PRs: cs/unsafe-reflection first, cs/untrusted-search-path as an audit query
    • Add a remote-source test (for example an ASP.NET request parameter) for cs/unsafe-reflection; current tests need the local threat model
    • Show at least one true positive per query on a real project revision; evidence is Juliet and a console sample
    • For the search path query, avoid the all-literal source set (start from the sink) and measure runtime on a large database
    • Document that the command-line finding needs the local threat model; the default remote model will not report it

    Split note. cs/unsafe-reflection is nearer high precision, but it is a new query and the Java equivalent is still experimental upstream, so both queries go to Community Packs. cs/untrusted-search-path is audit grade; submit the two separately.

    This is a recommendation only. A human reviews it before any pull request is opened against github/codeql or the Community Packs repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CWE-426CWE-470enhancementprecision:lowquery-createseverity:mediumtags:experimental

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions