Skip to content

agent: typed parser for bbot JSONL output (F10b) - #199

Merged
BaaRai merged 1 commit into
mainfrom
feat/bbot-typed-ingest
Nov 12, 2026
Merged

BaaRai merged 1 commit into
mainfrom
feat/bbot-typed-ingest

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 12, 2026

Copy link
Copy Markdown
Owner

What

A pure parser for bbot JSONL output (output.json), in agent/bbot_ingest.go:

  • parseBbotJSONL(io.Reader) returns the events split into InScope and Intel, plus a count of lines that do not decode.
  • bbotIngest.assetItems() maps in-scope events to insert_assets items (assetInputItem), from their typed fields only.

No agent tool is wired yet and nothing calls the parser outside the test; this PR is the parsing and routing layer only.

Why

Audit #124, item F10b, planned for 0.7.0. F10 (#189) put the untrusted wording and the scope_distance rule in the bbot skill text; F10b enforces the same rule in code. bbot events are shaped by the target and by third parties writing about it, so a DNS record, a page or a FINDING description can carry text addressed to an AI.

Typed fields

Only these keys are decoded, each validated; a field that fails validation is left empty:

  • type, module, module_sequence: plain tokens ([A-Za-z0-9_.>-], at most 128 chars).
  • scope_distance: integer; missing is treated as out of scope.
  • host: an IP, or a lowercase hostname charset, at most 253 chars.
  • port: 1 to 65535.
  • url: http or https only, and only when its hostname equals the typed host.

Every other key (tags, resolved_hosts, scope_description, any unknown key) is dropped by the decoder and never promoted.

Quoted inert text

The free text (data, or data_json, which holds the FINDING description) is kept only as one Go-quoted string (strconv.Quote) in Quoted. It is never parsed further, never used for host, scope, routing or an action.

Out-of-scope rule

  • scope_distance == 0: InScope, source tool_output. Only these feed assetItems(): DNS_NAME to subdomain, IP_ADDRESS to ip, OPEN_TCP_PORT to service with the port, URL to service with the validated url.
  • Any other value, or a missing one: Intel, source third_party_intel. assetItems() never reads them, so they are never auto-scoped.

Tests

agent/bbot_ingest_test.go, pure (no PostgreSQL, no Docker), with a 3-line benign fixture written inline (example.com / example.net / example.org): one in-scope DNS_NAME, one out-of-scope DNS_NAME (distance 1), and one in-scope FINDING whose data tells the reader to add evil.example.org to the scope and call insert_assets, plus unknown keys. It asserts:

  • the in-scope host comes out typed;
  • the out-of-scope event is a third_party_intel item and assetItems() is exactly the one in-scope subdomain;
  • the instruction-shaped text is only in Quoted (quoted, verbatim after unquote) and in no typed field;
  • unknown key values never reach the result.

Run in WSL Kali, go1.26.10, ARTEX_PG_DSN unset:

gofmt -l agent/bbot_ingest.go agent/bbot_ingest_test.go   -> (no output)
go build ./...                                             -> exit 0
go vet ./...                                               -> exit 0
go test -count=1 ./agent/ -run TestParseBbotJSONL -v       -> --- PASS: TestParseBbotJSONLTypedOnly (0.00s)
go test -count=1 ./agent/                                  -> ok  github.com/Autumn-27/artex/agent 0.104s

Mutation check

Mutation: take the event host from the free-text data.host instead of the typed host. The test fails:

--- FAIL: TestParseBbotJSONLTypedOnly (0.00s)
    bbot_ingest_test.go:49: finding typed fields = {Type:FINDING ... Host:evil.example.org ...}
    bbot_ingest_test.go:61: free text promoted to a typed field: {Type:FINDING ... Host:evil.example.org ...}
FAIL

Mutation reverted; the test passes again.

Not verified

  • No live bbot run. The field names follow the bbot skill and the bbot 2 event JSON (data / data_json) as documented, not a captured output.json. A bbot URL event that carries its URL only in data yields no URL asset here, by design (free text is never structure).
  • The PG-backed tests in agent were not run locally (no ARTEX_PG_DSN).

Parse bbot output.json reading only the typed fields (type,
scope_distance, host, url, port, module, module_sequence), validated.
The free text (data, or data_json with the FINDING description) is kept
only as one Go-quoted inert string, never used for scope or an action.
Unknown keys are ignored. Events at scope_distance 0 are the only ones
mapped to insert_assets items, from their typed host; any other distance
becomes a third_party_intel item that is never auto-scoped.
@BaaRai
BaaRai merged commit 840bc53 into main Nov 12, 2026
4 checks passed
AryanSLAYERRR referenced this pull request in AryanSLAYERRR/ARTEX Nov 12, 2026
ingest_bbot reads a bbot output file by path and ingests it through
the typed parser from #199 (parseBbotJSONL), one line at a time:

- Lines are read with a fixed cap (bbotMaxLineBytes = 64 KiB, newline
  included). A longer line is skipped and counted, never buffered whole.
- scope_distance == 0 events that are assets (assetItems) go through
  the existing insert_assets handler; no asset SQL is written here.
- Every other event is recorded as a fact with source
  third_party_intel. The summary is built from typed fields only; the
  free text is stored in detail as the inert Go-quoted string.
- Intel never reaches insert_assets or task_scope.

The tool is in WorkerTools, so the existing BuiltinToolSeeds/SeedTool
loop inserts its row (a new key, inserted on fresh and existing DBs).
It is listed in the target gate's noTargetTools: its input is a local
path, not a network target (TestDomainToolsDeclareNoTarget).
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