Skip to content

fix: round-H audit hardening (pid, filename, ssh timeout, throttling)#17

Merged
flamerged merged 1 commit into
masterfrom
fix/audit-batch-h
May 1, 2026
Merged

fix: round-H audit hardening (pid, filename, ssh timeout, throttling)#17
flamerged merged 1 commit into
masterfrom
fix/audit-batch-h

Conversation

@flamerged
Copy link
Copy Markdown
Owner

Summary

Six bugs from the latest audit batch, all in one fix: PR (sr → patch release).

  • PID file kill safety: verify cmdline contains sshshot + --daemon before sending a signal. Prevents sshshot stop killing an unrelated PID-recycled process.
  • Filename collision: generateFilename() collided on same-second screenshots. Adds milliseconds + 4-char random hex suffix. SAFE_REMOTE_FILENAME_RE updated; new test covers 100 same-tick calls being unique.
  • Status display "(from" leak: PID-file path stored a synthetic command string; the --daemon\s+(\S+) regex extracted "(from". ProcessInfo now carries a nullable target instead of command; PID-file path reads config.activeTarget for display.
  • Remote home path: ssh remote 'echo $HOME' with per-daemon cache. Handles /Users/<user>, /data/<user>, custom HOME overrides — anything getent passwd would resolve. Heuristic fallback retained for unreachable hosts.
  • SSH ConnectTimeout=5: applied to pipeToRemote and the echo-$HOME probe. Failures now surface in ~5s instead of SSH's ~75s default.
  • Config error throttling: loadConfig writes stderr once per unique read/parse error; persistent broken file stops spamming 5x/sec.

Test plan

  • yarn typecheck
  • yarn lint
  • yarn build
  • yarn format:check
  • yarn test (25 tests, +2 new for filename uniqueness/shape)
  • CI matrix Node 20/22/24 green

- Verify cmdline before signaling PID-file pid (`isSshshotDaemonPid`).
  Prevents `sshshot stop` from killing an unrelated process when the OS
  recycles the daemon's old PID.
- generateFilename() now includes ms + 4-char random suffix, eliminating
  same-second collisions on rapid-fire screenshots. SAFE_REMOTE_FILENAME_RE
  and tests updated.
- ProcessInfo loses the synthetic `command` field; it now carries an
  explicit nullable `target`. Status output no longer prints "(from"
  when discovery used the PID file.
- getRemoteHomePath() asks the remote directly via `ssh remote 'echo \$HOME'`
  with a per-daemon cache. Falls back to the user@host / ssh -G heuristic
  on failure. Handles non-standard home dirs (/Users/<user>, /data/<user>,
  custom HOME overrides) instead of guessing /home/<user>.
- Add `-o ConnectTimeout=5` to pipeToRemote and the new echo-\$HOME probe
  so an unreachable host fails in ~5s instead of SSH's default ~75s.
- Throttle loadConfig() parse/read error stderr to once per unique error
  message — a persistent broken file no longer floods stderr 5x/sec.

Adds two new tests covering filename uniqueness and the new shape.
@flamerged flamerged merged commit 7951546 into master May 1, 2026
5 checks passed
@flamerged flamerged deleted the fix/audit-batch-h branch May 1, 2026 19:19
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

🎉 This PR is included in version 0.7.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant