> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nika.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Security model

> Absent permits is zero authority. The SSRF floor, the shell floor, the order law, taint, the lethal trifecta, and typed NIKA-SEC errors.

Workflows run attacker-influenced inputs by nature: they fetch URLs,
shell out, and feed model output into tools. Nika's position is that the
**mechanism must be safe before policy makes it configurable**: the
dangerous primitives ship hardened by default, and a violation is a
typed `NIKA-SEC-*` error your workflow can read, not a stack trace.

## The threat model in one table

| You write | The attacker controls | The defense |
| - | - | - |
| `invoke: nika:fetch` | the URL (or a page that redirects) | 3-layer SSRF floor, on by default (`NIKA-SEC-005`) |
| `exec:` | argument values flowing from upstream tasks | shell floor (`NIKA-SEC-001`) + `permits.exec` allowlist + the order law (`NIKA-SEC-015`) |
| `agent:` / tool use | the fetched content the model reads | agent tools whitelist (`NIKA-SEC-002`) + permit re-gate on tainted arguments (`NIKA-SEC-004`) + lethal-trifecta check with its human gate (`NIKA-SEC-009`) |
| `secrets.*` bindings | log access | masked before events are written; a secret reaching a sink without `egress:` is refused (`NIKA-SEC-006`) |
| `invoke: workflow:` (a child workflow) | content that crosses into or out of the child | the trifecta and the consent law judge each call as the tasks its child stands for (`NIKA-SEC-009` · `NIKA-SEC-014`) |
| `infer:` with `vision:` files | which file's bytes reach the provider | a `source: file` image is a read inside `permits.fs.read`, judged on its resolved path before it is opened, and at check when the path is literal (`NIKA-AUTH-006` · `NIKA-SEC-004`); a vision entry is a sink for secrets and for the trifecta (`NIKA-SEC-006` · `NIKA-SEC-009`) |

## Permits — declare the blast radius

On top of the hardened mechanisms, a `permits:` block makes the file
itself declare its blast radius. Four families, one shape:

```yaml theme={"system"}
permits:
  fs:
    read: ["./data/**"]        # paths tasks may read
    write: ["./out/**"]        # paths tasks may write
  net:
    http: ["api.github.com"]   # hosts nika:fetch may reach
  exec: ["git", "wc"]          # programs exec: may run (false · true · allowlist)
  tools: ["nika:*"]            # tool ids invoke:/agents may call
```

Two laws govern it:

1. **No `permits:` block → zero authority**, not an unrestricted floor.
   Hardened defaults (SSRF, shell blocklist, secret masking) still apply,
   and they do **not** grant exec, net, fs, or tools. On 0.124.3,
   `exec: { command: ["printf", "hello"] }` with no `permits:` is
   `NIKA-AUTH-006` at check, exit 2. Spec 01-envelope · LAW-AUTH-0324.
2. **Any `permits:` block → default-deny for the whole file.** Anything
   not listed is refused. A task reaching beyond the boundary is caught
   by `nika check` (`NIKA-SEC-004` or `NIKA-AUTH-006`, with the exact
   fix) and again at run time.

A file whose bytes reach a model provider is a read like any other. An
`infer:` task's `vision:` image with `source: file` is admitted only by
`permits.fs.read`, on an API route and on an agent application's seat alike,
in a child workflow and in a rehearsal: `NIKA-AUTH-006` under an absent block,
`NIKA-SEC-004` outside a declared one. `nika check` judges a literal path, or
a whole bare `const` reference, and lists it in `--infer-permits`; it refuses
a computed path under a boundary that grants no read at all. The run reads
every file itself, on its resolved path, before any provider call. A workflow
that sent a vision file with no grant before 0.124 must now grant it. A
`source: url` image is not an fs effect: the provider fetches it and Nika
never does, so it needs no `fs` or `net.http` grant, and `permits: {}` admits
it ([Verbs](https://docs.nika.sh/concepts/verbs.md#vision-files-are-reads)).

<video autoPlay muted loop playsInline controls poster="/images/posters/permits-audit.png" aria-label="A workflow's permits drawn as a map; nika check catches the task that reaches outside it, then passes once the boundary is widened" alt="A workflow's permits drawn as a map; nika check catches the task that reaches outside it, then passes once the boundary is widened">
  <source src="https://mintcdn.com/supernovae-acdf3706/3tG2rJOQxMP3h2LO/videos/permits-audit.webm?fit=max&auto=format&n=3tG2rJOQxMP3h2LO&q=85&s=807d72186fe13eb45bc4248d9629a61c" type="video/webm" />

  <source src="https://mintcdn.com/supernovae-acdf3706/3tG2rJOQxMP3h2LO/videos/permits-audit.mp4?fit=max&auto=format&n=3tG2rJOQxMP3h2LO&q=85&s=2bc973ec606316c3a22e331839acec5b" type="video/mp4" />
</video>

**The file is the boundary.** The `permits:` block, drawn as a map of what each task may reach. One task fetches a host outside the fence: `nika check` refuses the file (`NIKA-SEC-004`) and names the one-line fix. Widen the fence on purpose and the same check says the file is ready to run. *Output captured from the real CLI on nika 0.121.0; the map is drawn from the file.*

> [!TIP]
>
> Predict: a file with one `exec:` and no `permits:` — does it run?
> It does not. `nika check --infer-permits` prints the tightest block
> to paste. Infer-only `mock/echo` with `permits: {}` is the declared
> zero, and that is enough for a first run.

You never have to write it by hand: `nika check --infer-permits`
computes the tightest boundary the file actually needs and prints it,
ready to paste. The SSRF floor below stays on **regardless** of
permits — a permitted host still cannot bounce into private space.

## SSRF defense (on by default)

`nika:fetch` refuses to be bounced into private space. Three layers,
verbatim from the engine (`nika-http`):

**1. Static checks (pure)**

Scheme allow-list (`http`/`https` only), blocked hostnames, and
range checks for implicit loopback, RFC 1918, link-local/metadata
(`169.254.169.254`), CGN, IPv6 local, v4-mapped v6. Spec
[01-envelope Exact-loopback declassification](https://github.com/supernovae-st/nika-spec/blob/6390b08eb9791ce49c63ee17f8466fab118cadb8/spec/01-envelope.md):
the **only** SSRF carve-out is an exact `permits.net.http` literal —
the closed set `localhost`, a `127.x.y.z` v4 literal, or `::1` /
`[::1]`. Clearing is exact-host: a permitted `localhost` does **not**
clear `127.0.0.1` (on 0.124.3, that grant with a fetch to
`127.0.0.1` is `NIKA-SEC-005` at check; an exact `127.0.0.1` grant
passes);
a public name that resolves to loopback stays refused; RFC1918 /
metadata named in the list stay floor-blocked (`NIKA-SEC-005`).

**2. DNS resolution check**

Non-literal hosts are resolved and **every address** is
range-checked: this kills decimal-IP tricks (`http://2130706433/`)
and public names that resolve to private addresses.

**3. Per-hop redirect re-check**

Client-level redirects are disabled; the engine follows redirects
itself and re-runs layers 1+2 on **every hop**. A public host
cannot 302 the client into your VPC.

Response sizes are capped (64 MiB default) and self-signed TLS is
rejected by default. Private-network access is opt-in configuration,
never the default.

## exec: the order law (NIKA-SEC-015)

Content the workflow did not author must never reach a shell. An `exec:`
task that sits downstream of a `nika:fetch` or `nika:notify` task, over a
`with:` data edge or an `after:` control edge, is refused at check, whatever
the channel: an argv element, `stdin:`, or no data at all. No `permits:`
entry and no `lift:` can open this law.

```yaml fetch-then-shell.nika theme={"system"}
# Refused at check: NIKA-SEC-015, the order law
nika: fetch-then-shell
model: mock/echo
permits:
  tools: ["nika:fetch"]
  net:
    http: ["api.github.com"]
  exec: ["wc"]
tasks:
  pull:
    invoke:
      tool: nika:fetch
      args:
        url: "https://api.github.com/repos/supernovae-st/nika"
        mode: raw
  count:
    with:
      body: ${{ tasks.pull.output }}
    exec:
      command: ["wc", "-c"]
      stdin: "${{ with.body }}"
outputs:
  bytes: ${{ tasks.count.output }}
```

```text theme={"system"}
✖ ORDER    [NIKA-SEC-015] the order law · `count` shells on content `pull` fetched — `pull` → `count`. …
           Fix: do the work in a builtin (`nika:jq` · `nika:grep`) instead of a shell, or cut the route so the fetched value never reaches `count`.
```

Do the work in a builtin instead. Here the fetch extracts with `mode: jq`
and a builtin writes the result, with no shell anywhere:

```yaml fetch-then-transform.nika theme={"system"}
nika: fetch-then-transform
model: mock/echo
permits:
  tools: ["nika:fetch", "nika:write"]
  net:
    http: ["api.github.com"]
  fs:
    write: ["./out/stars.json"]
tasks:
  pull:
    invoke:
      tool: nika:fetch
      args:
        url: "https://api.github.com/repos/supernovae-st/nika"
        mode: jq
        jq: "{stars: .stargazers_count, forks: .forks_count}"
  save:
    with:
      stats: ${{ tasks.pull.output }}
    invoke:
      tool: nika:write
      args:
        path: ./out/stars.json
        content: "${{ with.stats }}"
        create_dirs: true
outputs:
  stats: ${{ tasks.pull.output }}
```

For values that may reach `exec:` (a caller's `inputs`, a model's answer),
keep them in data channels: argv elements, each substituted on its own with
no shell to break out of, or `stdin:`; never a `shell:` string. The resolved
program must still match `permits.exec`: a model that answers a program name
the allowlist does not hold fails the run with `NIKA-SEC-004`.

## One authored door: lift: (two laws)

Some legitimate workflows do need to cross one of these lines. Nika refuses
to let that happen silently: there is exactly one door, `lift:`, authored,
naming the law it opens, requiring a written justification, recorded in the
run receipt.

| `lift:` entry | Lifts | Shape |
| - | - | - |
| `law: taint` | the **permit-parameterization taint** — an untrusted binding used where a permit is matched | `from:` (one dotted binding) + a non-empty `because:` |
| `law: data-as-code` | the **data-as-code sink** — a `nika:fetch` whose resolved URL names a code-bearing class (`NIKA-SEC-008`) | a non-empty `because:` · no `from:` |

```yaml theme={"system"}
load_inventory:
  invoke:
    tool: "nika:read"
    args: { path: "${{ inputs.p }}" }
  lift:
    - law: taint
      from: inputs.p
      because: "deployment-controlled inventory path, reviewed at release"
```

Each entry lifts **one** law and nothing else. `law: taint` does not widen
`permits:` — the value is still matched against the declared boundary, so it
can never become a permit bypass, and there is no implicit declassification.
`law: data-as-code` does not touch the `net.http` boundary or the SSRF floor.
(`declassify:` and `inert:` were the two earlier spellings; both merged into
`lift:` in 0.109 — the law is a parameter of one door, not two keywords.)

Because it is one plain YAML key, `grep -rn 'lift:'` over a repo returns
every place a law was opened, with the reason attached. That is the point:
the escape hatch is auditable by construction.

## Prompt injection: the boundary checks

Nika does not try to detect injected instructions in text. It bounds what a
model that has read untrusted content can make happen, with checks that hold
whatever the model decides:

| Check | What it refuses | Code |
| - | - | - |
| Agent tools whitelist | an `agent:` calling a tool outside its declared `tools:` (default-deny) | `NIKA-SEC-002` |
| Permit re-gate | a tainted argument that resolves outside `permits:` at run time | `NIKA-SEC-004` |
| SSRF floor | a fetch into loopback, private, link-local or metadata space | `NIKA-SEC-005` |
| Secret flow | a secret reaching a sink with no matching `egress:` entry | `NIKA-SEC-006` |
| Lethal trifecta | a boundary that grants private reads, untrusted ingress (a fetch, an MCP tool, an agent that can reach one) and external egress, where the untrusted content reaches the egress (directly, through a file a builtin reads back, or through a child workflow) and no blocking `nika:prompt` gate dominates it | `NIKA-SEC-009` |
| Affirmative consent | a confirm gate (`nika:prompt`) in front of an egress, a child workflow call included, with a route that a « no » answer does not close | `NIKA-SEC-014` |
| Order law | fetched or notified content reaching any `exec:` task | `NIKA-SEC-015` |
| Recursion bound | a self-launching workflow, or nested runs past the depth limit | `NIKA-SEC-003` |

Every failure is a [typed error](https://docs.nika.sh/reference/error-codes.md) with a stable code
and a `transient` flag; `on_error:` can act on it. The catalog lists the full
`NIKA-SEC` namespace.

## The trifecta across files and child workflows

The trifecta and the consent law follow untrusted content wherever it
travels, not only along one file's direct edges:

* **Through a file.** When a task saves untrusted content to a file, a
  builtin that reads that path carries the content on: `nika:read`,
  `nika:grep` (its default root `.` included), `nika:glob`, `nika:edit`, a
  `nika:decide` bundle, the files `nika:image_fx`, `nika:chart` and
  `nika:image_generate` read, and a `nika:fetch` multipart upload. With a
  literal write path the order does not matter: a read in the writer's own
  wave, or before it in the run (the next run reads the file), counts too.
  Paths compare lexically and case-blind, a templated path may be any file,
  and a read whose path cannot reach the written one stays clean.
* **Through a child workflow.** `nika check` and `nika run` judge an
  `invoke: workflow:` call as the tasks its child stands for, through every
  workflow below it. The call brings untrusted content in when content its
  child fetches, runs or receives from an MCP tool or an agent reaches the
  child's outputs or a file it writes. It is an egress when untrusted content
  reaches an egress inside it: the child's own, the call's arguments, or a
  file written before the call that a child `exec:` reads. The parent is
  refused unless a blocking `nika:prompt` of its own dominates the path; a
  gate inside the child is not credited to the caller. A child the check
  cannot read, parse or resolve counts as all of these. The finding names the
  child task behind the call, and `nika check --json` lists every direct call
  under `composed_calls`.
* **Consent in front of a child.** A confirm gate placed before a child
  workflow call must stop the child's effect on a « no », as for an inline
  egress: every route from the gate to the call must close on the refusal
  (`NIKA-SEC-014`), and the finding names the call. A bare
  `after: { ask: success }` edge does not close it, because a refused confirm
  also settles with success: bind the answer on the call instead
  (`with: { go: ${{ tasks.ask.output }} }` and
  `when: ${{ with.go == true }}`). A confirm gate inside the
  child owns the effect behind it. When the only gate before the effect is
  one inside the child that the check cannot decide from the caller (a
  `when:` on an input the caller may bind to its answer), the call gets the
  advisory hint instead of the refusal.
* **The run re-judges the calls.** The runtime re-derives the trifecta over
  the child calls the check report resolved. A call the report does not list
  for its task and target counts as unresolved, and the run refuses it with
  `NIKA-1707`, naming it, so a program that pairs its own check with the
  runtime cannot run a fetching child into an ungated egress.
  `nika run --task` re-checks the kept tasks with their children.

A check of the source alone (an editor, the MCP `nika_check` tool) reads no
child: its trifecta judges the parent's own tasks only. `NIKA-DRIFT-001` no
longer advises removing a grant a child needs (its program, its tools, the
files and hosts its own `permits:` lets it reach).

An `infer:` task's `vision:` entries are followed too. A vision read of a file
an untrusted writer left counts in the file channel, untrusted content that
picks a vision entry reaches the task's answer, and a parent must grant the
vision files of the children it calls (`NIKA-COMP-002`).

## Secrets

`${{ secrets.* }}` is a first-class namespace, backed by an environment
variable (`source: env`) or a file (`source: file`). Secret values are
**masked** before events are written: they never appear in the event stream,
and they are not readable back from a task's recorded output. A secret that
reaches any sink without a matching `egress:` entry is refused
(`NIKA-SEC-006`).

## Supply-chain hardening (the engine itself)

* `unsafe_code = "forbid"` workspace-wide · zero `.unwrap()` in `src/` (CI-enforced)
* `cargo deny` on every PR · `cargo audit` on every dependency change
* Sealed kernel traits · external code cannot impersonate engine I/O
* An AGPL engine of 75 admitted crates plus
  {STATUS.wipCrates.length} still pre-admission, some of which ship in the
  binary (the Session, the terminal workspace, `nika serve`)
* Every release ships SHA256 sums, a GitHub build attestation and SLSA
  provenance ([Verify a download](https://docs.nika.sh/getting-started/installation.md#verify-a-download))
* AGPL-3.0-or-later · the source travels with the binary, always auditable

## Reporting a vulnerability

**[security@supernovae.studio](mailto:security@supernovae.studio)** (please not via public issues).
Acknowledgement ≤72h, triage ≤7 days, disclosure ≤90 days. Security fixes
land on `main`, the only maintenance branch, and ship in the next release:
0.124.x is maintained, and the 0.123.x line, the previous one, receives no
further patches. Report against the latest release or `main`. Full policy,
disclosure process and the out-of-scope list:
[SECURITY.md](https://github.com/supernovae-st/nika/blob/main/SECURITY.md).

## See also

> [card] [Error codes](https://docs.nika.sh/reference/error-codes.md)
>
> The `NIKA-SEC` namespace + every typed failure.

> [card] [Bindings](https://docs.nika.sh/concepts/bindings.md)
>
> Taint, scopes, and the `secrets.*` namespace.

> [card] [Builtins · fetch](https://docs.nika.sh/reference/builtins.md)
>
> The `nika:fetch` contract (engines MUST ship SSRF defense).

> [card] [SECURITY.md](https://github.com/supernovae-st/nika/blob/main/SECURITY.md)
>
> Reporting, disclosure timeline, hall of fame.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.