Skip to content

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

    general-injection-swift-v1

    View as Markdown

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

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

    error swift data-flow rule swift, vapor, foundation

    A request or URL-scheme value reaches a file read, write, delete or file response without being reduced to a file name or checked against the base directory. A value such as ../../etc/passwd escapes the intended folder. Use lastPathComponent, or standardize the path and verify hasPrefix(baseDirectory) 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 the value’s lastPathComponent, or build the URL, call standardizedFileURL and refuse the request unless its path hasPrefix the base directory path (with a trailing separator). Prefer an id resolved through a lookup instead of a path.

    References: https://docs.vapor.codes/basics/routing/ · https://developer.apple.com/documentation/foundation/filemanager

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

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

    error swift data-flow rule swift, vapor, sqlite, grdb, fmdb, sqlkit

    A request or URL-scheme value is interpolated or concatenated into SQL text executed through SQLite, GRDB, FMDB or SQLKit. The value can change the query. Keep the SQL constant with ? placeholders and pass arguments separately.

    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: Use bound parameters: db.execute(sql: “… WHERE id = ?”, arguments: [id]), FMDB executeQuery with withArgumentsIn, or SQLKit interpolation (\(bind: value)). Never splice values into the statement text; map identifiers to a fixed allow-list.

    References: https://docs.vapor.codes/fluent/overview/ · https://developer.apple.com/documentation/foundation/nsstring

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

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

    error swift data-flow rule swift, vapor, foundation

    A request value is run as an operating system command, either as the executable of a Process or as the script of a shell (sh -c). The value can append further commands. Launch a fixed executable and pass each argument as a separate array element.

    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: Set executableURL to a constant tool path and put each argument in its own arguments element; do not use /bin/sh -c with a built string. Validate arguments against a strict allow-list.

    References: https://developer.apple.com/documentation/foundation/process

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

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

    warning swift data-flow rule swift, vapor, urlsession, alamofire

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

    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. Map an id to a fixed URL, or build URLComponents, require scheme == “https”, check host against a fixed allow-list, resolve and reject private addresses, and re-validate redirects in a URLSessionTaskDelegate.

    References: https://developer.apple.com/documentation/foundation/urlsession · https://docs.vapor.codes/basics/client/

    keryn.general.swift.webview-html-js-injection

    Section titled “keryn.general.swift.webview-html-js-injection”

    warning swift data-flow rule swift, wkwebview, ios

    A request, URL-scheme or deep-link value is loaded as HTML or evaluated as JavaScript in a web view without escaping. Markup or script in the value runs inside the app’s web view with its bridges and cookies. Escape the value for the context, or pass data through a message handler instead of building script text.

    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: HTML-escape values placed in loadHTMLString content, and pass data to scripts through WKScriptMessageHandler / callAsyncJavaScript arguments rather than interpolating it into evaluateJavaScript text. Load untrusted URLs only after an https and host allow-list check.

    References: https://developer.apple.com/documentation/webkit/wkwebview/loadhtmlstring(_:baseurl:) · https://developer.apple.com/documentation/webkit/wkwebview/evaluatejavascript(_:completionhandler:)

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

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

    warning swift swift, sqlite, grdb, fmdb, sqlkit

    SQL text passed to SQLite, GRDB, FMDB or SQLKit is assembled from a variable (string interpolation or +). Whatever the variable holds becomes part of the statement. Keep the SQL constant with ? placeholders and pass values as arguments; map table or column names to a fixed allow-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: Use bound parameters: db.execute(sql: “DELETE FROM t WHERE id = ?”, arguments: [id]), FMDB executeUpdate(_:withArgumentsIn:), sqlite3_bind_*, or SQLKit’s \(bind: value). For identifiers that cannot be bound (table or column names), pick them from a fixed list.

    References: https://github.com/groue/GRDB.swift/blob/master/README.md#executing-updates · https://www.sqlite.org/c3ref/bind_blob.html