# Static analysis (SAST)

> What Keryn's two source engines read, which languages and rules they cover, how Deep confirms pattern findings, and how to run, tune and gate the result.

Source: https://keryn.dev/docs/guides/sast/

## Goal

Know what a source scan checks, in which languages, with which engine, and how much evidence stands behind each finding. Then run one, read it, and set the gate that fits you.

## Before you start

- The Keryn CLI ([install](https://keryn.dev/docs/start/install/)), or [Keryn Web](https://keryn.dev/docs/guides/web-app/) to scan a folder, zip or repository in the browser.
- A repository. Everything below runs on your machine; the scan reads files and sends nothing anywhere.
- The [proof ladder](https://keryn.dev/docs/concepts/proof-ladder/), for what the proof levels mean.

## The two engines

A scan runs two engines over the same files, one after the other.

| Engine | What it does | Where it runs |
|---|---|---|
| **Pattern engine** | Matches rules against the syntax tree of each file: patterns, taint rules (a source reaching a sink inside one file), and the metavariable and `pattern-either`/`pattern-not` forms of Semgrep rule syntax. It is written in TypeScript and checked against Semgrep CE 1.157 on the rule fixtures. | Everywhere Keryn runs, including the browser. |
| **Deep** | Builds a call graph and follows data from sources to sinks, across files and through return values. It is a Rust engine, run as WebAssembly. | After the pattern engine, in a CLI scan. If Deep cannot run in Keryn Web, the Results view says so and gives the reason. |

The pattern engine reports a **pattern finding** at proof level 1, or a same-file path at level 2. Deep reports cross-file paths at level 3. `keryn scan` runs Deep after the pattern engine and hands it the pattern engine's facts. `--no-deep` skips Deep and keeps pattern rules only.

Semgrep CE parity is about rule syntax: rules written for Semgrep run on the pattern engine, and `keryn rules lint` tells you before a scan which parts of a rule the engine can run. It does not mean every Semgrep result is reproduced. Rules the pattern engine cannot run completely are counted as unsupported or partial in the [coverage](https://keryn.dev/docs/concepts/coverage/) line, and the scan exits with 3 unless you pass `--allow-incomplete`.

## Languages

The pattern engine parses these languages and file types:

- Application code: TypeScript, JavaScript, Python, Java, C#, Go, Rust, PHP, Kotlin, Swift, Ruby, C, C++, Bash, Scala, Solidity, Dart, Lua, OCaml, Julia and R.
- Configuration and markup: JSON, YAML, HCL (Terraform), XML, HTML and Dockerfiles. A Helm chart template is not YAML until it is rendered, and no rule matches it as written: on main, a scan counts chart templates as not analysed and is incomplete. Render first (`helm template <release> <chart> > rendered.yaml`) and scan the output; Keryn does not run Helm.

The bundled rule library targets Python, TypeScript, JavaScript, Java, C#, Go, Rust, PHP, Kotlin, Swift, Ruby, C, C++, Bash, JSON, YAML, HCL, Dockerfile and language-independent text patterns. A language the pattern engine parses but no bundled rule targets (Scala, Dart and the others in the list) is read by your own [custom rules](https://keryn.dev/docs/guides/custom-rules/) only.

Deep's reach differs by language. For Python and TypeScript/JavaScript it follows imports, re-exports, return values and subclass overrides across files. For Java, C# and Go it follows return values and subtype calls under the same caps but resolves an import one level deep. C and C++ follow a quoted `#include` one level. Other languages are analysed within one file. The exact caps are in [what Keryn does not do](https://keryn.dev/docs/concepts/limits/).

## Current browser build

The manually deployed browser build includes newer JavaScript/TypeScript Node checks and conservative Rails project applicability. Type assertions, non-null expressions and `satisfies` retain the underlying runtime expression for analysis. Dynamic call shapes and reference-tool semantics still have gaps; see the [ESLint](https://keryn.dev/evals/eslint-security/) and [Brakeman](https://keryn.dev/evals/brakeman/) location comparisons. Their scan failures and incomplete cases remain failures even when observed locations happen to agree.

The [capability map](https://keryn.dev/docs/concepts/capabilities/) separates this browser deployment from installed releases and native-engine research. The [rule catalog](https://keryn.dev/rules/) describes the currently published rule metadata.

## The rule library

The [rule catalog](https://keryn.dev/rules/) lists the current bundled rule metadata and source version. Installed releases can carry an older library; use their own version and coverage report. Most rules are about AI applications: prompt and tool injection, model output reaching a shell, query or template, agent permissions, MCP servers, secrets in prompts. Some are general-purpose:

- **Request input reaching a dangerous call**, for Java, Kotlin, C#, Go and Swift: path traversal, SQL injection, command injection, server-side request forgery, cross-site scripting, and CSRF protection turned off (an audit). Packs: [`general-injection-java-v1`](https://keryn.dev/rules/general-injection-java-v1/), [`-kotlin-v1`](https://keryn.dev/rules/general-injection-kotlin-v1/), [`-csharp-v1`](https://keryn.dev/rules/general-injection-csharp-v1/), [`-go-v1`](https://keryn.dev/rules/general-injection-go-v1/) and [`-swift-v1`](https://keryn.dev/rules/general-injection-swift-v1/).
- **Zip slip**: an archive entry name used as a path, for Java, Kotlin, C# and Go.

Every rule says its severity, its **confidence** (`P0` exploitable as written, `P1` dangerous in context, `P2` a heuristic or posture check) and its **false-positive risk**. `keryn explain <rule-id>` prints them offline, with the message, remediation and references; detection patterns are never shown.

```sh
keryn explain seceng.agentcfg.allow-bash-unrestricted
```

> **Note: Next release: rule additions**
> These rule additions are on main and ship in the next release; they are not in 0.5.2. A PHP pack, [`general-injection-php-v1`](https://keryn.dev/rules/), covers output escaping (cross-site scripting), SQL injection, path traversal, command injection, server-side request forgery, open redirect, `unserialize`, zip slip and `extractTo` of an uploaded archive. SQL built from a variable becomes an audit rule for Java, Kotlin, C#, Swift and Go. Insecure deserialization is added for Java, Kotlin and C#. Request sources are widened: Android ContentProvider and Intent, multipart file names, JAX-RS, Quarkus, Micronaut and Ktor. The SQL-from-variable audits are reported for review and fail a scan only when Deep proves a flow, as described below.

## 1. Scan and see how much evidence each finding has

```sh
keryn scan . --verbose --fail-on none
```

`--verbose` lists each finding with its proof rung and, from rung 3, the flow. `--fail-on none` keeps the exit code at 0 so you can read before you gate. Write the formats your tools read with `--sarif`, `--json`, `--markdown`, `--junit` and the others in [output formats](https://keryn.dev/docs/reference/formats/).

## 2. Read what Deep said about a pattern finding

After both engines ran, Keryn compares them on each pattern finding. Deep records its answer in the finding, and every output shows it next to the proof level:

- **confirmed by Deep**: Deep proved a flow from untrusted data to this sink. The finding takes Deep's proof level and trace.
- **needs review: Deep found no data flow to it**: Deep ran, models this sink and language, and found no flow. This is only applied to rules whose false-positive risk is medium or high, because those depend on the flow. The finding stays in the report and does not count toward the default gate. An exact-API rule (low false-positive risk) stands on its own.
- Nothing is added when Deep did not run, does not model the sink, or the language is one it does not follow. That is not the same as "no flow".

The report's `deep` summary counts both ("2 confirmed by Deep, 3 need review"). Deep's corroboration covers Python, TypeScript, JavaScript, Java, C# and Go files.

Compare a scan with Deep to one without it:

```sh
keryn scan . --verbose --fail-on none --no-deep
```

## 3. Decide what gates

By default a finding counts toward `--fail-on` when its rule is `P0` or `P1` and its false-positive risk is not high, or when it is proven at proof level 3 or above. `audit` and `inventory` findings (a control is missing, a capability exists) are reported and never fail a run. Widen or narrow it:

```sh
keryn scan . --fail-on none --gate-confidence P2
```

`--gate-confidence P2` also counts the lower-confidence rules and the "needs review" findings. `--fail-on error|warning|info|none` sets the severity at which the scan fails (default `error`). A suppression you record is kept in the repository, see [suppressions](https://keryn.dev/docs/guides/suppressions/).

> **Note: Next release: gating confirmed findings**
> A pattern finding that Deep **confirmed** (proof level 2 or more) counts toward the default gate whatever its rule's confidence, because two engines agree on the line. In 0.5.2 only proof level 3 and above gates regardless of the rule's confidence. This is on main and ships in the next release.

## What the numbers say

On the November 2026 held-out split, the request-to-sink rule round found 15 of 83 scored pairs, up from 13. JavaScript accounted for both new detections, rising from 1 to 3 of 15. TypeScript stayed at 3 of 29 and Python at 9 of 42. The number of detections that also fired on the fixed code rose from 10 of 13 to 12 of 15. These are the baseline and round-two results in the rules repository receipts `scoreboard-2026-11-18-engines-base-holdout-jstspy.json` and `scoreboard-2026-11-18-engines-r2-holdout-jstspy.json`.

Pattern findings often survive the fix, and Deep is how Keryn reduces that. The figures below come from Keryn's real-fix benchmark (582 pairs of vulnerable and fixed code from advisories, 565 scorable), scored on defect rules with findings of 10 lines or less. The question is how often a rule that found the vulnerable code also fires on the fixed code.

| Detecting findings (61 pairs found; "gating" under the default gate of 0.5.2) | Count | Still fire on the fixed code |
|---|---|---|
| confirmed by Deep, gating | 16 | 4 (25%) |
| confirmed by Deep, rule marked low confidence | 15 | 7 (47%) |
| Deep found no flow ("needs review") | 49 | 20 (41%) |
| not checked by Deep, gating | 22 | 14 (64%) |

Source: the 2026-11-07 precision round, receipt `scoreboard-2026-11-07-after1-deep-gating.json` in the rules repository. Two honest limits come with it. The benchmark is a mix of AI-specific and general projects, and the general ones are the weak side: recall on general vulnerabilities is low, see [what Keryn does not do](https://keryn.dev/docs/concepts/limits/). And several rules were corrected by reading that benchmark's diffs, so for those rules it is no longer a held-out measurement.

> **Note: Next release: benchmarked rules**
> The round after that used a held-out split of the benchmark (by repository, about 31% held out) so rules were tuned on one side only. For pairs with a changed PHP, Java, C#, Kotlin, Swift or Go file, the number of fixes found went from 5 to 13 of 129 on the development side and from 5 to 7 of 76 on the held-out side. The held-out gain is the number to trust, and it is small: most misses are fixes no general rule can see, such as refactors, allowlists added to libraries and flows across functions. Receipts: `scoreboard-2026-11-08-general-*`. These rules ship in the next release.
>
> A third round (November 2026) added request-to-sink rules for JavaScript, TypeScript and Python web frameworks: a value from an Express, Koa, Fastify, NestJS, Next.js, Flask, Django or FastAPI request reaching SQL text, a shell command, a file path, an outbound URL, a redirect or an HTML response. They were tuned on the development side only and the held-out side was run once. On the held-out side, for pairs with a changed JavaScript, TypeScript or Python file, the number of fixes found went from 13 to 15 of 83: JavaScript 1 to 3 of 15, TypeScript 3 of 29 and Python 9 of 42 both unchanged. Both new detections also fire on the fixed code (fires-on-fix 10 to 12), so on this benchmark the new rules find a little more and do not yet tell the fix from the bug. Receipts: `scoreboard-2026-11-18-engines-base-holdout-jstspy.json` and `scoreboard-2026-11-18-engines-after-holdout-jstspy.json`. The benchmark was re-fetched for this round and 29 of its pairs are no longer retrievable, so these counts are not comparable with the earlier rounds. These rules ship in the next release.

## What you just proved

You know which engine produced each finding and how much evidence stands behind it: a pattern, a path in a file, a path across files, or a pattern that Deep confirmed or could not confirm. A scan that says "no findings" means the rules that ran found nothing in the languages they cover. The [coverage](https://keryn.dev/docs/concepts/coverage/) line says which rules ran.

## Limits

- General (non-AI) static analysis recall is low, and a clean scan is not a statement that code is safe.
- The pattern engine and Deep are static. Neither runs your code. A path they report is a reading of the code, not an exploit.
- Deep's no-flow answer is a statement about what Deep models. It does not clear the finding.
- Bundled rules are mostly about AI applications and the agent surface around them. Languages with few rules (Rust, Ruby, C, C++, Bash) get little coverage from the library.

## Next

- Rules of your own: [write your own rules](https://keryn.dev/docs/guides/custom-rules/).
- What a finding means: [the proof ladder](https://keryn.dev/docs/concepts/proof-ladder/).
- Dependencies, secrets and binaries: [software composition analysis](https://keryn.dev/docs/guides/sca/), [secrets](https://keryn.dev/docs/guides/secrets/), [binary analysis](https://keryn.dev/docs/guides/binary-analysis/).
- Gate it in the pipeline: [Add Keryn to CI](https://keryn.dev/docs/guides/ci/).
