Skip to content

Harden lock takeover, killGroup and JSON extraction - #1

Merged
devmaxxx merged 6 commits into
mainfrom
fix/audit-hardening
Oct 17, 2026
Merged

devmaxxx merged 6 commits into
mainfrom
fix/audit-hardening

Conversation

@devmaxxx

Copy link
Copy Markdown
Owner

Summary

Audit pass over every module.

  • build: add unrun so tsdown can load tsdown.config.ts on Node versions without native type stripping. pnpm build failed on Node 22.13.
  • json: lastJsonObject retries from an earlier } when a stray one in later prose ends no object, and a guard that rejects the last object now falls back to an earlier one. The total try cap is unchanged, and hostile input still finishes in under a second.
  • proc: killGroup sends SIGTERM to every detached descendant group and waits the grace period for all of them before SIGKILL; before this, they only got SIGKILL. isAlive rejects 0, negative and non-integer pids. cwdOf reads /proc on Linux. The spawnGroup options are optional.
  • lock: a stale lock is renamed aside and checked by inode and pid before removal, so two runs clearing the same stale lock cannot both take it. A race between three runs is documented in the README limits.
  • ansi: strip ESC ( B (from tput sgr0), ESC 7/ESC 8 and ESC =/ESC >, and never treat [ or { as an escape's final byte, so the JSON after a truncated escape stays intact.
  • watchdog: the default clock is now performance.now(). An NTP step no longer fires it, and time the machine spends asleep does not count as a stall.
  • engines: Node >=22, and CI tests on Node 22 and 24 across Ubuntu, macOS and Windows. Node 20 is end-of-life, and the dev toolchain cannot run on it.

Behaviour changes

  • lastJsonObject(text, guard) can now return an earlier object when the guard rejects the last one.
  • Watchdog limits count only the time the machine is awake.

Test plan

  • pnpm typecheck, pnpm lint, pnpm test (70 tests) and pnpm build with publint pass locally on macOS
  • The new killGroup SIGTERM test fails against the old proc.ts
  • CI is green on Ubuntu, macOS and Windows, on Node 22 and 24

Audit pass over every module.

- build: add unrun so tsdown can load its TypeScript config on Node
  versions without native type stripping.
- json: lastJsonObject retries from an earlier `}` when a stray one in
  later prose ends no object, and a guard that rejects the last object
  now falls back to an earlier one. The total try cap is unchanged.
- proc: killGroup sends SIGTERM to every detached descendant group, not
  only the target, and waits the grace period for all of them before
  SIGKILL. isAlive rejects 0, negative and non-integer pids, which
  kill(2) reads as process groups. cwdOf reads /proc on Linux. The
  spawnGroup options are optional.
- lock: a stale lock is renamed aside and checked by inode and pid
  before removal, so two runs clearing the same stale lock cannot both
  take it.
- ansi: strip short escapes such as ESC ( B, ESC 7 and ESC =, and never
  treat `[` or `{` as an escape's final byte.
- watchdog: default to a monotonic clock.
- Require Node 22 and test on Node 22 and 24.
@devmaxxx
devmaxxx merged commit cbfedd3 into main Oct 17, 2026
5 checks passed
@devmaxxx
devmaxxx deleted the fix/audit-hardening branch October 17, 2026 17:53
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