Skip to content

fix(agent-core): try inner JSON objects after an unclosed or mismatched bracket and after invalid outer JSON - #834

Closed
nik13 wants to merge 1 commit into
devfrom
fix/agent-core-embedded-json-rescan
Closed

nik13 wants to merge 1 commit into
devfrom
fix/agent-core-embedded-json-rescan

Conversation

@nik13

@nik13 nik13 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary

agent-core's embedded-JSON scan finds JSON inside free text (tool output, log lines) and redacts credential members structurally. Three shapes kept it from trying the inner JSON objects, so a credential member inside them was only seen by the free-text rules:

  • a stray unclosed bracket before valid JSON: see [ {"api key":"…"};
  • a mismatched closer ending the region: cfg { mode: [ {"api key":"…"} } tail;
  • balanced but invalid outer JSON: [{"password":"…"}, NaN].

The free-text rules miss some credential names, for example a key with a space before the last word ("api key") or a leading underscore ("_password"), so those values were exported.

The scan now tries the inner bracket pairs it has already recorded for that region, and rewrites an object that parses the way it rewrites a top-level one. It tries at most 32 pairs per region, so it stays linear. Output for every input the old scan already handled is unchanged.

Part of TH-11639 (items 1 and 2 of the embedded-JSON follow-ups).

Tests

traceai_agent_core/test/privacy.test.cjs:

  • each shape, alone, nested in larger text and repeated, with idempotence (redact(redact(x)) === redact(x));
  • controls: non-credential JSON after a stray bracket or mismatched closer is unchanged;
  • linearity for adversarial bracket runs and the mismatched-closer path.

An internal pre-review used two lenses, with two skeptics per finding. It confirmed one gap, a mismatched closer that still hid the objects, which is fixed. Nothing was run locally (repo rule); CI runs these tests.

Please weigh

  • The text after a rewritten inner object is kept, as it already is after a valid top-level object. Before, when a credential member had an object or array value in unparsed text, the free-text rule dropped the rest of the text. A credential later in that tail that only that drop-the-rest rule caught (a quoted key with a space, such as "access key":"…") is now exported. The member the rewrite targets is redacted either way.
  • Known gap, not fixed here: an odd " between the stray bracket and the object (see [ " {"api key":"…"}) still hides the object, because the scan reads its brackets as string content. It stays on TH-11639.

🤖 Generated with Claude Code

…ed bracket and after invalid outer JSON

A stray unclosed bracket before valid JSON, a mismatched closer, or a
balanced but invalid outer value (such as a trailing NaN) kept the inner
JSON objects from the structured scan, so a credential member inside
them was only seen by the free-text rules. The scan now tries the inner
pairs it already recorded (at most 32 per region, so it stays linear)
and rewrites an object that parses, as it does a top-level one.

TH-11639

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nik13

nik13 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing for now. Review found that this version redacts less than dev in one shape: keeping the text after a rewritten inner object exposes a later credential that dev's free-text rule dropped. Fixing that statically turned into a second-pass design that has not converged and has not been executed.

Next steps, tracked on TH-11639:

  • check whether quoted-key recognition in the free-text rule (keys such as "api key" and "_password") covers these shapes more simply;
  • if a structural rescan is still needed, build it against an executed oracle: a frozen copy of dev's rule chain and a generated corpus, asserting "never less than dev" and idempotence in CI.

@nik13 nik13 closed this Dec 2, 2026
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