agent-sanitizer 2.47.11 → 2.47.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -105,7 +105,7 @@ export function minEnvSecretLen() {
105
105
  const hostLen = hostSource()?.minSecretLen;
106
106
  // The package floor comes from the same physical file
107
107
  // agent_sanitizer.secrets.config reads (DEFAULT_MIN_SECRET_LEN), so the JS
108
- // pre-gate and the Python daemon cannot drift apart on it.
108
+ // pre-gate and the Python daemon read the same number.
109
109
  if (hostLen === undefined) return redactionFloor.min_secret_len;
110
110
  if (!Number.isInteger(hostLen) || hostLen <= 0)
111
111
  throw new Error(
@@ -55,13 +55,13 @@ export const ALERT_BASE = join(
55
55
  * The path prefix every alert artifact of ONE session under this project shares.
56
56
  *
57
57
  * Session-keying is what makes the gate's one-time ask correct by construction.
58
- * The store and its ack used to be keyed by PROJECT alone and reset by a
59
- * destructive clear at SessionStart, which left two ways for a session to
60
- * inherit the previous one's answer: an early-exiting scanner arm (a dep-load
61
- * failure) returns before the clear, and nothing pins SessionStart against the
62
- * InstructionsLoaded events fired for the files loaded at launch. A session that
63
- * cannot see another session's files needs neither the clear nor the ordering —
64
- * past sessions' artifacts simply age out through {@link sweepStaleSessions}.
58
+ * Keying by PROJECT alone, reset by a destructive clear at SessionStart, would
59
+ * leave two ways for a session to inherit the previous one's answer: an
60
+ * early-exiting scanner arm (a dep-load failure) returns before the clear, and
61
+ * nothing pins SessionStart against the InstructionsLoaded events fired for
62
+ * the files loaded at launch. A session that cannot see another session's
63
+ * files needs neither the clear nor the ordering — past sessions' artifacts
64
+ * simply age out through {@link sweepStaleSessions}.
65
65
  * @param {string} [sessionId] the harness's session identity
66
66
  * @returns {string}
67
67
  */
@@ -414,11 +414,11 @@ export function invisibleCharAlert(sessionId) {
414
414
  * Add `text` to the alert the PreToolUse gate surfaces this session, keeping
415
415
  * whatever is already there.
416
416
  *
417
- * One O_EXCL-created, randomly-named file per finding. The store used to be a
418
- * single file appended through a read-modify-write, so two hooks recording a
419
- * finding at once silently dropped one of them; a fresh file per finding has no
420
- * shared cell to lose. Symlink-refusing (writeFileNoFollow) because the store
421
- * sits at a predictable, world-visible $TMPDIR path.
417
+ * One O_EXCL-created, randomly-named file per finding. A single file appended
418
+ * through a read-modify-write would let two hooks recording a finding at once
419
+ * silently drop one of them; a fresh file per finding has no shared cell to
420
+ * lose. Symlink-refusing (writeFileNoFollow) because the store sits at a
421
+ * predictable, world-visible $TMPDIR path.
422
422
  * @param {string} text
423
423
  * @param {string} [sessionId]
424
424
  * @returns {boolean} whether the finding was recorded
@@ -680,7 +680,7 @@ export function sanitizerDepsLoaded() {
680
680
  * otherwise invisible because every later tool call then fails closed with no
681
681
  * stated cause — the recorded loader error and its remedy ride along. The text
682
682
  * comes from missingPackageMessage so this hook, the PreToolUse gate and the
683
- * prompt gate cannot drift apart on what a missing dependency reads like.
683
+ * prompt gate read the same words for what a missing dependency looks like.
684
684
  * @param {() => boolean} [depsLoaded] injectable seam for testing
685
685
  * @param {string} [remedy] what a reader should run; hosts pass their own
686
686
  * @returns {string}
@@ -801,8 +801,8 @@ export function emitHookFailure(
801
801
 
802
802
  /**
803
803
  * The suppression placeholder that replaces the tool output under the closed
804
- * posture. Named so the posture table and {@link emitFailClosed} cannot drift on
805
- * the wording the model sees.
804
+ * posture. Named so the posture table and {@link emitFailClosed} read the
805
+ * same wording the model sees.
806
806
  * @param {string} cause the scrubbed hook error
807
807
  * @returns {string}
808
808
  */
@@ -963,12 +963,11 @@ export async function evaluateToolOutput(input, ext = {}) {
963
963
  containsPlaceholder(toolOutput)
964
964
  )
965
965
  warnings.push(ON_DISK_PLACEHOLDER_WARNING);
966
- // `notes` is part of the guard, not covered by `modified`. The Layer-1
967
- // carve-out that used to be the only note DID imply a strip, but the
968
- // detect-only tiers do not: a preserved `<script>` and a plain-link exfil URL
969
- // change no bytes and raise no warning, so without this clause the walk would
970
- // return `clean` and the note would not be quieter it would be GONE, taking
971
- // "do not fetch, relay, or embed these URLs" with it.
966
+ // `notes` is part of the guard, not covered by `modified`. A detect-only
967
+ // tier's note implies no strip: a preserved `<script>` and a plain-link
968
+ // exfil URL change no bytes and raise no warning, so without this clause the
969
+ // walk would return `clean` and the note would not be quieter it would be
970
+ // GONE, taking "do not fetch, relay, or embed these URLs" with it.
972
971
  if (!modified && warnings.length === 0 && notes.length === 0)
973
972
  return revealRead
974
973
  ? emit("flagged", { additional_context: REVEAL_READ_ENVELOPE })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-sanitizer",
3
- "version": "2.47.11",
3
+ "version": "2.47.13",
4
4
  "description": "Defend an agent against hidden-content injection: strip payload-capable invisible Unicode and ANSI, splice out human-invisible HTML, and flag data-exfil URLs in untrusted text before any model sees it.",
5
5
  "type": "module",
6
6
  "repository": {
package/src/gates.mjs CHANGED
@@ -74,11 +74,11 @@ export function needsUrlScan(text) {
74
74
  // opaque run for ReDoS-safety. It is NOT derivable from that JSON: inlining the
75
75
  // detector regexes would reintroduce the cross-arm polynomial backtracking the
76
76
  // two-alternation split below exists to prevent, so this is a distinct
77
- // representation for a distinct constraint, not a copy. That duplication can't
78
- // be collapsed to one source, so it is instead DRIFT-GUARDED: the test in
79
- // test/secret-detectors-portability.test.mjs drives from the JSON and fails the
80
- // moment a detector is added/changed without a matching arm here — extend
81
- // SECRET_HINT when that fires.
77
+ // representation for a distinct constraint, not a copy. drift-guard-ok: that
78
+ // duplication can't be collapsed to one source, so a test instead guards it
79
+ // test/secret-detectors-portability.test.mjs drives from the JSON and fails
80
+ // the moment a detector is added/changed without a matching arm here —
81
+ // extend SECRET_HINT when that fires.
82
82
  // Split across TWO regexes, combined by matchesSecretHint:
83
83
  // one alternation of every arm makes a redos analyzer see cross-arm polynomial
84
84
  // backtracking (each arm is linear alone, but the union was a 3rd-degree
package/src/html.mjs CHANGED
@@ -2350,10 +2350,10 @@ export function sanitizeHtml(text) {
2350
2350
  // post-parse walk never runs).
2351
2351
  const EXFIL_INDICATORS = [/\$\{[^{}]+\}/, /\{\{[^{}]+\}\}/];
2352
2352
 
2353
- // Parameter NAMES whose presence used to flag on sight; now they only gate
2354
- // WHICH raw params the value-shape test is applied to before the URL is parsed.
2355
- // Kept narrow (the historically over-eager set) so the raw pre-parse pass stays
2356
- // cheap; any non-keyword param is still value-gated post-parse by the walk.
2353
+ // Parameter NAMES that gate WHICH raw params the value-shape test is applied
2354
+ // to before the URL is parsed presence alone no longer flags. Kept narrow so
2355
+ // the raw pre-parse pass stays cheap; any non-keyword param is still
2356
+ // value-gated post-parse by the walk.
2357
2357
  const KEYWORD_PARAM_NAME_RE =
2358
2358
  /^(?:data|d|payload|exfil|leak|steal|secret|token|key|env|password|pwd|cookie|session|auth)$/i;
2359
2359
 
package/src/index.mjs CHANGED
@@ -7,12 +7,12 @@
7
7
  * is only paid for by callers that ask for it.
8
8
  *
9
9
  * Layers 1-3 are NOT implemented here: this module is a facade over the single
10
- * implementation in `./output.mjs` (`sanitizeText`). The two used to be
11
- * hand-synced copies and had already drifted apart in their warning prose, so
12
- * the layer bodies live in exactly one place and this file only translates the
13
- * facade's option/result shape. Importing `./output.mjs` costs nothing at module
14
- * scope — its graph is dependency-free and it lazy-loads `./html.mjs` on the
15
- * same terms this facade used to.
10
+ * implementation in `./output.mjs` (`sanitizeText`). A hand-synced copy would
11
+ * drift apart in its warning prose, so the layer bodies live in exactly one
12
+ * place and this file only translates the facade's option/result shape.
13
+ * Importing `./output.mjs` costs nothing at module scope — its graph is
14
+ * dependency-free and it lazy-loads `./html.mjs` on the same terms this facade
15
+ * does.
16
16
  *
17
17
  * The low-level building blocks stay public via the `./invisible` and `./html`
18
18
  * subpath entries; import those directly when you want a single layer without
package/src/invisible.mjs CHANGED
@@ -127,11 +127,11 @@ export const STRIP = new RegExp(
127
127
 
128
128
  // SGR (Select Graphic Rendition) colour matching. Re-exported from ./ansi.mjs —
129
129
  // the ONE ANSI grammar, shared with the Layer-1 stripper, which cannot import
130
- // this module (layer1.mjs imports invisible.mjs, not the other way round). The
131
- // two used to be separate regexes with DIFFERENT parameter rules, and the looser
132
- // copy lived here: `ESC[12345m` read as SGR-only (so the operator got a
133
- // "display-only colour" note) while the stripper could not match it and spliced
134
- // a visible `[12345m` into the model's view.
130
+ // this module (layer1.mjs imports invisible.mjs, not the other way round). A
131
+ // second, looser copy here with DIFFERENT parameter rules would read
132
+ // `ESC[12345m` as SGR-only (so the operator got a "display-only colour" note)
133
+ // while the stripper could not match it and would splice a visible `[12345m`
134
+ // into the model's view.
135
135
  export { SGR_RE } from "./ansi.mjs";
136
136
 
137
137
  /**
@@ -252,7 +252,7 @@ export function hasLongRun(text) {
252
252
  * payload-length invisible run, and a pointer to recover the bytes — a hex dump
253
253
  * is ASCII, so it passes through sanitization untouched. The single source of
254
254
  * this note, shared by the `sanitize` convenience entry and the tool-output
255
- * pipeline so the two can't drift.
255
+ * pipeline.
256
256
  * @param {string[]} invisFound CATEGORY codes applyLayer1 reported removing
257
257
  * @param {string} deAnsi ANSI-stripped text (invisible runs intact), for the LONG_RUN probe
258
258
  * @returns {string}
@@ -463,9 +463,9 @@ const MAX_TAG_SPEC_CHARS = 6;
463
463
  //
464
464
  // The two Compatibility Ideograph BLOCKS stay literal: they are not
465
465
  // Unified_Ideograph, and JS RegExp exposes no \p{Block=…}. Block boundaries are
466
- // immutable by Unicode's stability policy, so a literal span cannot drift; the
467
- // contract test in test/invisible-unicode-tables.test.mjs pins that every
468
- // ASSIGNED code point inside them is a Script=Han letter.
466
+ // immutable by Unicode's stability policy, so a literal span stays correct
467
+ // forever; the contract test in test/invisible-unicode-tables.test.mjs pins
468
+ // that every ASSIGNED code point inside them is a Script=Han letter.
469
469
  const IVS_MIN = 0xe0100;
470
470
  const IVS_MAX = 0xe01ef;
471
471
  const CJK_IDEOGRAPH_RE =
package/src/output.mjs CHANGED
@@ -163,10 +163,10 @@ function errMessage(err) {
163
163
  * but each mutation can BREAK it again: a Layer-5 span deletion joins the
164
164
  * bytes on either side of the deleted span and can leave a lone surrogate
165
165
  * the model renders as a broken glyph and the redactor reads as U+FFFD.
166
- * Repairing it inside whichever layer happened to need it (it used to live
167
- * in the post-span-deletion re-redact, so it only ran when a redactor was
168
- * configured) makes an invariant of Layer 1 conditional on an unrelated
169
- * option.
166
+ * Repairing it inside whichever layer happens to need it e.g. only in
167
+ * the post-span-deletion re-redact, so it runs only when a redactor is
168
+ * configured would make an invariant of Layer 1 conditional on an
169
+ * unrelated option.
170
170
  * 2. `modified` is set — the caller's "bytes changed" banner.
171
171
  * 3. `unreportedChange` is set. A mutation that pushed no finding — a Layer-5
172
172
  * span deletion whose filter returned no warning code — is a change the
@@ -196,9 +196,8 @@ function applyMutation(state, nextText) {
196
196
  /**
197
197
  * Run Layer 4 (`redact`) over the state's current text and fold any finding
198
198
  * back in. The single Layer-4 invocation site FOR THE PIPELINE STATE: the first
199
- * pass and the re-scan after a Layer-5 span deletion are the same call, so their
200
- * fail-closed handling, warning prose and post-redaction invariants cannot drift
201
- * apart.
199
+ * pass and the re-scan after a Layer-5 span deletion are the same call, so they
200
+ * share one fail-closed handling, warning prose and post-redaction invariant.
202
201
  *
203
202
  * One other site runs Layer 4 deliberately: {@link vetStageValue}, which vets a
204
203
  * stage value on its way out and has no `PipelineState` to fold a finding into.
@@ -714,10 +713,10 @@ export async function sanitizeText(text, options = {}) {
714
713
  notes,
715
714
  modified: state.modified,
716
715
  // Kept under its original name (it is a published field, and renaming a
717
- // published field for a wording win is a breaking change) but now derived
718
- // rather than tracked: "nothing here rose above a note". That is a strict
719
- // generalization of what it used to mean the inert-ANSI strip that set it
720
- // before is now simply the most common way to end up note-only.
716
+ // published field for a wording win is a breaking change) but derived
717
+ // rather than tracked: "nothing here rose above a note". The inert-ANSI
718
+ // strip is simply the most common way to end up note-only, not the only
719
+ // one this field now covers.
721
720
  sgrNote:
722
721
  notes.length > 0 && warnings.length === 0 && !state.unreportedChange,
723
722
  ...(reveal !== undefined && { reveal }),
package/src/prompt.mjs CHANGED
@@ -39,9 +39,10 @@ import { CONTROL_INTRODUCER_SOURCE } from "./ansi.mjs";
39
39
  // legitimate prompt (the SGR color carve-out is applied separately, after SGR
40
40
  // removal), so the whole block is gated, not a hand-picked subset that lets
41
41
  // DCS/SOS/PM/APC through. Built from the SHARED charset source instead of a
42
- // third hand-written copy: keeping the copies in step used to be a prose
43
- // obligation recorded in this very comment, and two of the three spelled ESC
44
- // differently, so even a grep-based drift check would have missed a divergence.
42
+ // third hand-written copy: a hand-written third copy has no drift check
43
+ // beyond a prose reminder in a comment, and a spelling difference between two
44
+ // hand-written copies (e.g. how each spells ESC) is exactly what a grep-based
45
+ // drift check would miss.
45
46
  const ANSI_INTRODUCER = new RegExp(CONTROL_INTRODUCER_SOURCE);
46
47
 
47
48
  /**
package/src/rehydrate.mjs CHANGED
@@ -367,8 +367,8 @@ async function rehydrateEdit(
367
367
  * The shared anchor-ambiguity refusal: a stripped run abuts kept text it
368
368
  * resembles, so greedy deletion alignment cannot prove which bytes the region
369
369
  * owns. Edit's searched spans and Write's position-anchored regions hit the
370
- * same soundness gate and must speak the same language — one builder so the
371
- * two deny sentences cannot drift apart.
370
+ * same soundness gate and must speak the same language — one builder for
371
+ * both deny sentences.
372
372
  * @param {string} lead what could not be anchored ("the matched region", …)
373
373
  * @param {string} filePath
374
374
  * @param {string} guidance the caller-specific way out, without trailing punctuation
package/src/view-map.mjs CHANGED
@@ -59,11 +59,11 @@ const FILE_VIEW = Symbol("agent-sanitizer:file-view");
59
59
  * Wrap a redactor's map-mode result in a frozen, branded view tagged with the
60
60
  * space its offsets are in.
61
61
  *
62
- * The redactor's own object is never touched. It used to be: the caller did
63
- * `view.pairs = pairsToUtf16(view.text, view.pairs)`, an in-place mutation of a
62
+ * The redactor's own object is never touched. A caller doing
63
+ * `view.pairs = pairsToUtf16(view.text, view.pairs)` would mutate in place a
64
64
  * value returned from an INJECTED seam. A redactor that memoizes its map result
65
65
  * (a reasonable thing for a caller to build) hands back the same object on the
66
- * second identical call, which then got converted a SECOND time — every
66
+ * second identical call, which would then get converted a SECOND time — every
67
67
  * placeholder preceded by an astral character shifts again and the same input
68
68
  * yields a different verdict.
69
69
  *
@@ -2,13 +2,13 @@
2
2
  * The path prefix every alert artifact of ONE session under this project shares.
3
3
  *
4
4
  * Session-keying is what makes the gate's one-time ask correct by construction.
5
- * The store and its ack used to be keyed by PROJECT alone and reset by a
6
- * destructive clear at SessionStart, which left two ways for a session to
7
- * inherit the previous one's answer: an early-exiting scanner arm (a dep-load
8
- * failure) returns before the clear, and nothing pins SessionStart against the
9
- * InstructionsLoaded events fired for the files loaded at launch. A session that
10
- * cannot see another session's files needs neither the clear nor the ordering —
11
- * past sessions' artifacts simply age out through {@link sweepStaleSessions}.
5
+ * Keying by PROJECT alone, reset by a destructive clear at SessionStart, would
6
+ * leave two ways for a session to inherit the previous one's answer: an
7
+ * early-exiting scanner arm (a dep-load failure) returns before the clear, and
8
+ * nothing pins SessionStart against the InstructionsLoaded events fired for
9
+ * the files loaded at launch. A session that cannot see another session's
10
+ * files needs neither the clear nor the ordering — past sessions' artifacts
11
+ * simply age out through {@link sweepStaleSessions}.
12
12
  * @param {string} [sessionId] the harness's session identity
13
13
  * @returns {string}
14
14
  */
@@ -134,11 +134,11 @@ export function invisibleCharAlert(sessionId?: string): string | null;
134
134
  * Add `text` to the alert the PreToolUse gate surfaces this session, keeping
135
135
  * whatever is already there.
136
136
  *
137
- * One O_EXCL-created, randomly-named file per finding. The store used to be a
138
- * single file appended through a read-modify-write, so two hooks recording a
139
- * finding at once silently dropped one of them; a fresh file per finding has no
140
- * shared cell to lose. Symlink-refusing (writeFileNoFollow) because the store
141
- * sits at a predictable, world-visible $TMPDIR path.
137
+ * One O_EXCL-created, randomly-named file per finding. A single file appended
138
+ * through a read-modify-write would let two hooks recording a finding at once
139
+ * silently drop one of them; a fresh file per finding has no shared cell to
140
+ * lose. Symlink-refusing (writeFileNoFollow) because the store sits at a
141
+ * predictable, world-visible $TMPDIR path.
142
142
  * @param {string} text
143
143
  * @param {string} [sessionId]
144
144
  * @returns {boolean} whether the finding was recorded
@@ -163,7 +163,7 @@ export function sanitizerDepsLoaded(): boolean;
163
163
  * otherwise invisible because every later tool call then fails closed with no
164
164
  * stated cause — the recorded loader error and its remedy ride along. The text
165
165
  * comes from missingPackageMessage so this hook, the PreToolUse gate and the
166
- * prompt gate cannot drift apart on what a missing dependency reads like.
166
+ * prompt gate read the same words for what a missing dependency looks like.
167
167
  * @param {() => boolean} [depsLoaded] injectable seam for testing
168
168
  * @param {string} [remedy] what a reader should run; hosts pass their own
169
169
  * @returns {string}
@@ -51,7 +51,7 @@ export function hasLongRun(text: string): boolean;
51
51
  * payload-length invisible run, and a pointer to recover the bytes — a hex dump
52
52
  * is ASCII, so it passes through sanitization untouched. The single source of
53
53
  * this note, shared by the `sanitize` convenience entry and the tool-output
54
- * pipeline so the two can't drift.
54
+ * pipeline.
55
55
  * @param {string[]} invisFound CATEGORY codes applyLayer1 reported removing
56
56
  * @param {string} deAnsi ANSI-stripped text (invisible runs intact), for the LONG_RUN probe
57
57
  * @returns {string}
@@ -19,11 +19,11 @@
19
19
  * Wrap a redactor's map-mode result in a frozen, branded view tagged with the
20
20
  * space its offsets are in.
21
21
  *
22
- * The redactor's own object is never touched. It used to be: the caller did
23
- * `view.pairs = pairsToUtf16(view.text, view.pairs)`, an in-place mutation of a
22
+ * The redactor's own object is never touched. A caller doing
23
+ * `view.pairs = pairsToUtf16(view.text, view.pairs)` would mutate in place a
24
24
  * value returned from an INJECTED seam. A redactor that memoizes its map result
25
25
  * (a reasonable thing for a caller to build) hands back the same object on the
26
- * second identical call, which then got converted a SECOND time — every
26
+ * second identical call, which would then get converted a SECOND time — every
27
27
  * placeholder preceded by an astral character shifts again and the same input
28
28
  * yields a different verdict.
29
29
  *