@hasna/hooks 0.12.4 → 0.12.6

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.
package/README.md CHANGED
@@ -297,6 +297,13 @@ hooks safety install trash-guard --target sumi --expected-binding-sha256 CURRENT
297
297
  hooks safety verify --target sumi --execution
298
298
  ```
299
299
 
300
+ Hooks registered as `hooks run <hook>` do not go through the native worker, so
301
+ re-registration does not cover them. When a release changes the script of such
302
+ a hook, run `hooks trust <hook>` with the new CLI on every station after
303
+ switching PATH to it, as "Trust model" under "Custom and remote hooks"
304
+ describes. Until then, wherever an old pin exists, it refuses the new script
305
+ and that hook exits 1 on every call.
306
+
300
307
  `hooks safety provision --target sumi`, which the package's lifecycle script
301
308
  also runs, keeps a binding that still verifies, so it does not move Sumi to a
302
309
  worker installed in a different tree; the explicit install above does. That
@@ -365,13 +372,19 @@ Codex is installed through npm, pass the platform package's native binary rather
365
372
  than its JavaScript launcher. Executable ownership, permissions, ancestry and
366
373
  bytes are checked. Supported protocol versions are 0.153.0, 0.154.0,
367
374
  0.154.0-alpha.6.1, 0.155.0, 0.155.1, 0.156.1, 0.157.0, 0.157.1, 0.158.0, 0.159.0, 0.159.2,
368
- 0.159.3 and 0.160.0;
375
+ 0.159.3, 0.160.0 and 0.160.1;
369
376
  other versions refuse pending compatibility validation. Updating Codex can
370
377
  therefore require a compatible Hooks release before native safety verification
371
378
  and trust provisioning succeed. Keep existing hook definitions and trust intact
372
379
  when this check reports `native_unsupported`.
373
380
  The version probe has a five-second forced timeout and native discovery a
374
381
  fifteen-second lifetime budget. Neither step restarts an existing agent.
382
+ Both run the native with an explicit environment allowlist: `PATH`, `USER`,
383
+ `LOGNAME`, `LANG`, `LC_*`, `TMPDIR`, the XDG base directories and Codex's own
384
+ `CODEX_*` variables, with `HOME`, `NO_COLOR` and `CODEX_HOME` set by Hooks.
385
+ Dynamic-loader (`LD_*`, `DYLD_*`) and runtime-hook (`NODE_*`, `BUN_*`,
386
+ `BASH_ENV`, `ENV`) variables never reach it, because only the executable's
387
+ bytes are verified.
375
388
 
376
389
  Success reports `nativeDiscoveryVerified: true`, `guardVerified: true` and
377
390
  `nativeAdoptionVerified: false`. It does not enroll trust, change configuration,
@@ -449,13 +462,15 @@ hooks install https://example.com/hooks/my-hook/manifest.json
449
462
 
450
463
  Custom hooks land in `~/.hasna/hooks/hooks/<name>/`. A custom hook with the same name as a bundled hook takes precedence (visible in `hooks info <name>`).
451
464
 
452
- **Trust model.** Every hook script is pinned by sha256 in `~/.hasna/hooks/hooks.lock` and the SQLite `hooks` table. `hooks run` verifies the script hash before executing; if the script changed, the run is refused:
465
+ **Trust model.** Every hook script is pinned by sha256 in `hooks.lock` in the hooks data directory (`~/.hasna/hooks/hooks.lock` unless the data directory resolves elsewhere; `HASNA_HOOKS_LOCK_PATH`, or its alias `HOOKS_LOCK_PATH`, overrides the lock path) and, in local mode, in the SQLite `hooks` table, which is checked first. `hooks run` verifies the script hash before executing; if the script changed, the run is refused and exits 1:
453
466
 
454
467
  ```bash
455
468
  hooks trust <name> # re-pin the current script content
456
469
  hooks update # re-register hooks and refresh pins
457
470
  ```
458
471
 
472
+ A hook's first run writes its pin, and so do `hooks sync` (in local mode it pins every bundled hook without running any of them), `hooks update`, `hooks install <name>@<version>`, `hooks update <name>@<version>` and `hooks trust`. A station can therefore hold a pin for a hook that has never run there. After any upgrade that changes the script of a hook registered as `hooks run <hook>`, run `hooks trust <hook>` with the new CLI on every station. Run it as the same user and with the same hooks environment that the harness's `hooks run` sees: the local opt-in or registry credential, and any data directory, DB or lock path override. Otherwise it can write a pin that `hooks run` does not read. Where the hook is not pinned yet, it pins the same sha256 that the first run would have pinned, so it is harmless there.
473
+
459
474
  **Registry server.** `hooks serve` exposes the local store over HTTP — catalog, artifacts, and the published lock:
460
475
 
461
476
  ```bash
package/bin/hooks-mcp.js CHANGED
@@ -347,8 +347,8 @@ var init_registry = __esm(() => {
347
347
  {
348
348
  name: "signed-link-output",
349
349
  displayName: "Signed Link Output",
350
- description: "Claude PostToolUse backstop: replaces signed-link URLs in tool output with a redaction marker (updatedToolOutput, where the running Claude Code supports it) and tells the model not to repeat or store the link. It runs after the tool, so it cannot undo display or other persistence",
351
- version: "0.1.0",
350
+ description: "Claude PostToolUse backstop: replaces capability links in tool output \u2014 signature-class query or fragment parameters, and anchored path-borne provider classes such as the Stripe Connect onboarding link \u2014 with a redaction marker (updatedToolOutput, where the running Claude Code supports it) and tells the model not to repeat or store the link. Every string is walked, so nested metadata such as a browser result's `_meta.browser_use.url` is covered. It runs after the tool, so it cannot undo display or other persistence",
351
+ version: "0.1.1",
352
352
  category: "Security",
353
353
  event: "PostToolUse",
354
354
  matcher: "^(Bash|WebFetch|mcp__.*)$",
package/bin/index.js CHANGED
@@ -378,8 +378,8 @@ var init_registry = __esm(() => {
378
378
  {
379
379
  name: "signed-link-output",
380
380
  displayName: "Signed Link Output",
381
- description: "Claude PostToolUse backstop: replaces signed-link URLs in tool output with a redaction marker (updatedToolOutput, where the running Claude Code supports it) and tells the model not to repeat or store the link. It runs after the tool, so it cannot undo display or other persistence",
382
- version: "0.1.0",
381
+ description: "Claude PostToolUse backstop: replaces capability links in tool output \u2014 signature-class query or fragment parameters, and anchored path-borne provider classes such as the Stripe Connect onboarding link \u2014 with a redaction marker (updatedToolOutput, where the running Claude Code supports it) and tells the model not to repeat or store the link. Every string is walked, so nested metadata such as a browser result's `_meta.browser_use.url` is covered. It runs after the tool, so it cannot undo display or other persistence",
382
+ version: "0.1.1",
383
383
  category: "Security",
384
384
  event: "PostToolUse",
385
385
  matcher: "^(Bash|WebFetch|mcp__.*)$",
@@ -36319,6 +36319,51 @@ var init_native_safety_registration = __esm(() => {
36319
36319
  };
36320
36320
  });
36321
36321
 
36322
+ // src/lib/native-child-env.ts
36323
+ function isRefusedNativeChildEnvName(name) {
36324
+ return REFUSED.has(name) || REFUSED_PREFIXES.some((prefix3) => name.startsWith(prefix3));
36325
+ }
36326
+ function codexInherited(name) {
36327
+ return name.startsWith("CODEX_") && name !== "CODEX_HOME" && name !== "CODEX_APPLY_GIT_CFG" && !name.startsWith("CODEX_NETWORK_PROXY_SNAPSHOT_");
36328
+ }
36329
+ function nativeChildEnv(source, explicit = {}, inherit = () => false) {
36330
+ const env = {};
36331
+ for (const [name, value] of Object.entries(source)) {
36332
+ if (typeof value !== "string" || isRefusedNativeChildEnvName(name))
36333
+ continue;
36334
+ if (INHERITED.has(name) || /^LC_[A-Z]+$/.test(name) || inherit(name))
36335
+ env[name] = value;
36336
+ }
36337
+ for (const [name, value] of Object.entries(explicit)) {
36338
+ if (isRefusedNativeChildEnvName(name))
36339
+ throw new Error(`A native child environment cannot set ${name}.`);
36340
+ if (value === undefined)
36341
+ delete env[name];
36342
+ else
36343
+ env[name] = value;
36344
+ }
36345
+ return env;
36346
+ }
36347
+ var INHERITED, REFUSED_PREFIXES, REFUSED;
36348
+ var init_native_child_env = __esm(() => {
36349
+ INHERITED = new Set([
36350
+ "PATH",
36351
+ "USER",
36352
+ "LOGNAME",
36353
+ "LANG",
36354
+ "TMPDIR",
36355
+ "XDG_CONFIG_HOME",
36356
+ "XDG_CONFIG_DIRS",
36357
+ "XDG_DATA_HOME",
36358
+ "XDG_DATA_DIRS",
36359
+ "XDG_CACHE_HOME",
36360
+ "XDG_STATE_HOME",
36361
+ "XDG_RUNTIME_DIR"
36362
+ ]);
36363
+ REFUSED_PREFIXES = ["LD_", "DYLD_", "NODE_", "BUN_", "BASH_FUNC_"];
36364
+ REFUSED = new Set(["BASH_ENV", "ENV", "GLIBC_TUNABLES", "GCONV_PATH", "LOCPATH"]);
36365
+ });
36366
+
36322
36367
  // src/lib/codex-safety-check.ts
36323
36368
  import { spawn as spawn2, execFile as execFile2 } from "child_process";
36324
36369
  import { createHash as createHash23 } from "crypto";
@@ -36373,13 +36418,7 @@ function executable(command) {
36373
36418
  }
36374
36419
  async function connectCodexSafety(options) {
36375
36420
  const command = options.command ?? "codex", before = executable(command);
36376
- const env = { ...process.env, HOME: options.home, NO_COLOR: "1" };
36377
- for (const key of ["NODE_OPTIONS", "NODE_PATH", "BUN_OPTIONS", "BASH_ENV", "ENV", "DYLD_INSERT_LIBRARIES", "LD_PRELOAD"])
36378
- delete env[key];
36379
- if (options.codexHome === undefined)
36380
- delete env.CODEX_HOME;
36381
- else
36382
- env.CODEX_HOME = options.codexHome;
36421
+ const env = nativeChildEnv(process.env, { HOME: options.home, NO_COLOR: "1", CODEX_HOME: options.codexHome }, codexInherited);
36383
36422
  let version2;
36384
36423
  try {
36385
36424
  version2 = (await promisify(execFile2)(before.path, ["--version"], { env, cwd: options.home, timeout: 5000, killSignal: "SIGKILL", maxBuffer: 4096 })).stdout.trim();
@@ -36596,9 +36635,10 @@ var SUPPORTED_CODEX_SAFETY_VERSIONS, versions, matcher = "^(Bash|apply_patch|App
36596
36635
  var init_codex_safety_check = __esm(() => {
36597
36636
  init_native_safety();
36598
36637
  init_native_readiness_command();
36638
+ init_native_child_env();
36599
36639
  init_native_safety2();
36600
36640
  init_native_readiness();
36601
- SUPPORTED_CODEX_SAFETY_VERSIONS = ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0"];
36641
+ SUPPORTED_CODEX_SAFETY_VERSIONS = ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0", "codex-cli 0.160.1"];
36602
36642
  versions = new Set(SUPPORTED_CODEX_SAFETY_VERSIONS);
36603
36643
  CodexSafetyError = class CodexSafetyError extends Error {
36604
36644
  code;
@@ -17,4 +17,4 @@ var{defineProperty:fZ,getOwnPropertyNames:t0,getOwnPropertyDescriptor:e0}=Object
17
17
  `).replace(/%s/g,()=>G[K++]?.value??"")+(K<G.length?" "+G.slice(K).map((H)=>H.value).join(" "):"")}if(z==="cat"){let Y=Z.indexOf("<<");if(Y<0)return null;let G=JZ(Z,Y),K=Z.indexOf(`
18
18
  `,Y);if(!G||K<0)return null;let H=LZ(Z,K,[G]);if(H<0)return null;let B=Z.slice(K+1,H);return B.slice(0,B.lastIndexOf(G.delimiter)).replace(/\n$/,"")}return null}function rZ(Z,J,$){for(let X of tZ(Z).bodies){let z=Z0(X);if(z===null)continue;let Q=m(z,J+1,$.debug);if(Q.refused)return Q}return q}function m(Z,J=0,$=!1){if(typeof Z!=="string"||!Z.trim())return q;if(J>r3)return EZ.test(Z)?F("unclassifiable"):q;let{segments:X,trustworthy:z}=K0(Z);if(!z)return EZ.test(Z)?F("unclassifiable"):q;let Q=$,Y=(G)=>m(G,J+1,Q);for(let G of e3(Z)){if(G.runsBody){let K=Y(G.body);if(K.refused)return K}if(!G.quoted){let K=tZ(G.body,"heredoc");if(!K.complete&&EZ.test(G.body))return F("unclassifiable");for(let H of K.bodies){let B=Y(H);if(B.refused)return B}}}for(let G=0;G<X.length;G++){let K=X[G];for(let L of K.words){let v=tZ(L.text);if(!v.complete&&EZ.test(L.text))return F("unclassifiable");for(let k of v.bodies){let w=Y(k);if(w.refused)return w}}let H=l(K),B=K.words.map((L,v)=>({word:XZ(L.text),redirect:K.redirects.has(v)})),U=B.slice(0,H<0?B.length:H).map((L)=>L.word),V=H>=0?o(B[H].word.value):"";if(H<0||["export","declare","typeset","readonly","local"].includes(V)){if(Q=m0([...U,...B.slice(H+1).map((L)=>L.word)],Q),H<0)continue}let C=m0(U,Q),_=B.slice(H+1).filter((L)=>!L.redirect).map((L)=>L.word),O=B.slice(H+1).filter((L)=>L.redirect).map((L)=>L.word),M=B[H].word,j=o(M.value),c={depth:J,appendsArgs:!1,debug:C};if(H>0&&B[H-1].word.value==="function"){let L=_.filter((k)=>!["{","()","(",")"].includes(k.value)),v=$0(L,c);if(v.refused)return v;continue}if(G>0&&d0(K.sepBefore)&&eZ(j,_)){let L=X[G-1],v=o3(Z,L),k=v===null?null:Z0(v);if(k!==null){let w=m(k,J+1,C);if(w.refused)return w}}let p=X[G+1];if(p&&/<\(\s*$/.test(p.sepBefore)&&(yZ.has(j)||j==="source"||j===".")){let L=p.words[0].start-p.sepBefore.length+p.sepBefore.lastIndexOf("("),v=qZ(Z,L),k=v<0?null:Z0(Z.slice(L+1,v-1));if(k!==null){let w=m(k,J+1,C);if(w.refused)return w}}let a=i0(j,M,_,O,K.words.slice(0,H+1),c);if(a.refused)return a}return q}function o3(Z,J){let $=J.words[0],X=J.words[J.words.length-1];return $&&X?Z.slice($.start,X.end):null}function t3(Z){let J=o(Z.value);return/[$`]/.test(J)||J===""?void 0:J}function i0(Z,J,$,X,z,Q){let Y=Q.depth,G=(K)=>m(K,Y+1,Q.debug);if(J.opaque){let K=t3(J);if(K===void 0){let H=$.find((U)=>!U.value.startsWith("-")),B=RZ($,Q);if(!B.refused)return q;return B.rule!=="unclassifiable"||H!==void 0&&!H.opaque&&A3.has(H.value)?B:q}Z=K}if(Z==="gh")return RZ($,Q);if(yZ.has(Z)){let K=Q0($);if(K){let H=G(K.value);if(H.refused||!K.opaque)return H;return rZ(K.raw,Y,Q)}for(let H of X){let B=G(H.value);if(B.refused)return B;if(H.opaque){let U=rZ(H.raw,Y,Q);if(U.refused)return U}}return q}if(p3.has(Z)){let K=$.findIndex((B)=>B.value==="-c"||B.value==="--command"||/^-[A-Za-z]*c$/.test(B.value)),H=K>=0?$[K+1]:void 0;return H?G(H.value):oZ($,Q)}if(Z==="eval"||Z==="watch"){let K=$;if(Z==="watch"){let B=0;while(B<$.length&&$[B].value.startsWith("-")){if($[B].value==="--"){B++;break}if(["-n","--interval","-q","--equexit"].includes($[B].value))B++;B++}K=$.slice(B)}let H=G(K.map((B)=>B.value).join(" "));if(H.refused)return H;for(let B of K){let U=rZ(B.raw,Y,Q);if(U.refused)return U}return q}if(Z==="env")return G(FZ([...z.map((K)=>XZ(K.text).value),...$.map((K)=>K.value)]));if(Z==="ssh"){let K=0;for(;K<$.length;K++){let U=$[K].value;if(!U.startsWith("-"))break;if(a3.has(U))K++}let H=$.slice(K+1);if(H[0]?.value==="--")H.shift();let B=H.map((U)=>U.value).join(" ");return B?G(B):q}if(Z==="xargs"){let K=0,H=!1;for(;K<$.length;K++){let B=$[K].value;if(B==="--"){K++;break}if(!B.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(B))H=!0;if(s3.has(B))K++}return $0($.slice(K),{depth:Y,appendsArgs:!H,debug:Q.debug})}if(Z==="find"){for(let K=0;K<$.length;K++){if(!["-exec","-execdir","-ok","-okdir"].includes($[K].value))continue;let H=K+1;while(H<$.length&&$[H].value!==";"&&$[H].value!=="+")H++;let B=$0($.slice(K+1,H),Q);if(B.refused)return B;K=H}return q}if(d3.has(Z))return oZ($,Q);if(i3.get(Z)?.includes($[0]?.value??""))return oZ($.slice(1),Q);return q}function $0(Z,J){if(Z.length===0)return q;let $=o(Z[0].value);if($==="gh")return RZ(Z.slice(1),J);if(yZ.has($)){let X=Q0(Z.slice(1));return X?m(X.value,J.depth+1,J.debug):q}return i0($,Z[0],Z.slice(1),[],[],J)}function oZ(Z,J){let $=Z.findIndex((X)=>!X.opaque&&o(X.value)==="gh"&&(X.value==="gh"||X.value.includes("/")));return $>=0?RZ(Z.slice($+1),J):q}function Q0(Z){for(let J=0;J<Z.length;J++){let $=Z[J].value;if($==="--")return;if(!$.startsWith("-")&&!$.startsWith("+"))return;if($==="-c"||/^-[A-Za-z]+$/.test($)&&$.includes("c"))return Z.slice(J+1).find((X)=>!X.value.startsWith("-")||X.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test($))J++}return}function e3(Z){let J=[],$=0;for(;;){let X=Z.indexOf("<<",$);if(X<0)break;if($=X+2,Z[X+2]==="<"||X>0&&Z[X-1]==="<"){$=X+3;continue}let z=JZ(Z,X);if(!z)continue;let Q=Z.lastIndexOf(`
19
19
  `,X)+1,Y=Z.indexOf(`
20
- `,X);if(Y<0)continue;let G=LZ(Z,Y,[z]),K=G<0?Z.slice(Y+1):Z.slice(Y+1,G),H=G<0?K:K.slice(0,Math.max(0,K.lastIndexOf(z.delimiter))).replace(/\n$/,""),B=Z.slice(Q,X)+" HEREDOC_OPERATOR "+Z.slice(z.end,Y);J.push({body:H,runsBody:Z4(B),quoted:z.quoted})}return J}function Z4(Z){let{segments:J}=K0(Z),$=J.findIndex((G)=>G.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let X=(G)=>{let K=l(G);if(K<0)return{verb:"",args:[]};let H=G.words.slice(K+1).filter((B)=>B.text!=="HEREDOC_OPERATOR").map((B)=>XZ(B.text));return{verb:o(XZ(G.words[K].text).value),args:H}},{verb:z,args:Q}=X(J[$]);if(z==="ssh"||eZ(z,Q))return!0;if((z==="source"||z===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(Q[0]?.value??""))return!0;let Y=J[$+1];if(z==="cat"&&Y&&d0(Y.sepBefore)){let G=X(Y);return G.verb==="ssh"||eZ(G.verb,G.args)}return!1}var $4=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function s0(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:J0}}}var J4=new Set(["Bash","Monitor"]);function a0(Z){if(Z?.hook_event_name!=="PreToolUse"||!J4.has(Z.tool_name??""))return{continue:!0};let J=$Z(Z);if(!J.trim())return{continue:!0};try{return m(J).refused?s0():{continue:!0}}catch{return $4.test(J)?s0():{continue:!0}}}function X4(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function n0(Z,J){X4(Z);let $=Z,X=JSON.parse(J);if(!X||Array.isArray(X)||X.hook_event_name!=="PreToolUse"||typeof X.tool_name!=="string"||!X.tool_input||typeof X.tool_input!=="object"||Array.isArray(X.tool_input)||typeof X.cwd!=="string"||!Y0.isAbsolute(X.cwd))throw Error("Invalid safety input");if(X.tool_name==="Bash"&&typeof X.tool_input.command!=="string")throw Error("Invalid shell input");if(X.tool_name==="Monitor"&&X.tool_input.command!==void 0&&typeof X.tool_input.command!=="string")throw Error("Invalid monitor input");let z=X.hasna_execution;if(z!==void 0&&(!z||Object.keys(z).sort().join()!=="agent,schema"||z.schema!=="hasna.hooks.execution.v1"||typeof z.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(z.agent)))throw Error("Invalid execution capability");let Q=z===void 0?void 0:{runtime:process.execPath,home:SZ.homedir(),path:process.env.PATH,agent:z.agent};if(Q&&(!Y0.isAbsolute(Q.runtime)||!Q.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(X.tool_name)){if(X.tool_input.command!==void 0&&X.tool_input.patch!==void 0&&X.tool_input.command!==X.tool_input.patch)throw Error("Conflicting patch aliases");let O=X.tool_input.command??X.tool_input.patch;if(typeof O!=="string")throw Error("Invalid patch input");X.tool_input={...X.tool_input,command:O,patch:O}}let Y=X.tool_name==="Monitor",G=X.tool_name==="Bash"||Y&&typeof X.tool_input.command==="string",K=Y&&G?{...X,tool_name:"Bash"}:X,H=(O)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:O}}),B=y0(K).output,U=a0(K),V=G&&NZ(K.tool_input.command,{home:SZ.homedir(),cwd:X.cwd}).handoffHits.length>0,C=$==="trash-guard"&&(!Y||G)?I0(K,{home:SZ.homedir(),cwd:X.cwd,findTrash:DZ,inspectTrash:BZ,execution:Q}):{continue:!0};if(Y&&C.hookSpecificOutput?.permissionDecision==="allow")C=H("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let _=B.decision==="block"?H(B.reason):U.hookSpecificOutput?U:V?H("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):C;return JSON.stringify({verdict:"continue"in _?null:_})}var z4=2,K4="0.12.4";function Q4(Z,J){return n0(Z,J)}
20
+ `,X);if(Y<0)continue;let G=LZ(Z,Y,[z]),K=G<0?Z.slice(Y+1):Z.slice(Y+1,G),H=G<0?K:K.slice(0,Math.max(0,K.lastIndexOf(z.delimiter))).replace(/\n$/,""),B=Z.slice(Q,X)+" HEREDOC_OPERATOR "+Z.slice(z.end,Y);J.push({body:H,runsBody:Z4(B),quoted:z.quoted})}return J}function Z4(Z){let{segments:J}=K0(Z),$=J.findIndex((G)=>G.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let X=(G)=>{let K=l(G);if(K<0)return{verb:"",args:[]};let H=G.words.slice(K+1).filter((B)=>B.text!=="HEREDOC_OPERATOR").map((B)=>XZ(B.text));return{verb:o(XZ(G.words[K].text).value),args:H}},{verb:z,args:Q}=X(J[$]);if(z==="ssh"||eZ(z,Q))return!0;if((z==="source"||z===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(Q[0]?.value??""))return!0;let Y=J[$+1];if(z==="cat"&&Y&&d0(Y.sepBefore)){let G=X(Y);return G.verb==="ssh"||eZ(G.verb,G.args)}return!1}var $4=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function s0(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:J0}}}var J4=new Set(["Bash","Monitor"]);function a0(Z){if(Z?.hook_event_name!=="PreToolUse"||!J4.has(Z.tool_name??""))return{continue:!0};let J=$Z(Z);if(!J.trim())return{continue:!0};try{return m(J).refused?s0():{continue:!0}}catch{return $4.test(J)?s0():{continue:!0}}}function X4(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function n0(Z,J){X4(Z);let $=Z,X=JSON.parse(J);if(!X||Array.isArray(X)||X.hook_event_name!=="PreToolUse"||typeof X.tool_name!=="string"||!X.tool_input||typeof X.tool_input!=="object"||Array.isArray(X.tool_input)||typeof X.cwd!=="string"||!Y0.isAbsolute(X.cwd))throw Error("Invalid safety input");if(X.tool_name==="Bash"&&typeof X.tool_input.command!=="string")throw Error("Invalid shell input");if(X.tool_name==="Monitor"&&X.tool_input.command!==void 0&&typeof X.tool_input.command!=="string")throw Error("Invalid monitor input");let z=X.hasna_execution;if(z!==void 0&&(!z||Object.keys(z).sort().join()!=="agent,schema"||z.schema!=="hasna.hooks.execution.v1"||typeof z.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(z.agent)))throw Error("Invalid execution capability");let Q=z===void 0?void 0:{runtime:process.execPath,home:SZ.homedir(),path:process.env.PATH,agent:z.agent};if(Q&&(!Y0.isAbsolute(Q.runtime)||!Q.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(X.tool_name)){if(X.tool_input.command!==void 0&&X.tool_input.patch!==void 0&&X.tool_input.command!==X.tool_input.patch)throw Error("Conflicting patch aliases");let O=X.tool_input.command??X.tool_input.patch;if(typeof O!=="string")throw Error("Invalid patch input");X.tool_input={...X.tool_input,command:O,patch:O}}let Y=X.tool_name==="Monitor",G=X.tool_name==="Bash"||Y&&typeof X.tool_input.command==="string",K=Y&&G?{...X,tool_name:"Bash"}:X,H=(O)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:O}}),B=y0(K).output,U=a0(K),V=G&&NZ(K.tool_input.command,{home:SZ.homedir(),cwd:X.cwd}).handoffHits.length>0,C=$==="trash-guard"&&(!Y||G)?I0(K,{home:SZ.homedir(),cwd:X.cwd,findTrash:DZ,inspectTrash:BZ,execution:Q}):{continue:!0};if(Y&&C.hookSpecificOutput?.permissionDecision==="allow")C=H("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let _=B.decision==="block"?H(B.reason):U.hookSpecificOutput?U:V?H("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):C;return JSON.stringify({verdict:"continue"in _?null:_})}var z4=2,K4="0.12.6";function Q4(Z,J){return n0(Z,J)}
package/bin/serve.js CHANGED
@@ -314,8 +314,8 @@ var HOOKS = [
314
314
  {
315
315
  name: "signed-link-output",
316
316
  displayName: "Signed Link Output",
317
- description: "Claude PostToolUse backstop: replaces signed-link URLs in tool output with a redaction marker (updatedToolOutput, where the running Claude Code supports it) and tells the model not to repeat or store the link. It runs after the tool, so it cannot undo display or other persistence",
318
- version: "0.1.0",
317
+ description: "Claude PostToolUse backstop: replaces capability links in tool output \u2014 signature-class query or fragment parameters, and anchored path-borne provider classes such as the Stripe Connect onboarding link \u2014 with a redaction marker (updatedToolOutput, where the running Claude Code supports it) and tells the model not to repeat or store the link. Every string is walked, so nested metadata such as a browser result's `_meta.browser_use.url` is covered. It runs after the tool, so it cannot undo display or other persistence",
318
+ version: "0.1.1",
319
319
  category: "Security",
320
320
  event: "PostToolUse",
321
321
  matcher: "^(Bash|WebFetch|mcp__.*)$",
package/dist/index.js CHANGED
@@ -7177,8 +7177,8 @@ var HOOKS = [
7177
7177
  {
7178
7178
  name: "signed-link-output",
7179
7179
  displayName: "Signed Link Output",
7180
- description: "Claude PostToolUse backstop: replaces signed-link URLs in tool output with a redaction marker (updatedToolOutput, where the running Claude Code supports it) and tells the model not to repeat or store the link. It runs after the tool, so it cannot undo display or other persistence",
7181
- version: "0.1.0",
7180
+ description: "Claude PostToolUse backstop: replaces capability links in tool output \u2014 signature-class query or fragment parameters, and anchored path-borne provider classes such as the Stripe Connect onboarding link \u2014 with a redaction marker (updatedToolOutput, where the running Claude Code supports it) and tells the model not to repeat or store the link. Every string is walked, so nested metadata such as a browser result's `_meta.browser_use.url` is covered. It runs after the tool, so it cannot undo display or other persistence",
7181
+ version: "0.1.1",
7182
7182
  category: "Security",
7183
7183
  event: "PostToolUse",
7184
7184
  matcher: "^(Bash|WebFetch|mcp__.*)$",
@@ -42479,6 +42479,48 @@ import { constants as constants12, openSync as openSync15, closeSync as closeSyn
42479
42479
  import { dirname as dirname21, isAbsolute as isAbsolute17, resolve as resolve19 } from "path";
42480
42480
  import { promisify } from "util";
42481
42481
 
42482
+ // src/lib/native-child-env.ts
42483
+ var INHERITED = new Set([
42484
+ "PATH",
42485
+ "USER",
42486
+ "LOGNAME",
42487
+ "LANG",
42488
+ "TMPDIR",
42489
+ "XDG_CONFIG_HOME",
42490
+ "XDG_CONFIG_DIRS",
42491
+ "XDG_DATA_HOME",
42492
+ "XDG_DATA_DIRS",
42493
+ "XDG_CACHE_HOME",
42494
+ "XDG_STATE_HOME",
42495
+ "XDG_RUNTIME_DIR"
42496
+ ]);
42497
+ var REFUSED_PREFIXES = ["LD_", "DYLD_", "NODE_", "BUN_", "BASH_FUNC_"];
42498
+ var REFUSED = new Set(["BASH_ENV", "ENV", "GLIBC_TUNABLES", "GCONV_PATH", "LOCPATH"]);
42499
+ function isRefusedNativeChildEnvName(name) {
42500
+ return REFUSED.has(name) || REFUSED_PREFIXES.some((prefix3) => name.startsWith(prefix3));
42501
+ }
42502
+ function codexInherited(name) {
42503
+ return name.startsWith("CODEX_") && name !== "CODEX_HOME" && name !== "CODEX_APPLY_GIT_CFG" && !name.startsWith("CODEX_NETWORK_PROXY_SNAPSHOT_");
42504
+ }
42505
+ function nativeChildEnv(source, explicit = {}, inherit = () => false) {
42506
+ const env = {};
42507
+ for (const [name, value] of Object.entries(source)) {
42508
+ if (typeof value !== "string" || isRefusedNativeChildEnvName(name))
42509
+ continue;
42510
+ if (INHERITED.has(name) || /^LC_[A-Z]+$/.test(name) || inherit(name))
42511
+ env[name] = value;
42512
+ }
42513
+ for (const [name, value] of Object.entries(explicit)) {
42514
+ if (isRefusedNativeChildEnvName(name))
42515
+ throw new Error(`A native child environment cannot set ${name}.`);
42516
+ if (value === undefined)
42517
+ delete env[name];
42518
+ else
42519
+ env[name] = value;
42520
+ }
42521
+ return env;
42522
+ }
42523
+
42482
42524
  // src/native-safety.ts
42483
42525
  import { execFile } from "child_process";
42484
42526
  import { closeSync as closeSync13, constants as constants4, existsSync as existsSync15, fstatSync as fstatSync5, fsyncSync, linkSync as linkSync3, lstatSync as lstatSync10, mkdirSync as mkdirSync12, openSync as openSync13, readFileSync as readFileSync16, realpathSync as realpathSync11, renameSync as renameSync3, unlinkSync as unlinkSync5, writeFileSync as writeFileSync10 } from "fs";
@@ -42562,7 +42604,7 @@ async function verifyNativeSafetyCommand(command, home = homedir8()) {
42562
42604
  }
42563
42605
 
42564
42606
  // src/lib/codex-safety-check.ts
42565
- var SUPPORTED_CODEX_SAFETY_VERSIONS = ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0"];
42607
+ var SUPPORTED_CODEX_SAFETY_VERSIONS = ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0", "codex-cli 0.160.1"];
42566
42608
  var versions = new Set(SUPPORTED_CODEX_SAFETY_VERSIONS);
42567
42609
  var matcher = "^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$";
42568
42610
 
@@ -42622,13 +42664,7 @@ function executable(command) {
42622
42664
  }
42623
42665
  async function connectCodexSafety(options) {
42624
42666
  const command = options.command ?? "codex", before = executable(command);
42625
- const env = { ...process.env, HOME: options.home, NO_COLOR: "1" };
42626
- for (const key of ["NODE_OPTIONS", "NODE_PATH", "BUN_OPTIONS", "BASH_ENV", "ENV", "DYLD_INSERT_LIBRARIES", "LD_PRELOAD"])
42627
- delete env[key];
42628
- if (options.codexHome === undefined)
42629
- delete env.CODEX_HOME;
42630
- else
42631
- env.CODEX_HOME = options.codexHome;
42667
+ const env = nativeChildEnv(process.env, { HOME: options.home, NO_COLOR: "1", CODEX_HOME: options.codexHome }, codexInherited);
42632
42668
  let version2;
42633
42669
  try {
42634
42670
  version2 = (await promisify(execFile2)(before.path, ["--version"], { env, cwd: options.home, timeout: 5000, killSignal: "SIGKILL", maxBuffer: 4096 })).stdout.trim();
@@ -1,7 +1,7 @@
1
1
  import { verifyNativeSafetyCommand } from "../native-safety.js";
2
2
  /** Exact `codex --version` outputs whose app-server protocol was measured
3
3
  * against the real native binary. Anything else refuses as native_unsupported. */
4
- export declare const SUPPORTED_CODEX_SAFETY_VERSIONS: readonly ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0"];
4
+ export declare const SUPPORTED_CODEX_SAFETY_VERSIONS: readonly ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0", "codex-cli 0.160.1"];
5
5
  export type CodexSafetyCode = "native_unavailable" | "native_unsafe_executable" | "native_executable_required" | "native_unsupported" | "native_failed" | "native_discovery_failed" | "hooks_disabled" | "guard_missing" | "guard_ambiguous" | "guard_definition_invalid" | "guard_disabled" | "guard_untrusted" | "guard_changed" | "guard_failed";
6
6
  export declare class CodexSafetyError extends Error {
7
7
  readonly code: CodexSafetyCode;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Environment for a native executable that Hooks verifies and then runs, such
3
+ * as the Codex app-server used by `hooks safety verify|trust --target codex`.
4
+ *
5
+ * Hooks pins only the native's main executable bytes. Dynamic-loader and
6
+ * runtime-hook variables would load code that the pin never covered: a glibc
7
+ * build honours LD_AUDIT, LD_PRELOAD and LD_LIBRARY_PATH before main() runs,
8
+ * so the native's own pre-main scrubbing is too late. The child therefore gets
9
+ * an explicit allowlist, never the parent's environment minus a denylist.
10
+ *
11
+ * Inherited from the parent, by exact name unless noted:
12
+ * - PATH: the native resolves its helper executables through it.
13
+ * - USER, LOGNAME: the user identity some native paths read.
14
+ * - LANG and every LC_* name: locale selection only (LOCPATH and GCONV_PATH,
15
+ * which load locale and iconv modules from a directory, are refused).
16
+ * - TMPDIR: Codex derives the temporary writable roots in its permission
17
+ * profiles from it, so a different value changes what config/read reports.
18
+ * - The XDG base directories, so a native that resolves configuration, data,
19
+ * cache, state or its runtime directory (and the default session bus under
20
+ * XDG_RUNTIME_DIR) through them sees the same paths as the agent session.
21
+ * - Whatever a caller's `inherit` predicate admits (Codex: `codexInherited`).
22
+ *
23
+ * Not inherited, deliberately:
24
+ * - Proxy and TLS-trust settings outside the caller's namespace (HTTP_PROXY,
25
+ * HTTPS_PROXY, ALL_PROXY, NO_PROXY, SSL_CERT_FILE, SSL_CERT_DIR). The Codex
26
+ * app-server still reads local configuration and may make its plugin-sync
27
+ * network call; CODEX_* names, such as CODEX_CA_CERTIFICATE, are inherited.
28
+ * - Credentials outside the native's own namespace, logging and backtrace
29
+ * switches (RUST_LOG would grow stderr toward the child's byte budget),
30
+ * SHELL, TERM and DBUS_SESSION_BUS_ADDRESS (a D-Bus address may name an
31
+ * executable transport; XDG_RUNTIME_DIR still locates the default bus).
32
+ *
33
+ * Refused unconditionally, whether inherited or passed in `explicit`:
34
+ * every LD_* and DYLD_* name, every NODE_* and BUN_* name, BASH_ENV, ENV,
35
+ * BASH_FUNC_* exported functions, GLIBC_TUNABLES, GCONV_PATH and LOCPATH.
36
+ * An explicit refused name is a programming error and throws.
37
+ */
38
+ /** True for a name that must never reach a verified native child. */
39
+ export declare function isRefusedNativeChildEnvName(name: string): boolean;
40
+ /**
41
+ * Codex's own namespace is inherited so the app-server resolves the same
42
+ * configuration, state and auth home as the agent session (for example
43
+ * CODEX_SQLITE_HOME). CODEX_HOME is never inherited here: the caller sets or
44
+ * removes it explicitly. Two kinds of CODEX_* name are dropped because they
45
+ * make Codex run code it was not asked to run:
46
+ * - CODEX_NETWORK_PROXY_SNAPSHOT_*: Codex's carriers that restore BASH_ENV,
47
+ * ENV, ZDOTDIR and brokered variables inside its tool shells, which would
48
+ * re-import names this module refuses.
49
+ * - CODEX_APPLY_GIT_CFG: inline `git -c` settings, which can name commands.
50
+ */
51
+ export declare function codexInherited(name: string): boolean;
52
+ /**
53
+ * Build a native child's environment from `source` (normally process.env).
54
+ * `explicit` is applied last: a string sets the name, `undefined` removes it.
55
+ */
56
+ export declare function nativeChildEnv(source: Readonly<Record<string, string | undefined>>, explicit?: Readonly<Record<string, string | undefined>>, inherit?: (name: string) => boolean): Record<string, string>;
@@ -2,10 +2,12 @@
2
2
  * Signed-link shapes in text.
3
3
  *
4
4
  * The same shape the in-process harness redaction uses for this class: an
5
- * absolute http(s) URL whose query or fragment carries a capability-class
6
- * parameter. The measured signed action links carry `expires`, `pr_number`,
7
- * `repository`, `return_to` and `signature`; `signature` is the discriminating
8
- * parameter, and the other capability names below are the same class.
5
+ * absolute http(s) URL that carries a capability — a capability-class query or
6
+ * fragment parameter, or a capability carried in the path of a measured
7
+ * provider class. The measured signed action links carry `expires`,
8
+ * `pr_number`, `repository`, `return_to` and `signature`; `signature` is the
9
+ * discriminating parameter, and the other capability names below are the same
10
+ * class.
9
11
  *
10
12
  * A match is replaced by the URL's origin plus `/[redacted signed link]`, so a
11
13
  * reader keeps the host for diagnosis and nothing else. The matched text is
@@ -23,6 +25,31 @@ export const SIGNED_LINK_PARAMS: readonly string[] = [
23
25
  "token",
24
26
  ];
25
27
 
28
+ /**
29
+ * Anchored, provider-scoped path-borne capability classes.
30
+ *
31
+ * Some providers put the whole proof in the URL path, so a parameter scan
32
+ * reports their capability links clean (HP659: a Stripe Connect account
33
+ * onboarding link reached a transcript through browser tool-result metadata).
34
+ * Each entry names one measured provider class: the exact host plus the path
35
+ * shape that carries the token. A generic "long path" heuristic would flag
36
+ * ordinary links, so extend this table only with a class that was measured.
37
+ * Do not fetch a link to test it.
38
+ *
39
+ * This mirrors the scanner's table in @hasna/secrets (`signed-urls.ts`), so a
40
+ * link one Hasna component redacts is a link the other recognizes.
41
+ */
42
+ export const PATH_CAPABILITY_CLASSES: ReadonlyArray<{ hostname: string; path: RegExp }> = [
43
+ {
44
+ // Stripe Connect account-onboarding links: /setup/<letter>/<token> and the
45
+ // documented /setup/c/acct_<id>/<token> form. The onboarding token is the
46
+ // capability and the link is the account's entry point; nothing in the
47
+ // query marks it.
48
+ hostname: "connect.stripe.com",
49
+ path: /^\/setup\/[a-z]\/(?:acct_[A-Za-z0-9]+\/)?[^/?#]+\/?$/i,
50
+ },
51
+ ];
52
+
26
53
  /** Cheap pre-filter: any absolute URL. (A keyword pre-filter would miss percent- or entity-encoded names.) */
27
54
  const HINT = /https?:\/\//i;
28
55
 
@@ -75,13 +102,41 @@ export function hasSignatureParameter(url: string): boolean {
75
102
  return false;
76
103
  }
77
104
 
105
+ /**
106
+ * True when a URL's path carries a capability of an anchored, provider-scoped
107
+ * class (see `PATH_CAPABILITY_CLASSES`). The host and path shape are the whole
108
+ * rule: an ordinary URL, the bare provider origin, a host that merely ends with
109
+ * the provider name, and the same path shape on another host are all untouched.
110
+ * Separators are decoded first, exactly as the parameter check does, so a JSON
111
+ * `\u003f` (`?`) or `\u0026` (`&`) straight after the token cannot push the
112
+ * token out of the matched path segment.
113
+ */
114
+ export function hasPathBorneCapability(url: string): boolean {
115
+ let parsed: URL;
116
+ try { parsed = new URL(decodeSeparators(url)); } catch { return false; }
117
+ const hostname = parsed.hostname.replace(/\.$/, "").toLowerCase();
118
+ for (const klass of PATH_CAPABILITY_CLASSES) {
119
+ if (hostname === klass.hostname && klass.path.test(parsed.pathname)) return true;
120
+ }
121
+ return false;
122
+ }
123
+
124
+ /**
125
+ * True when a URL carries a capability: a signature-class query or fragment
126
+ * parameter, or an anchored path-borne class. The count and the redaction share
127
+ * this predicate, so the two cannot disagree.
128
+ */
129
+ export function carriesCapability(url: string): boolean {
130
+ return hasSignatureParameter(url) || hasPathBorneCapability(url);
131
+ }
132
+
78
133
  /** Number of signed-link URLs in `text`. */
79
134
  export function countSignedLinks(text: string): number {
80
135
  if (typeof text !== "string" || !text || !HINT.test(text)) return 0;
81
136
  let count = 0;
82
137
  for (const match of text.matchAll(URL_PATTERN)) {
83
138
  const url = match[0].replace(TRAILING_PUNCTUATION, "");
84
- if (hasSignatureParameter(url)) count++;
139
+ if (carriesCapability(url)) count++;
85
140
  }
86
141
  return count;
87
142
  }
@@ -92,7 +147,7 @@ export function redactSignedLinks(text: string): string {
92
147
  return text.replace(URL_PATTERN, (match) => {
93
148
  const trailing = match.match(TRAILING_PUNCTUATION)?.[0] ?? "";
94
149
  const url = trailing ? match.slice(0, -trailing.length) : match;
95
- if (!hasSignatureParameter(url)) return match;
150
+ if (!carriesCapability(url)) return match;
96
151
  const origin = url.match(/^https?:\/\/[^/?#]+/i)?.[0];
97
152
  return origin ? `${origin}/${REDACTION_MARKER}${trailing}` : `${REDACTION_MARKER}${trailing}`;
98
153
  });
@@ -4,13 +4,26 @@ Claude Code PostToolUse hook, installed as `hooks run signed-link-output`
4
4
  (matcher `Bash`, `WebFetch` and MCP tools). It is the backstop behind the
5
5
  `signed-link-guard` PreToolUse guard.
6
6
 
7
- When a tool result contains a signed-link URL — an absolute `http(s)` URL whose
8
- query or fragment carries `signature`, `sig`, `x-amz-signature`,
9
- `x-goog-signature`, `x-ms-signature`, `hmac` or `token` — it returns the two
10
- fields below. Separators are recognised in their encoded forms too: `&amp;`
11
- (also repeated, `&amp;amp;`), `&#38;`, `&#x26;`, the JSON escape `\u0026` and
12
- percent-encoded parameter names. A result with no such link gets no output at
13
- all, however large it is.
7
+ When a tool result contains a capability link it returns the two fields below.
8
+ Two shapes are recognised:
9
+
10
+ - an absolute `http(s)` URL whose query or fragment carries `signature`, `sig`,
11
+ `x-amz-signature`, `x-goog-signature`, `x-ms-signature`, `hmac` or `token`;
12
+ separators are recognised in their encoded forms too: `&amp;` (also repeated,
13
+ `&amp;amp;`), `&#38;`, `&#x26;`, the JSON escape `\u0026` and percent-encoded
14
+ parameter names.
15
+ - an absolute `http(s)` URL of an anchored, provider-scoped path-borne class:
16
+ the exact provider host plus the measured path shape that carries the token.
17
+ The measured class is the Stripe Connect account-onboarding link
18
+ (`connect.stripe.com/setup/<letter>/<token>`, including the documented
19
+ `connect.stripe.com/setup/c/acct_<id>/<token>` form), the shape that reached
20
+ a transcript through browser tool-result metadata in HP659. The table mirrors
21
+ the scanner's in `@hasna/secrets` (`signed-urls.ts`).
22
+
23
+ Every string of the tool result is walked, so a capability in nested metadata —
24
+ for example a browser tool result's `_meta.browser_use.url` — is redacted like
25
+ one in ordinary output text. A result with no such link gets no output at all,
26
+ however large it is.
14
27
 
15
28
  - `hookSpecificOutput.updatedToolOutput`: the same tool result with each such
16
29
  URL replaced by `<origin>/[redacted signed link]`. Keys, order and
@@ -23,10 +36,26 @@ It never blocks, and it never prints, logs or stores a matched URL.
23
36
 
24
37
  ## What it can and cannot do
25
38
 
26
- - Output replacement depends on the running Claude Code build. The 2.1.285
39
+ - Output replacement depends on the running harness. Claude Code's 2.1.285
27
40
  build accepts `updatedToolOutput` on PostToolUse for every tool, checks it
28
41
  against the tool's output schema, and uses the original output (with a hook
29
42
  error) when the check fails. Older builds may ignore or reject the field.
43
+ - Codex has no output rewrite: that is a native capability limit on Codex, not
44
+ a configuration toggle. Stock Codex 0.160.0, stable 0.160.1 and shipped Hoshi
45
+ 0.5.2 share the same relevant hook schema, parser, event and core consumers.
46
+ The rewrite field this hook emits, `updatedToolOutput`, is not in Codex's
47
+ PostToolUse output schema, so Codex rejects that response as unknown and the
48
+ hook fails open: the redaction does not apply and the notice sent with it is
49
+ dropped. Codex's own rewrite field, `updatedMCPToolOutput`, is parsed but
50
+ explicitly unsupported (the hook run is marked Failed, `should_block` stays
51
+ false, and `additionalContext` is dropped); an async hook preserves the
52
+ context only. A notice-only response (`additionalContext` without a rewrite
53
+ field, as this hook returns when the copy bound prevents a rewrite) is
54
+ accepted, so the notice can still reach the model on Codex; the link is never
55
+ rewritten there. The controls Codex does support are `decision: block` with a
56
+ non-empty reason, or exit 2 — they reject the model-facing result after
57
+ execution, but they do not rewrite the payload and do not remove prior
58
+ transcript exposure. Codex-side wiring is a harness-owned follow-up.
30
59
  - It runs after the tool has run. The command already executed, the terminal
31
60
  may already have shown the output, and files the command or the harness
32
61
  wrote (including a spill file for large output) keep the link. Whether the
@@ -34,8 +63,12 @@ It never blocks, and it never prints, logs or stores a matched URL.
34
63
  - PostToolUse hooks run in parallel on the original output and the last
35
64
  rewrite wins, so another rewriting hook can undo this one. This hook returns
36
65
  a rewrite only when it changed something.
37
- - A URL that carries its capability in the path, with no capability-named
38
- parameter, is not recognised.
66
+ - A path-borne capability is recognised only for the anchored, measured
67
+ provider classes in `PATH_CAPABILITY_CLASSES` (currently
68
+ `connect.stripe.com` with `^/setup/<letter>/(acct_<id>/)?<token>/?$`). A
69
+ token in the path of an unmeasured provider class is not recognised until
70
+ that class is measured and added; a generic "long path" heuristic would flag
71
+ ordinary links.
39
72
  - Output larger than its copy bound (1,000,000 JSON nodes or 2,000 levels
40
73
  deep) is still scanned for links; when one is found the notice is added but
41
74
  the output is not rewritten, because a partial copy would change the
@@ -4,8 +4,11 @@
4
4
  * PostToolUse hook: signed-link-output (Claude Code)
5
5
  *
6
6
  * The second layer behind signed-link-guard. When a tool result contains a
7
- * signed-link URL (an absolute URL whose query or fragment carries a
8
- * capability-class parameter such as `signature`), this hook:
7
+ * capability link — an absolute URL whose query or fragment carries a
8
+ * capability-class parameter such as `signature`, or a URL of an anchored,
9
+ * provider-scoped path-borne class such as the Stripe Connect onboarding link
10
+ * (`connect.stripe.com/setup/<letter>/<token>`, including the documented
11
+ * `connect.stripe.com/setup/c/acct_<id>/<token>` form) — this hook:
9
12
  *
10
13
  * 1. returns `hookSpecificOutput.updatedToolOutput`: the same tool result
11
14
  * with each such URL replaced by `<origin>/[redacted signed link]`, and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/hooks",
3
- "version": "0.12.4",
3
+ "version": "0.12.6",
4
4
  "description": "Open source hooks library for AI coding agents - Install safety, quality, and automation hooks with a single command",
5
5
  "type": "module",
6
6
  "bin": {