Skip to content

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

    general-injection-go-v1

    View as Markdown

    7 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.go.path-traversal-request-to-file

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

    error go data-flow rule go, net-http, gin, echo, chi, gorilla-mux

    A request value reaches a file open, read, write, remove or ServeFile call without being reduced to a base name or confined to a directory. Sequences such as ../ escape the intended folder. Use filepath.Base, or clean a rooted path and verify strings.HasPrefix(full, base) / filepath.Rel 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 filepath.Base(name), or join with a rooted clean (filepath.Clean(“/”+name)) and then confirm the result still has the base directory as prefix (or that filepath.Rel does not start with ..). On Go 1.20+ filepath.IsLocal rejects escaping paths. Prefer an id mapped to a path server-side.

    References: https://pkg.go.dev/path/filepath#Clean · https://pkg.go.dev/path/filepath#Rel · https://pkg.go.dev/net/http#ServeFile

    error go data-flow rule go, archive-zip, archive-tar

    An archive entry name (zip File.Name or tar Header.Name) is used to build the destination of a created file. A crafted name with ../ writes outside the extraction directory (Zip Slip). Join with the destination, then verify the result still starts with the destination directory before creating it.

    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 target := filepath.Join(dest, f.Name), then fail unless strings.HasPrefix(target, filepath.Clean(dest)+string(os.PathSeparator)) before os.OpenFile / os.MkdirAll.

    References: https://pkg.go.dev/archive/zip#File · https://pkg.go.dev/path/filepath#Rel

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

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

    error go data-flow rule go, database-sql, sqlx, gorm

    A request value is formatted or concatenated into SQL text passed to database/sql, sqlx or GORM. The value can change the query. Keep the SQL constant with $1 / ? placeholders and pass values as arguments.

    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 db.Query(“SELECT … WHERE id = $1”, id) (or ? for MySQL/SQLite) and never build the statement with fmt.Sprintf or +. Identifiers cannot be bound: map them to a fixed allow-list.

    References: https://pkg.go.dev/database/sql#DB.Query · https://gorm.io/docs/security.html

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

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

    error go data-flow rule go, os-exec

    A request value is run as a command: as the program passed to exec.Command, or as the script of a shell (sh -c, cmd /c). The value can inject further commands. Run a fixed binary and pass each argument as its own exec.Command argument, validating it against an allow-list.

    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: Call exec.Command(“tool”, “–flag”, arg) with a constant program and separate arguments; never pass input to sh -c or cmd /c. Validate arguments against a strict pattern and place – before positional values where supported.

    References: https://pkg.go.dev/os/exec#Command

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

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

    warning go data-flow rule go, net-http, resty

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

    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: Never hand a user supplied URL to http.Get or NewRequest. Accept an id mapped to a fixed URL, or parse with url.Parse, check Scheme == “https” and Host against an allow-list, resolve and reject non-public IPs, and pin the dialled IP in a custom Transport (also covers redirects).

    References: https://pkg.go.dev/net/http#Get · https://pkg.go.dev/net/http#NewRequestWithContext

    keryn.general.go.xss-request-to-response-writer

    Section titled “keryn.general.go.xss-request-to-response-writer”

    warning go data-flow rule go, net-http, gin, echo

    A request value is written to the HTTP response without HTML escaping. Go sniffs the content type and serves markup as text/html, so the value runs as script in the visitor’s browser. Render through html/template (auto-escaping) or escape with html.EscapeString / template.HTMLEscapeString.

    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: Use html/template (never text/template) for pages, or escape with html.EscapeString before writing; set Content-Type: text/plain and X-Content-Type-Options: nosniff for plain responses. Sanitise rich input with a policy such as bluemonday.

    References: https://pkg.go.dev/html/template · https://pkg.go.dev/html#EscapeString

    warning go go, database-sql, sqlx, gorm

    SQL text is assembled from a variable with fmt.Sprintf or + and passed to database/sql, sqlx or GORM, or a format string that reads as SQL has %s / %v holes. Whatever the variable holds becomes part of the statement. Keep the SQL constant with $1 / ? placeholders and pass values as arguments; pick table and column names from a fixed list.

    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: Pass values as query arguments: db.Query(“SELECT … WHERE id = $1”, id). For identifiers that cannot be bound (table, column, sort order), map the input to a fixed set of names and quote them with the driver’s identifier quoting (pq.QuoteIdentifier).

    References: https://go.dev/doc/database/sql-injection · https://pkg.go.dev/database/sql#DB.Query