Skip to content

feat(intercept): target extraction, resolver, exemptions and the gate in the hook (S3b 1.5-1.7) - #179

Merged
BaaRai merged 1 commit into
mainfrom
feat/target-gate-extract-resolve-gate
Nov 11, 2026
Merged

BaaRai merged 1 commit into
mainfrom
feat/target-gate-extract-resolve-gate

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Steps 1.5, 1.6 and 1.7 of the S3b phase 1 plan: the approval gate for asset targets now decides. Builds on #177 (hooks and scope) and #178 (schema, flag, requests).

The gate is opt-in per task and per conversation (target_gate, default off). With the flag off nothing changes: no extraction, no DNS lookup, no store read. No UI in this phase.

What it does

For a tool call of a gated session:

  1. Extract the targets the call declares (intercept.ExtractTargets): WebFetch url exactly; Bash, shell_open, Monitor (command) and shell_send (text) with command-string rules (URLs with a scheme, IP literals, IP:port, host:port, CIDR); every string of the input for MCP tools, custom tools and any tool the gate does not know. ExecuteExtraTool is unwrapped to the inner tool. Targets are normalised to (kind, host, port).
  2. Tool rules and judge run as before. A deny blocks first, before any target request exists.
  3. Asset block rules (global and of the task) on the name and on its resolved addresses: TARGET_RULE_BLOCKED.
  4. Exemptions: exact host + port. Derived from the configuration (LLM gateways, search backend in use, platform proxies), never resolved and never voided; or stored (target_gate_exempt_hosts, seeded once with the package sources), resolved and void when any address is private, loopback, link-local, unspecified, unique-local, multicast or a metadata address.
  5. Resolve: system resolver, A and AAAA, 3 s per lookup, positive answers cached 10 s per host, failures never cached, always fresh when a request is raised. A name that does not resolve: TARGET_RESOLVE_FAILED, no request.
  6. Pin lookup: a (host, 0) pin covers every port; a (host, 443) pin covers 443 only and never a target without a declared port; address sets of two pins are never merged.
  7. Request every uncovered target (at most 5 per call, else TARGET_TOO_MANY), merged with a pending ask of a rule or of the judge when the call creates the row. Wait up to the scope's bound (300 s; 0 in the final settlement round).
  8. Check again after the decisions; the call runs only if every target is covered. Bounded to three passes.

A rule allow, a judge allow, a timeout and an exemption never pin. Only Decide on a human click does.

Owner conditions

  • With global_proxy set every pin is name-only at call time, whatever name_only_effective says in the row: TestProxySetAfterApprovalNeitherBlocksNorAsks (hook, PostgreSQL), TestProxyTurnedOnAfterApprovalMakesPinNameOnly, TestUpstreamProxyMakesPinsNameOnlyAtCallTime.
  • An approval never pins zero addresses: db.ErrTargetPinEmpty in the pin writer (the row stays pending, an existing pin is not re-issued), RequestTargets refuses to open such a request, the decide endpoint answers 422. TestTargetPinRefusesEmptyAddressList, TestApprovalNeverPinsEmptyAddressList, TestInterceptDecideRefusesEmptyPinOverHTTP.
  • Void rule per class: seeded and operator-added names, operator IP literals (private unicast allowed; link-local, metadata, loopback, unspecified, multicast never), derived entries never voided. TestStoredExemptionVoidOnPrivateOrLoopback, TestSeededExemptionIsVoidOnPrivateAddress, TestStoredExemptionOnIPLiteral, TestDerivedExemptionNotVoidedByPrivateAddress, TestEntryInBothOriginsIsDerived.
  • GET / PUT /api/target-gate/exemptions (and GET .../history): settings table, append-only target_gate_exemption_log written in the same transaction, ValidateExemptionHost on the normalised host. TestTargetGateExemptionsAPI, TestExemptionChangeIsLogged.
  • Port precedence: TestPinPortPrecedence.
  • The target-only guard records blocks only: TestTargetOnlyGuardRecordsBlocksOnly.
  • Gate off is unchanged: TestGateOffLeavesEveryBranchUnchanged, TestGateOffTouchesNothing, TestTargetGateConversationScope, TestTaskGuardsRunTargetGate.

Not in this PR

  • Step 1.8: rendered targets of custom tools.
  • Step 1.9: redirect targets of WebFetch and of the custom http tool (needs a Norma tag).
  • Subprocess paths stay advisory (D9): the TestBypass_* tests document what the gate does not see.

… in the hook (S3b 1.5-1.7)

The approval gate for asset targets now decides. It is opt-in per task and
per conversation (target_gate, default off). With the flag off nothing is
extracted, resolved, read or written, and every branch of the hook behaves as
before. No UI.

Extraction and normalisation (1.5)
- intercept.NormalizeTarget: lower case, trailing dot, userinfo, IPv6
  brackets, IPv4-mapped IPv6, decimal / hex / octal / short IPv4, percent-
  encoded host, punycode; port explicit, else the scheme default, else 0.
- intercept.ExtractTargets: WebFetch url exactly; Bash, shell_open, Monitor
  (command) and shell_send (text) with the command-string rules (URL with a
  scheme, IP, IP:port, host:port, CIDR; a bare name is not a target); every
  string of the input for MCP tools, custom tools and any tool the gate does
  not know. ExecuteExtraTool is unwrapped to the inner tool. The platform's
  domain tools, the file tools and web_search have no target.
- The fields are decoded as the tools decode them (key case, last duplicate),
  and a URL authority that reads differently quoted and unquoted yields both
  readings.

Resolver, exemptions, gate decision (1.6)
- Resolver interface, system implementation (A and AAAA), 3 s per lookup,
  positive answers cached 10 s per host with collapsed lookups, failures and
  empty answers never cached, always fresh when a request is raised.
- Exemptions are exact host + port. Derived from the configuration (LLM
  gateways, search backend in use, platform proxies): computed on every call,
  never resolved, never voided. Stored (settings key
  target_gate_exempt_hosts, seeded once with the package sources): resolved,
  and void when any address is private, loopback, link-local, unspecified,
  unique-local, multicast or a metadata address. An entry in both origins
  counts as derived. A stored IP literal that can never be exempt does not
  apply.
- GET / PUT /api/target-gate/exemptions and GET .../history. A change is
  validated (ValidateExemptionHost on the normalised host) and appended to
  target_gate_exemption_log in the transaction that stores it.
- Interceptor.CheckTargets: asset block rules (global and of the task) on the
  name and its addresses, exemptions, resolution, pin lookup. A (host, 0) pin
  covers every port; a (host, 443) pin covers 443 only and never a target
  without a declared port; two pins are never merged. At most 5 unpinned
  targets per call. Codes: TARGET_RULE_BLOCKED, TARGET_RESOLVE_FAILED,
  TARGET_TOO_MANY, TARGET_GATE_UNAVAILABLE; none opens a request.
- With the upstream egress proxy set every pin is name-only at call time,
  whatever name_only_effective says in its row.
- An approval never pins zero addresses: the pin writer refuses a request
  that displays none (db.ErrTargetPinEmpty, 422 on the decide endpoint, the
  row stays pending) and RequestTargets does not open one.
- Every block, and the first use per process of each exemption and of each
  pin version, is a decided row (decided_by system, decision_source target).

The gate in the hook (1.7)
- guard.applyIntercept: a deny by a rule or by the judge blocks first, before
  any target request exists; then CheckTargets; an allow is logged as before
  and does not satisfy the gate; an ask and an unpinned target share one
  request, and the classic ask is raised only when it was not merged. The
  call is checked again after the decisions, at most three passes.
- The gate applies to every tool of a gated session, enabled for rules or
  not, and to the target-only guard of the planner and the main agent, which
  still records blocks only.
- Target blocks have their own model-facing text, built from the code and the
  reason of the result.

Not in this change: rendered targets of custom tools (1.8) and redirect
targets (1.9). Subprocess paths stay advisory; the TestBypass_* tests document
what the gate does not see.
@BaaRai
BaaRai merged commit ec3db7f into main Nov 11, 2026
4 checks passed
@BaaRai BaaRai mentioned this pull request Nov 11, 2026
usinfosec pushed a commit to usinfosec/ARTEX that referenced this pull request Nov 17, 2026
…er-sort

feat(traffic): 流量列表支持内容检索、路径/状态码/长度筛选与列排序 (BaaRai#177)
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.

1 participant