Skip to content

feat(hardening): opt-in operator approval for acquiring third-party code - #417

Merged
BaaRai merged 3 commits into
BaaRai:mainfrom
ldevbr:contrib/third-party-approval
Nov 22, 2026
Merged

BaaRai merged 3 commits into
BaaRai:mainfrom
ldevbr:contrib/third-party-approval

Conversation

@ldevbr

@ldevbr ldevbr commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Add opt-in intercept rules (action ask, timeout -> deny) that pause the agent before it downloads from code/exploit hosts, runs git clone, installs packages, or pipes remote content into a shell, plus a third-party-code-review skill (hash, blocklist-check, read and summarize the code before running it).

Nothing is seeded: the rules change no behavior until hardening/apply-intercept-rules.sh is run, and code the agent writes itself is not gated -- only the point where untrusted code enters. Regex patterns are RE2 (verified to compile); the apply script is idempotent.

@BaaRai BaaRai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes. The idea is right, the gate is not.

  1. These ask rules outrank the built-in refusals. intercept/intercept.go Match returns the first rule in priority order, the built-in DELETE and bulk-clear denies are priority 80, and these rules are 95-96. pip install x && curl -X DELETE ... now becomes an approval instead of a refusal. Set these below 80.
  2. hardening/apply-intercept-rules.sh sources .env as shell (set -a; . ./.env). A value containing $(...) executes, and a $ in a secret expands and can leak in an error. Parse KEY=VALUE without evaluation, or use docker compose --env-file.
  3. skills/third-party-code-review/SKILL.md says downloads are gated, but in target-only mode only MatchBuiltin runs, so these rules are never consulted and a git clone passes without a request. Either apply them in that mode or state the limitation in the skill.
  4. The regexes are a safety net, not a gate: tabs, JSON escapes, git -c, pip3.12, curl | tar and bash -c "$(curl ...)" pass, while grep 'npm install' docs/ waits 30 minutes. Say that in the skill and add a test for each bypass you close.
  5. The sha256 blocklist and the /app/keys and DSN prohibition are prose only. Nothing enforces them.

Good: the skill cannot auto-approve, and the SQL structure is correct.

@ldevbr

ldevbr commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in the follow-up commit.

  1. Priority. Dropped from 95-96 to 70-72, below the built-in destructive denies (80/90/100). Since intercept.Match returns the first rule priority-DESC, pip install x && curl -X DELETE ... now hits the built-in DELETE deny (80) instead of being downgraded to an approval.
  2. .env sourcing. apply-intercept-rules.sh no longer sources .env. It runs psql inside the postgres container and reads $POSTGRES_USER/$POSTGRES_DB from the container's own environment — no host-side evaluation of secret values.
  3. Target-only mode. Stated as a limitation in the skill: when only MatchBuiltin runs, these DB rules are not consulted and e.g. a git clone passes with no prompt; the skill still binds the agent. Applying them in that mode is an interceptor change — I left it out of this SQL-only PR; tell me if you'd like that instead.
  4. Regexes are a net, not a gate. Said so explicitly in the skill and README. Closed the named bypasses — pip3.12, git -c, bash -c "$(curl ...)", curl | tar — and documented the ones that remain open (JSON-escaped whitespace, unlisted hosts, base64 -d split from the run) and the grep 'npm install' false positive. Added hardening/rulecheck, which compiles the patterns from the SQL (RE2) and asserts each case: 18 cases, 0 failures, run with go run ./hardening/rulecheck.
  5. Prose-only enforcement. The /app/keys, /proc/<pid>/environ and DSN prohibition is now a deny rule, so it is enforced rather than prose. The SHA-256 blocklist stays agent discipline by nature — a text-matching interceptor can't hash a downloaded file — and the skill now labels it as such instead of implying it's enforced.

@BaaRai BaaRai left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the five original review points: the priority drop to 70-72, the container-env psql (no .env sourcing), the target-only documentation, the closed bypasses, and the enforced deny rule are all solid.

Four small items to close before merge:

  1. /proc/self/environ gap in rule 5. hardening/intercept-rules.sql matches /proc/[0-9]+/environ, which misses /proc/self/environ and /proc/thread-self/environ. Change it to /proc/(?:[0-9]+|self|thread-self)/environ and add a case for it.

  2. Match agents.key instead of a.name. agent_skill_visibility currently filters WHERE a.name IN ('Main', 'Worker', 'Auto', 'Penetration Testing', 'Vulnerability Retest'). Matching on display name silently matches 0 rows if an agent is renamed or localized. Match on agents.key instead.

  3. Wire rulecheck into go test and CI. hardening/rulecheck/main.go is a standalone package main, so go test ./... in CI never runs the 18 assertions. Convert it into a *_test.go so CI executes them on every PR.

  4. Priority-precedence test through intercept.Match. Add a test that runs the loaded rules alongside the built-in rules through intercept.Match and asserts that pip install x && curl -X DELETE ... hits the built-in priority-80 deny rather than the priority-70 ask.

Once those are in, this is ready as an opt-in candidate for the next release.

ldevbr and others added 3 commits November 22, 2026 10:16
Add opt-in intercept rules (action ask, timeout -> deny) that pause the agent
before it downloads from code/exploit hosts, runs git clone, installs packages,
or pipes remote content into a shell, plus a third-party-code-review skill
(hash, blocklist-check, read and summarize the code before running it).

Nothing is seeded: the rules change no behavior until hardening/apply-intercept-rules.sh
is run, and code the agent writes itself is not gated -- only the point where
untrusted code enters. Regex patterns are RE2 (verified to compile); the apply
script is idempotent.
- Priority 95-96 -> 70-72, below the built-in destructive denies (80/90/100),
  so 'pip install x && curl -X DELETE ...' still hits the DELETE deny instead of
  being downgraded to an approval (intercept.Match is priority-DESC).
- apply-intercept-rules.sh no longer sources .env as shell (code execution / $
  expansion). It reads POSTGRES_USER/DB from the postgres container's own env.
- Add a 'deny' rule for reading /app/keys, /proc/<pid>/environ and the DSN, so
  the key/DSN prohibition is enforced, not prose.
- Close named regex bypasses (pip3.12, git -c, bash -c "$(curl)", curl | tar);
  document the remaining open bypasses, the false positive, and the target-only
  limitation in the skill.
- Add hardening/rulecheck: compiles the patterns from the SQL (RE2) and asserts
  positives, closed bypasses, and documented open cases (18 cases, 0 failures).
@BaaRai
BaaRai force-pushed the contrib/third-party-approval branch from 86ab9dd to 9028dfe Compare November 22, 2026 09:21
@BaaRai
BaaRai merged commit 2bd1b71 into BaaRai:main Nov 22, 2026
11 checks passed
@BaaRai

BaaRai commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Thanks @ldevbr. Merged. The approval rules, the review skill and the rulecheck test are in, with the priority below the built-in denies so a destructive command is never downgraded to an approval. The review fixes are included.

AhmedAlhatem pushed a commit to AhmedAlhatem/artex that referenced this pull request Nov 22, 2026
The skill told the agent to append to /app/data/third-party-blocklist.txt, but under agent isolation the data directory is not writable by the executor uid. HOME points at the executor home in both modes and is writable there. Follow-up to BaaRai#417.
Azhar457 pushed a commit to Azhar457/ARTEX that referenced this pull request Nov 22, 2026
Azhar457 pushed a commit to Azhar457/ARTEX that referenced this pull request Nov 22, 2026
The skill told the agent to append to /app/data/third-party-blocklist.txt, but under agent isolation the data directory is not writable by the executor uid. HOME points at the executor home in both modes and is writable there. Follow-up to BaaRai#417.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants