param-mutation.ts 593 B

123456789101112
  1. // Parameter write-back (heap fix): objects cross call boundaries by reference. `stash`
  2. // writes a tainted value into a field of its `box` parameter; the write is merged back
  3. // into the caller's argument, so the caller reads the secret through `box.f`.
  4. // Expected: source -> ask#1, ask#1 -> ask#2 (secret via param write-back), ask#2 -> sink.
  5. function stash(box: { f: string }, v: string): void {
  6. box.f = v;
  7. }
  8. const secret = await agent("writer").ask<string>("secret");
  9. const box = { f: "" };
  10. stash(box, secret);
  11. const out = await agent("reader").ask<string>(`use ${box.f}`);
  12. return out;