penthera 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +212 -0
- package/README.md +379 -39
- package/docs/METHODOLOGY.md +321 -0
- package/docs/evidence.md +158 -0
- package/docs/examples/github-actions-deps.yml +105 -0
- package/docs/examples/github-actions-scan.yml +1 -1
- package/docs/examples/pr-dependency-review.yml +56 -0
- package/docs/funding/due-diligence-checklist.md +79 -0
- package/docs/funding/nlnet-ngi-zero-draft.md +273 -0
- package/docs/funding/partner-one-pager.md +84 -0
- package/docs/funding/sponsor-tiers.md +81 -0
- package/docs/index.md +12 -1
- package/docs/local-loop.md +276 -0
- package/docs/references.bib +539 -0
- package/docs/references.md +77 -0
- package/docs/release-plan.md +228 -0
- package/lib/adaptive-probes.js +8 -5
- package/lib/agents/discover.js +384 -0
- package/lib/agents/hidden-content.js +387 -0
- package/lib/agents/index.js +286 -0
- package/lib/agents/lock.js +115 -0
- package/lib/agents/owasp.js +83 -0
- package/lib/agents/rules.js +376 -0
- package/lib/crawler.js +5 -15
- package/lib/data/retire-jsrepository.json.gz +0 -0
- package/lib/data/retire-jsrepository.meta.json +7 -0
- package/lib/deps/capabilities.js +523 -0
- package/lib/deps/diff.js +84 -0
- package/lib/deps/index.js +416 -0
- package/lib/deps/lockfile.js +106 -0
- package/lib/deps/online.js +132 -0
- package/lib/deps/popular-packages.json +1 -0
- package/lib/deps/report.js +173 -0
- package/lib/deps/source.js +171 -0
- package/lib/deps/typosquat.js +113 -0
- package/lib/fix/apply.js +95 -0
- package/lib/fix/diff.js +199 -0
- package/lib/fix/index.js +129 -0
- package/lib/fix/model.js +108 -0
- package/lib/fix/recipes/cookies.js +130 -0
- package/lib/fix/recipes/cors.js +116 -0
- package/lib/fix/recipes/headers.js +250 -0
- package/lib/fix/recipes/rate-limit.js +211 -0
- package/lib/fix/recipes/secrets.js +110 -0
- package/lib/fix/util.js +231 -0
- package/lib/fuzzer.js +14 -8
- package/lib/injections.js +19 -15
- package/lib/install/index.js +271 -0
- package/lib/install/policy.js +117 -0
- package/lib/memory/history.js +52 -0
- package/lib/memory/index.js +111 -0
- package/lib/memory/repo-suppress.js +64 -0
- package/lib/memory/store.js +325 -0
- package/lib/memory/views.js +198 -0
- package/lib/params.js +4 -12
- package/lib/provenance.js +2 -0
- package/lib/recon.js +12 -20
- package/lib/references.js +31 -0
- package/lib/references.json +374 -0
- package/lib/remediation/index.js +28 -0
- package/lib/retirejs.js +50 -22
- package/lib/templates.js +7 -10
- package/lib/whitebox/frameworks.js +1 -1
- package/package.json +16 -4
- package/skills/penthera/SKILL.md +103 -22
- package/src/agent/git.js +87 -0
- package/src/agent/loop.js +519 -0
- package/src/agent/tests.js +48 -0
- package/src/cli/agent.js +183 -0
- package/src/cli/deps.js +84 -0
- package/src/cli/evidence.js +67 -0
- package/src/cli/fix.js +191 -0
- package/src/cli/install.js +225 -0
- package/src/cli/memory.js +146 -0
- package/src/cli/merge-results.js +2 -0
- package/src/cli/report-outputs.js +72 -0
- package/src/cli/run-scan.js +2 -0
- package/src/cli.js +152 -6
- package/src/report/audience.js +270 -0
- package/src/report/evidence.js +253 -0
- package/src/report/markdown.js +65 -2
- package/src/report/model.js +212 -0
- package/src/report/template.js +175 -0
- package/src/report/timeline.js +145 -0
- package/src/reporter.js +109 -5
- package/src/scan-url.js +31 -7
- package/src/utils/http.js +252 -11
- package/src/utils/url.js +23 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# The local loop
|
|
2
|
+
|
|
3
|
+
Penthera v1.4 adds a loop that runs entirely on your machine: scan, fix on a
|
|
4
|
+
local branch, verify, learn, repeat. Nothing in it talks to a Penthera server,
|
|
5
|
+
because there isn't one. This page covers the loop itself (`penthera agent
|
|
6
|
+
--loop`) and the part that makes it improve over time: the local learning store.
|
|
7
|
+
|
|
8
|
+
## The agent loop
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
penthera agent --loop --repo . --url http://localhost:3000 -o reports/loop.json
|
|
12
|
+
penthera agent --loop --repo . --run-tests # also run the project's test script
|
|
13
|
+
penthera agent --loop --repo . --auto low # auto-apply only recipes memory has proven
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
One iteration:
|
|
17
|
+
|
|
18
|
+
1. **Scan** the repo (white-box scan plus the fix recipes' static probes) and,
|
|
19
|
+
with `--url`, the running app.
|
|
20
|
+
2. **Triage**: drop findings suppressed in memory or `penthera.suppress.json`,
|
|
21
|
+
and rank the rest with memory (severity always first).
|
|
22
|
+
3. **Plan**: a deterministic recipe first. The local model is asked only with
|
|
23
|
+
`--fix-model <name>`, and only for findings no recipe matches.
|
|
24
|
+
4. **Patch** on a local branch `penthera/fix-<yyyymmdd-hhmm>`, created from the
|
|
25
|
+
current HEAD when the run starts.
|
|
26
|
+
5. **Verify**: re-scan. A fix passes when the findings it targeted are gone from
|
|
27
|
+
the repo scan, no new finding appeared, and, with `--run-tests`, the
|
|
28
|
+
project's `test` script exits 0 (`node --run test`).
|
|
29
|
+
6. **Learn**: `scan`, `fix_applied` and `fix_verified` or `fix_failed` go to
|
|
30
|
+
memory.
|
|
31
|
+
7. **Commit** each verified fix on its own, with a message that lists the
|
|
32
|
+
findings, the recipe, and how it was verified. A fix that fails is reverted
|
|
33
|
+
(`git checkout` of the files it changed; files it created are removed).
|
|
34
|
+
|
|
35
|
+
Plans are applied one at a time and re-planned against the tree after each
|
|
36
|
+
fix, since two recipes can touch the same file. The loop repeats until nothing
|
|
37
|
+
fixable is left, `--max-iterations` (default 5) is reached, or you stop it.
|
|
38
|
+
A fix you decline (`n`) or that fails verification is not proposed again in
|
|
39
|
+
the same run; `s` skips it until the next iteration.
|
|
40
|
+
|
|
41
|
+
A live URL serves the code it was started with, so a fix to response headers
|
|
42
|
+
shows up in the URL scan only after the app restarts. The loop counts those as
|
|
43
|
+
`liveRemaining` in the fix's `verify` block, not as a failure; the repo scan
|
|
44
|
+
decides whether the fix landed.
|
|
45
|
+
|
|
46
|
+
### What it guarantees
|
|
47
|
+
|
|
48
|
+
Each of these has a test in `tests/agent.test.js`.
|
|
49
|
+
|
|
50
|
+
- **No remote operations.** All git goes through `src/agent/git.js`, an
|
|
51
|
+
allow-list of local subcommands (`rev-parse`, `symbolic-ref`, `status`,
|
|
52
|
+
`diff`, `log`, `show-ref`, `checkout`, `add`, `commit`, `config --get`).
|
|
53
|
+
`push`, `fetch`, `pull`, `remote`, `clone`, `ls-remote`, `submodule` and
|
|
54
|
+
everything else are refused before a process starts, as are URL arguments
|
|
55
|
+
and `-c` overrides. Every call also runs with `protocol.allow=never` and
|
|
56
|
+
`GIT_NO_LAZY_FETCH=1`, so no transport can work. The loop never runs `gh`
|
|
57
|
+
and never opens a pull request.
|
|
58
|
+
- **The repo's hooks never run.** Git runs with `core.hooksPath=/dev/null`,
|
|
59
|
+
`core.fsmonitor=false` and `commit --no-verify`: a scanned repo can ship hooks
|
|
60
|
+
that run anything.
|
|
61
|
+
- **Network.** The whole run is one W1 egress context with `--offline` always
|
|
62
|
+
on: the URL target is the only host. Loopback is added only when
|
|
63
|
+
`--fix-model` is set, and the model client then accepts only
|
|
64
|
+
`http://127.0.0.1:11434`.
|
|
65
|
+
- **Clean start.** A dirty tree (untracked files included), a detached HEAD, a
|
|
66
|
+
repo without commits, or a directory that is not a git repo is refused.
|
|
67
|
+
`--allow-dirty` lets the loop start anyway, but it never patches a file that
|
|
68
|
+
had uncommitted changes.
|
|
69
|
+
- **Approval.** Every diff is shown, secrets masked, with
|
|
70
|
+
`[y]es / [n]o / [s]kip / [q]uit`. When input runs out (piped stdin), the
|
|
71
|
+
answer is `n`. `--auto low` applies a diff without asking only when it comes
|
|
72
|
+
from a recipe (not the model), its confidence is not `needs-human-review`,
|
|
73
|
+
memory's chain verifies, and memory shows that recipe with at least 3
|
|
74
|
+
verified fixes and no failures for this framework.
|
|
75
|
+
- **Interruption.** The first Ctrl-C lets the fix in flight finish: it is
|
|
76
|
+
verified and committed, or reverted. The loop then stops on the fix branch,
|
|
77
|
+
which holds only verified commits. A second Ctrl-C reverts the fix in flight
|
|
78
|
+
at once and exits.
|
|
79
|
+
|
|
80
|
+
`--run-tests` runs the project's own code, so it can do anything that code
|
|
81
|
+
does, including network calls. It is off by default for that reason.
|
|
82
|
+
|
|
83
|
+
### The loopRun object
|
|
84
|
+
|
|
85
|
+
`-o <file>` writes `{ "loopRun": { ... } }`. W6's report timeline renders it.
|
|
86
|
+
Every step carries `startedAt` and `durationMs`.
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
{
|
|
90
|
+
schema: "penthera.loopRun/1",
|
|
91
|
+
id, startedAt, finishedAt, durationMs,
|
|
92
|
+
target: { repo, url },
|
|
93
|
+
branch: { base, baseSha, fix }, // base is null on a detached HEAD
|
|
94
|
+
options: { maxIterations, auto: "off" | "low", runTests, fixModel, offline: true, allowDirty },
|
|
95
|
+
stopReason: "no-fixable-findings" | "declined-or-failed-left" | "max-iterations"
|
|
96
|
+
| "user-quit" | "interrupted" | "error",
|
|
97
|
+
error, // message when stopReason is "error"
|
|
98
|
+
findings: { initial, final }, // non-info, unsuppressed
|
|
99
|
+
totals: { iterations, planned, applied, verified, failed, declined, skipped, commits: [sha] },
|
|
100
|
+
memory: { projectId, chain: "ok" | "broken", eventsAppended },
|
|
101
|
+
iterations: [{
|
|
102
|
+
n, startedAt, durationMs,
|
|
103
|
+
findings: { total, suppressed, fixable },
|
|
104
|
+
steps: [{ step: "scan" | "triage" | "plan", startedAt, durationMs }],
|
|
105
|
+
fixes: [{
|
|
106
|
+
planId, recipe, title, framework, source: "recipe" | "local-model", confidence,
|
|
107
|
+
files, findings: [{ fid, title, severity, category }],
|
|
108
|
+
memory: { verified, failed } | null, // recipe history when the plan was ranked
|
|
109
|
+
decision: "approved" | "auto" | "declined" | "skipped" | "quit" | "obsolete",
|
|
110
|
+
status: "verified" | "failed" | "not-applied",
|
|
111
|
+
reason, commit,
|
|
112
|
+
verify: { targetedRemaining, newFindings, liveRemaining, tests: { ok, exitCode, durationMs } | null } | null,
|
|
113
|
+
testOutput, // tail of the test output, only when tests failed
|
|
114
|
+
steps: [{ step: "approve" | "patch" | "learn" | "verify" | "commit" | "revert", startedAt, durationMs }],
|
|
115
|
+
}],
|
|
116
|
+
}],
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`obsolete` means an earlier fix in the same iteration already covered the plan.
|
|
121
|
+
The same object, without `testOutput` and with finding ids in place of finding
|
|
122
|
+
objects, is appended to memory as a `loop_run` event.
|
|
123
|
+
|
|
124
|
+
Exit codes: `0` nothing fixable left, `1` fixable findings remain (declined,
|
|
125
|
+
failed, or out of iterations), `2` the loop could not start (dirty tree,
|
|
126
|
+
detached HEAD, bad options), `130` interrupted.
|
|
127
|
+
|
|
128
|
+
## The learning store
|
|
129
|
+
|
|
130
|
+
Scans run with `--memory` record what happened, and the next scan uses that
|
|
131
|
+
record to rank and suppress findings.
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
penthera --repo . --memory # scan, apply memory, record this scan
|
|
135
|
+
penthera memory show # what memory knows about this project
|
|
136
|
+
penthera memory verify # check the hash chain
|
|
137
|
+
penthera memory suppress <id> --reason "set by the CDN" [--expires 2027-01-01]
|
|
138
|
+
penthera memory forget # delete this project's memory
|
|
139
|
+
penthera memory forget --all # delete all memory
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`<id>` is the 16-character `fid` shown next to each finding in a `--memory`
|
|
143
|
+
report.
|
|
144
|
+
|
|
145
|
+
### Where it lives
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
~/.penthera/memory/<project-id>/events.jsonl the event log
|
|
149
|
+
~/.penthera/memory/<project-id>/head.json count and hash of the last event
|
|
150
|
+
~/.penthera/memory/<project-id>/meta.json the project's path or origin, for `memory show`
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
`<project-id>` is a SHA-256 of the repo's absolute path plus its git remote URL,
|
|
154
|
+
or of the target origin for URL-only scans. Set `PENTHERA_HOME` to move the
|
|
155
|
+
root (the tests do). Penthera reads the remote from `.git/config` itself rather
|
|
156
|
+
than running `git`, because running git inside an untrusted repo can execute
|
|
157
|
+
that repo's hooks or `core.fsmonitor` command.
|
|
158
|
+
|
|
159
|
+
### What it records
|
|
160
|
+
|
|
161
|
+
One JSON event per line, append-only:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{ "v": 1, "ts": "...", "type": "scan", "data": { ... }, "prev": "<hash of previous line>", "hash": "..." }
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`hash = sha256(prev + canonical JSON of { v, ts, type, data })`, with object
|
|
168
|
+
keys sorted. The first line's `prev` is derived from the project id.
|
|
169
|
+
|
|
170
|
+
| Type | Data |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| `scan` | stack, modes, counts by severity, ids of the actionable findings |
|
|
173
|
+
| `probe_yield` | probe id, stack, findings count |
|
|
174
|
+
| `fix_applied` | finding id, recipe id, framework, category, diff SHA-256 |
|
|
175
|
+
| `fix_verified` / `fix_failed` | finding id (recipe and framework are joined from `fix_applied`) |
|
|
176
|
+
| `fp_suppressed` | finding id, reason, actor, optional expiry |
|
|
177
|
+
| `loop_run` | one `penthera agent --loop` run: the [loopRun](#the-looprun-object) without test output, finding ids only |
|
|
178
|
+
|
|
179
|
+
From these, `penthera memory show` derives four views: recipe success rate per
|
|
180
|
+
framework, active suppressions, probe ranking by yield per stack, and median
|
|
181
|
+
time to fix (first seen in a scan to `fix_verified`).
|
|
182
|
+
|
|
183
|
+
### How a scan uses it
|
|
184
|
+
|
|
185
|
+
Memory can do two things to a report, and nothing else:
|
|
186
|
+
|
|
187
|
+
1. **Suppress** a finding the user (or the loop, on the user's behalf) marked as
|
|
188
|
+
a false positive, with a reason. Suppressed findings move to a separate
|
|
189
|
+
"Suppressed" section in the terminal and Markdown reports, each with who
|
|
190
|
+
suppressed it and why. They do not count toward the exit code.
|
|
191
|
+
2. **Re-order** findings within a severity: categories with a fix recipe that
|
|
192
|
+
has worked on this framework come first, then findings that have shown up in
|
|
193
|
+
more past scans. Severity is never changed and no finding is dropped.
|
|
194
|
+
|
|
195
|
+
## Threat model
|
|
196
|
+
|
|
197
|
+
The learning store is an attack surface. An agent loop that learns from its own
|
|
198
|
+
past is open to memory poisoning (OWASP Agentic Security Initiative, ASI06): if
|
|
199
|
+
an attacker can write to what the loop remembers, they can steer what it does
|
|
200
|
+
next. In Penthera's case the obvious targets are hiding a real finding and
|
|
201
|
+
getting the loop to run something. The store is designed so neither works
|
|
202
|
+
quietly.
|
|
203
|
+
|
|
204
|
+
### Why it never executes
|
|
205
|
+
|
|
206
|
+
Memory is data. No value read from it is ever executed, evaluated, imported,
|
|
207
|
+
used as a file path, or passed to a shell. A recipe id in memory is only a
|
|
208
|
+
string that gets counted; the recipe code lives in Penthera's own source
|
|
209
|
+
(`lib/fix/`) and is chosen by Penthera, not by the log. Every field a view reads
|
|
210
|
+
is type- and length-checked, and an event that fails a check is ignored rather
|
|
211
|
+
than interpreted. Strings shown in the terminal have control characters stripped,
|
|
212
|
+
so a stored reason cannot inject ANSI escape sequences.
|
|
213
|
+
|
|
214
|
+
The worst a fully poisoned memory can do is hide findings, and hidden findings
|
|
215
|
+
are listed, with their reason, in every report.
|
|
216
|
+
|
|
217
|
+
### Why it is hash-chained
|
|
218
|
+
|
|
219
|
+
The chain makes tampering visible. Editing a line, reordering lines, deleting a
|
|
220
|
+
line from the start or middle, or splicing in another project's log all break
|
|
221
|
+
the chain, and `penthera memory verify` names the first broken line. `head.json`
|
|
222
|
+
records the count and hash of the last event, so cutting lines off the end is
|
|
223
|
+
caught too.
|
|
224
|
+
|
|
225
|
+
When the chain is broken, scans **fail closed**: memory suppressions and
|
|
226
|
+
ranking are not applied, nothing new is appended, and the scan prints a warning
|
|
227
|
+
telling you to run `penthera memory verify`. You can then inspect the log or
|
|
228
|
+
start over with `penthera memory forget`.
|
|
229
|
+
|
|
230
|
+
What the chain does not do: it is tamper-evident, not tamper-proof. Anyone who
|
|
231
|
+
can write to your home directory can rewrite the whole log and recompute every
|
|
232
|
+
hash. Keying the chain would not help, since the key would sit in the same home
|
|
233
|
+
directory. The chain is there to catch a partial edit, an accidental truncation,
|
|
234
|
+
or a tool that writes where it should not; it is not a defence against malware
|
|
235
|
+
already running as you.
|
|
236
|
+
|
|
237
|
+
### Why it lives in your home directory
|
|
238
|
+
|
|
239
|
+
Memory is never read from the scanned repo. If it were, a repo could ship
|
|
240
|
+
pre-poisoned memory, for example a suppression for the secret it is about to
|
|
241
|
+
leak. Keeping memory under `~/.penthera` means only runs on your machine, as
|
|
242
|
+
you, write to it.
|
|
243
|
+
|
|
244
|
+
### The one thing a repo can say: `penthera.suppress.json`
|
|
245
|
+
|
|
246
|
+
Teams do need to share decisions like "this key is a revoked test fixture". For
|
|
247
|
+
that a repo may contain `penthera.suppress.json`:
|
|
248
|
+
|
|
249
|
+
```json
|
|
250
|
+
{
|
|
251
|
+
"version": 1,
|
|
252
|
+
"suppress": [
|
|
253
|
+
{ "id": "16e06eb3fd94664b", "reason": "test fixture, revoked", "expires": "2027-01-01" }
|
|
254
|
+
]
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
It is held to a stricter standard than memory:
|
|
259
|
+
|
|
260
|
+
- Every entry needs a reason. Entries without one, with a malformed id or date,
|
|
261
|
+
or past their expiry are dropped with a warning.
|
|
262
|
+
- Every finding it hides is listed in the report as **suppressed by repo file**
|
|
263
|
+
with the reason, so a reviewer sees both the file change in the PR and its
|
|
264
|
+
effect in the report.
|
|
265
|
+
- It only applies with `--memory`, and a local suppression for the same finding
|
|
266
|
+
takes precedence.
|
|
267
|
+
|
|
268
|
+
Treat a change to `penthera.suppress.json` in a pull request like a change to
|
|
269
|
+
CI config: it decides what the scanner reports.
|
|
270
|
+
|
|
271
|
+
### Concurrency
|
|
272
|
+
|
|
273
|
+
Two scans of the same project can run at once. Each append takes an exclusive
|
|
274
|
+
lock file (`events.lock`, created with `O_EXCL`), reads the tip, and writes one
|
|
275
|
+
line with a single `O_APPEND` write. Lines never interleave and the chain never
|
|
276
|
+
forks. A lock older than 30 seconds is treated as stale and removed.
|