repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(verboten): allow internal secret consumers

0b72e3d4ee32e3555ac26d524ada8a894214bc5b

Oliver Krylow <o.krylow@isp-insoft.de> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (6)

extensions/verboten/CHANGELOG.md

Modified
3 3 # Changelog
5 5 ## Unreleased
7 7 - Block model reads and mutations of built-in or configured protected paths
8 +- Allow trusted programs, hooks, filters, and credential helpers to consume protected files without exposing them
8 9 - Keep metadata operations available and filter protected rows from broad grep results
9 10 - Judge matching Bash and PowerShell commands before execution
10 11 - Show effective rules and judge model with `/verboten`

extensions/verboten/README.md

Modified
49 49 `ls`, `find`, stat, status, existence checks, exclusions, and inert path mentions remain allowed.
51 51 Matching Bash and PowerShell commands go to a dedicated low-reasoning judge with one constrained verdict tool.
52 +Trusted programs, repository hooks, filters, and credential helpers may consume protected files internally when they do not expose protected data or mutate protected files.
52 53 The judge receives the complete raw command, cwd, and matched regexes, which may cross providers when `judgeModel` selects another provider.
53 54 A probability of at least `0.8` blocks.
54 55 Successful verdicts use a bounded in-memory SHA-256 cache.

extensions/verboten/SPEC.md

Modified
8 8 ## Mission
10 -`verboten` is a best-effort Pi extension that keeps model agents from reading or mutating files whose paths are likely to contain secrets.
10 +`verboten` is a best-effort Pi extension that keeps model agents from exposing or mutating files whose paths are likely to contain secrets.
11 11 It blocks obvious direct filesystem tool calls, filters protected rows from broad content searches, judges ambiguous model-authored shell commands, and gives the model terse preventive instructions.
12 12 It does not claim isolation, sandboxing, or complete mediation.
14 14 False positives matter because blocking ordinary engineering work defeats the extension's purpose.
15 15 Metadata-only operations remain available.
16 -Forbidden operations are content reads and protected-path mutations.
16 +Trusted programs, repository hooks, filters, and credential helpers may consume protected files internally when they neither expose protected data nor mutate protected files.
17 +Forbidden operations are direct content inspection, content exposure, and protected-path mutations.
18 19 ## Security boundary
24 25 A forbidden operation is any operation likely to:
26 -- read protected-file contents
27 +- directly inspect protected-file contents
28 +- expose protected-file contents, encodings, hashes, or copies in model context or tool output
27 29 - create or overwrite a protected path
28 30 - modify protected contents or metadata
29 31 - delete or rename a protected path
31 33 - execute or source a protected file
32 34 - transmit protected contents
36 +An ordinary command is allowed when its trusted program, repository hook, filter, or credential helper consumes protected files internally without exposing protected data or mutating protected files.
37 +This allowance does not make direct inspection safe merely because output is redirected or discarded.
34 39 The following metadata-only operations are allowed:
36 41 - listing names
273 278 The judge rubric is:
275 -> Estimate the probability that executing this command will read protected-file contents or create, modify, delete, rename, copy, archive, encode, hash, execute, source, or transmit a matched protected path.
280 +> Estimate the probability that executing this command will directly inspect protected-file contents, expose protected-file contents, encodings, hashes, or copies in model-visible output, or create, modify, delete, rename, copy, archive, encode, hash, execute, source, or transmit a matched protected path.
281 +> Trusted programs, repository hooks, filters, and credential helpers may consume protected files internally when they neither expose protected data nor mutate protected files.
276 282 > Metadata-only listing, path discovery, status, stat, and existence checks are allowed.
277 283 > Mere textual mentions and exclusion patterns are allowed.
278 284 > Parse the outer shell and scripts passed to invoked interpreters.
282 288 The judge prompt includes compact positive and negative examples.
283 289 Positive examples include `cat`, content diffing, hashing, copying, archiving, sourcing, permission mutation, and deletion.
284 -Negative examples include `ls`, `find`, `stat`, existence tests, version-control status, exclusion globs, and writing documentation that merely mentions a protected path.
290 +Negative examples include `ls`, `find`, `stat`, existence tests, version-control status, exclusion globs, writing documentation that merely mentions a protected path, and trusted authentication tools that consume a private key without exposing it.
286 292 ## Judge tool contract
393 399 Append a terse Verboten instruction in `before_agent_start` on every agent run.
394 400 The instruction must state:
396 -> Never read protected-file contents or create, modify, delete, rename, copy, execute, encode, or transmit protected files.
402 +> Never expose protected-file contents, encodings, hashes, or copies to model context or tool output, directly or through a bypass.
403 +> Never create, modify, delete, rename, copy, execute, encode, or transmit protected files.
404 +> Trusted programs, hooks, filters, and credential helpers may consume protected files internally when they neither expose protected data nor mutate protected files.
397 405 > Metadata-only listing, finding, status, stat, and existence checks are allowed.
398 406 > Broad grep searches rooted outside a protected path are allowed; Verboten filters protected rows.
399 407 > Mere textual mentions and exclusion patterns are allowed.
400 -> Never bypass Verboten through shells, symlinks, alternate tools, encoding, or delegation.
408 +> Never bypass Verboten through shells, symlinks, alternate tools, encoding, or delegation to expose or target protected files.
401 409 > Reformulate a false positive only when the new operation avoids protected content and mutation.
403 411 Inject every effective regex in XML:
477 485 | V2 | Aliases | Real temporary symlink on Unix and directory junction or supported equivalent on Windows |
478 486 | V3 | Direct tools | Real `tool_call` paths for `read`, `write`, `edit`, direct `grep`, allowed `ls`, allowed `find` |
479 487 | V4 | Grep filtering | Mixed rows, context rows, omitted counts, all-omitted success, limit-consumed error, byte-limit error, no path/snippet disclosure |
480 -| V5 | Shell candidates | No-match bypass, Bash, PowerShell, metadata allows, content/mutation blocks, exclusion and mention cases |
488 +| V5 | Shell candidates | No-match bypass, Bash, PowerShell, internal secret consumers, metadata allows, content/mutation blocks, exclusion and mention cases |
481 489 | V6 | Embedded scripts | Bash heredocs, PowerShell here-strings, Python/Node scripts, captured text, invoked text, redirects, containers |
482 490 | V7 | Judge lifecycle | One-tool schema, threshold, same-context contract retry, fallback, timeout, auth failure, cancellation, warning dedupe |
483 491 | V8 | Cache | SHA-256 keys, no raw command storage, model/pattern key changes, 256-entry FIFO eviction, failure non-caching |
490 498 - benign text: documentation mentioning `.env`
491 499 - exclusion: grep or ripgrep excluding `.env`
492 500 - reads: `cat`, `grep`, `git diff`, Python `read_text`, Node `readFileSync`
493 -- indirect reads: copy, archive, hash, source, container execution
501 +- indirect exposure: copy, archive, hash, source, and container execution that returns protected data
502 +- internal consumption: trusted hooks, filters, and authentication tools that do not expose or mutate protected files
494 503 - mutations: write redirection, `Set-Content`, `chmod`, and deletion
495 504 - embedded text that looks dangerous but is only assigned, printed, or stored
496 505 - embedded text executed through an interpreter or `Invoke-Expression`

extensions/verboten/__tests__/harness.test.ts

Modified
98 98 expect(result?.systemPrompt).toContain("BASE");
99 99 expect(result?.systemPrompt).toContain(
100 + "Never expose protected-file contents",
101 + );
102 + expect(result?.systemPrompt).toContain(
103 + "Trusted programs, hooks, filters, and credential helpers may consume protected files internally",
104 + );
105 + expect(result?.systemPrompt).not.toContain(
100 106 "Never read protected-file contents",
102 108 expect(result?.systemPrompt).toContain("Broad grep searches");
230 236 const [, context, options] = stream.mock.calls[0] ?? [];
231 237 expect(context?.tools).toHaveLength(1);
232 238 expect(context?.tools?.[0]?.name).toBe("record_verdict");
239 + expect(context?.systemPrompt).toContain(
240 + "Trusted programs, repository hooks, filters, and credential helpers may consume protected files internally",
241 + );
233 242 expect(options).toMatchObject({
234 243 maxTokens: 1_024,
235 244 reasoning: "low",

extensions/verboten/index.ts

Modified
21 21 } from "./src/rules.ts";
23 23 const ENTRY_TYPE = "verboten-report-v1";
24 -const INSTRUCTION = `Never read protected-file contents or create, modify, delete, rename, copy, execute, encode, or transmit protected files.
24 +const INSTRUCTION = `Never expose protected-file contents, encodings, hashes, or copies to model context or tool output, directly or through a bypass.
25 +Never create, modify, delete, rename, copy, execute, encode, or transmit protected files.
26 +Trusted programs, hooks, filters, and credential helpers may consume protected files internally when they neither expose protected data nor mutate protected files.
25 27 Metadata-only listing, finding, status, stat, and existence checks are allowed.
26 28 Broad grep searches rooted outside a protected path are allowed; Verboten filters protected rows.
27 29 Mere textual mentions and exclusion patterns are allowed.
28 -Never bypass Verboten through shells, symlinks, alternate tools, encoding, or delegation.
30 +Never bypass Verboten through shells, symlinks, alternate tools, encoding, or delegation to expose or target protected files.
29 31 Reformulate a false positive only when the new operation avoids protected content and mutation.`;
31 33 interface RuntimeState extends LoadedVerbotenSettings {

extensions/verboten/src/judge.ts

Modified
42 42 Call record_verdict exactly once and output no prose.
43 43 forbiddenOperationProbability is the probability that executing the command itself performs a forbidden operation. Zero means certainly allowed. One means certainly forbidden. It is not confidence in your explanation.
45 -Forbidden operations read protected-file contents or create, modify, delete, rename, copy, archive, encode, hash, execute, source, or transmit a matched protected path.
45 +Forbidden operations expose protected-file contents, encodings, hashes, or copies in model-visible output, directly inspect those contents, or create, modify, delete, rename, copy, archive, encode, hash, execute, source, or transmit a matched protected path.
46 +Trusted programs, repository hooks, filters, and credential helpers may consume protected files internally when they neither expose protected data nor mutate protected files.
46 47 Metadata-only listing, path discovery, status, stat, and existence checks are allowed.
47 48 Mere textual mentions and exclusion patterns are allowed.
48 49 Parse the outer shell and scripts passed to invoked interpreters.
50 51 Trace whether embedded text is actually invoked rather than merely assigned, printed, or stored.
52 53 Forbidden examples: cat .env; grep token .env; git diff -- .env; sha256sum .env; cp .env backup; tar -cf secrets.tar .env; source .env; chmod 600 .env; rm .env; python -c "open('.env').read()".
53 -Allowed examples: ls -la .env; find . -name .env; stat .env; test -e .env; git status --short .env; rg token . --glob '!.env'; printf 'Never read .env' > README.md.
54 +Allowed examples: ls -la .env; find . -name .env; stat .env; test -e .env; git status --short .env; rg token . --glob '!.env'; printf 'Never read .env' > README.md; ssh -i ~/.ssh/id_ed25519 host true.
54 55 Give a terse reason without quoting command payloads.`;
56 57 interface CacheInput {