Skip to content

    Type a page, a command such as keryn scan, or a rule id.

    general-injection-csharp-v1

    View as Markdown

    9 rules · Keryn Software Licence · rules 0.8.0 · all packs

    How to read a rule
    Severity
    How bad the finding is if it is real: error fails a default gate, warning and info do not.
    Confidence
    P0 exploitable as written; P1 dangerous in context; P2 a heuristic or a posture check: confirm by reading the code.
    False-positive risk
    low: an exact API or flag, so hits are almost always real; medium: the pattern is legitimate in many programs, so check each hit; high: it finds a lead to confirm, so expect benign hits.
    Edge
    The relationship the finding sits on. reaches: content or traffic gets to a thing; calls: one thing invokes another; reads: one thing reads from another; writes: one thing writes to another; sends: data leaves for another party; grants: authority is given or left unchecked; depends_on: something relies on a component it does not verify; trusts: one party believes another without evidence. The boundary it crosses, when there is one: user->prompt (untrusted input reaching a prompt); model->code (model output reaching code, a shell, a query or a page); secret->outside (a secret leaving the trusted side); supply-chain (code, models or prompts pulled in from outside).
    Taxonomy chips
    References for readers who work in OWASP LLM 2025, OWASP Agentic, CWE or NIST AI RMF. They say where a rule belongs, not that a framework is satisfied.

    keryn.general.csharp.path-traversal-request-to-file

    Section titled “keryn.general.csharp.path-traversal-request-to-file”

    error csharp data-flow rule csharp, aspnet-core, mvc

    A request value reaches a file read, write, delete or file-download call without being reduced to a file name or checked against the base directory. A value such as ..\..\secret escapes the intended folder. Use Path.GetFileName, or Path.GetFullPath and verify StartsWith(baseDir) before opening.

    Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.

    Edge inspected: reaches content or traffic gets to a thing; it crosses the user->prompt boundary (untrusted input reaching a prompt).

    CWE-22 LLM05

    Fix: Take only Path.GetFileName(name), or combine with the base directory, call Path.GetFullPath and refuse the request unless the result StartsWith the base directory plus a separator. Prefer an id resolved through a lookup table.

    References: https://learn.microsoft.com/en-us/dotnet/api/system.io.path.getfullpath · https://learn.microsoft.com/en-us/aspnet/core/mvc/models/model-binding

    error csharp data-flow rule csharp, system-io-compression

    An archive entry name (ZipArchiveEntry.FullName / Name, TarEntry.Name) is used to build the output path of a file that is created. A crafted entry with ../ writes outside the extraction folder (Zip Slip). Resolve with Path.GetFullPath and verify the result starts with the destination folder before creating the file.

    Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.

    Edge inspected: reads one thing reads from another.

    CWE-22 LLM05

    Fix: Compute var full = Path.GetFullPath(Path.Combine(dest, entry.FullName)); throw unless full.StartsWith(Path.GetFullPath(dest) + Path.DirectorySeparatorChar) before File.Create / ExtractToFile.

    References: https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.fullname

    keryn.general.csharp.sql-injection-request-to-query

    Section titled “keryn.general.csharp.sql-injection-request-to-query”

    error csharp data-flow rule csharp, aspnet-core, ado-net, ef-core, dapper

    A request value is concatenated, formatted or interpolated into SQL text that is executed by ADO.NET, Dapper or EF Core raw SQL. The value can change the query. Use parameters (@name with SqlParameter / Parameters.Add), FromSqlInterpolated or ExecuteSqlInterpolated, and keep the SQL text constant.

    Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.

    Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-89 LLM05

    Fix: Write the statement as a constant string with @parameters and add SqlParameter values (cmd.Parameters.Add), or use EF Core FromSqlInterpolated / ExecuteSqlInterpolated which bind interpolated values. Do not use FromSqlRaw or ExecuteSqlRaw with an interpolated or concatenated string.

    References: https://learn.microsoft.com/en-us/dotnet/api/microsoft.data.sqlclient.sqlcommand.parameters · https://learn.microsoft.com/en-us/ef/core/querying/sql-queries

    keryn.general.csharp.xss-request-to-html-output

    Section titled “keryn.general.csharp.xss-request-to-html-output”

    warning csharp data-flow rule csharp, aspnet-core, razor

    A request value is written into an HTML response without encoding (Response.Write, a text/html Content result, HtmlString, Html.Raw). The value runs as markup or script in the visitor’s browser. Encode with HtmlEncoder.Default.Encode, WebUtility.HtmlEncode or HttpUtility.HtmlEncode, or render through Razor which encodes by default.

    Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.

    Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-79 LLM05

    Fix: Encode request-derived text for the context it lands in (HtmlEncoder, JavaScriptEncoder, UrlEncoder) or return it through a Razor view. Avoid HtmlString/Html.Raw and text/html Content results built from input; sanitise rich input with a library such as HtmlSanitizer.

    References: https://learn.microsoft.com/en-us/aspnet/core/security/cross-site-scripting

    keryn.general.csharp.ssrf-request-to-http-client

    Section titled “keryn.general.csharp.ssrf-request-to-http-client”

    warning csharp data-flow rule csharp, aspnet-core, httpclient

    A request value decides which URL the server requests through HttpClient, WebClient or WebRequest. An attacker can reach internal services, cloud metadata or loopback. Parse the URL, require https, compare the host to an allow-list and reject private and loopback addresses before sending.

    Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.

    Edge inspected: reaches content or traffic gets to a thing; it crosses the user->prompt boundary (untrusted input reaching a prompt).

    CWE-918 LLM05

    Fix: Do not pass a user supplied string as a request URL. Accept an id mapped to a fixed URL, or parse with Uri.TryCreate, require Scheme == https, check Host against an allow-list, resolve and reject non-public IPs, and disable auto-redirect or re-validate each hop.

    References: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient · https://learn.microsoft.com/en-us/dotnet/api/system.uri.host

    keryn.general.csharp.command-injection-request-to-shell

    Section titled “keryn.general.csharp.command-injection-request-to-shell”

    error csharp data-flow rule csharp, aspnet-core

    A request value is run as an operating system command, either as the program in Process.Start / ProcessStartInfo or as the command text of a shell (cmd /c, bash -c). The value can append further commands. Start a fixed executable and pass arguments through ProcessStartInfo.ArgumentList.

    Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.

    Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-78 LLM05

    Fix: Use new ProcessStartInfo(“tool”) with UseShellExecute = false and add each argument via ArgumentList; never concatenate input into a cmd /c or bash -c string. Validate arguments against an allow-list.

    References: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo

    keryn.general.csharp.csrf-antiforgery-disabled

    Section titled “keryn.general.csharp.csrf-antiforgery-disabled”

    warning csharp csharp, aspnet-core, mvc, minimal-api

    Antiforgery validation is turned off for an action, endpoint or the whole MVC filter set. Cookie- authenticated state-changing requests can then be forged from another site. Remove the opt-out, or restrict it to endpoints that authenticate with a bearer token rather than a cookie.

    Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.

    Edge inspected: calls one thing invokes another.

    CWE-352 LLM05

    Fix: Keep [ValidateAntiForgeryToken] or the global AutoValidateAntiforgeryTokenAttribute filter on cookie-authenticated actions. Use [IgnoreAntiforgeryToken] / DisableAntiforgery() only on token- authenticated API endpoints that never read the auth cookie.

    References: https://learn.microsoft.com/en-us/aspnet/core/security/anti-request-forgery

    keryn.general.csharp.sql-built-from-variable

    Section titled “keryn.general.csharp.sql-built-from-variable”

    warning csharp csharp, ado-net, ef-core, dapper

    The SQL text of this command is assembled from a variable by concatenation, string.Format or an interpolated string, so whatever the variable holds becomes part of the statement. Keep the SQL constant and bind values with parameters (SqlParameter, Dapper anonymous objects, FromSqlInterpolated / ExecuteSqlInterpolated).

    Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.

    Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).

    CWE-89 LLM05

    Fix: Use a constant command text with @name parameters (cmd.Parameters.Add) or Dapper parameters. With EF Core use FromSqlInterpolated / ExecuteSqlInterpolated, or FromSqlRaw with DbParameter arguments, never an interpolated string passed to FromSqlRaw / ExecuteSqlRaw. Identifiers cannot be parameters: map them from an allow-list.

    References: https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand.parameters · https://learn.microsoft.com/en-us/ef/core/querying/sql-queries · https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html

    keryn.general.csharp.insecure-deserialization-javascriptserializer-typeresolver

    Section titled “keryn.general.csharp.insecure-deserialization-javascriptserializer-typeresolver”

    error csharp csharp, aspnet, javascriptserializer

    JavaScriptSerializer is built with SimpleTypeResolver, so the __type member in the JSON picks the instantiated class. Untrusted JSON can then create arbitrary types. Construct the serializer without a type resolver.

    Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.

    Edge inspected: depends_on something relies on a component it does not verify; it crosses the supply-chain boundary (code, models or prompts pulled in from outside).

    CWE-502 LLM03

    Fix: Use new JavaScriptSerializer() with no resolver, or move to System.Text.Json. If a custom JavaScriptTypeResolver is unavoidable, make it allow only a fixed list of types.

    References: https://learn.microsoft.com/en-us/dotnet/api/system.web.script.serialization.simpletyperesolver