Skip to content

fix: harden update cache boundary - #72

Merged
abruption merged 1 commit into
mainfrom
fix/update-cache-boundary
Sep 29, 2026
Merged

abruption merged 1 commit into
mainfrom
fix/update-cache-boundary

Conversation

@abruption

Copy link
Copy Markdown
Owner

Summary

  • fix: a FIFO at the update cache path hangs list, inspect, and unlock #57 (FIFO at cache paths): the cache file and update.lock are checked with lstat as private regular files before opening, opened with O_NOFOLLOW | O_NONBLOCK, and revalidated with fstat (device/inode) after opening. The final verification open in writeUpdateCache is also non-blocking. A FIFO now yields an invalid cache (cache_file_is_not_private) or an unavailable lease (refresh_lock_is_not_private) immediately.
  • fix: explicit check-update fails when the cache directory is not writable #62 (unwritable cache directory): explicit check-update uses a new checkForUpdate() that treats the cache as advisory. If the lease or cache write fails, a successful registry result is still reported with status: "ok" and exit 0. Lease contention without a fresh cache still returns refresh_in_progress, and registry failures still exit 3. Human output prints one stderr warning (update cache not updated: <reason>); JSON mode keeps stderr empty.
  • fix: elevated runs with a preserved HOME create a root-owned update cache in the user home #70 (elevated runs / foreign-owned home): a new cache boundary check runs before any mkdir in the read, write, and lease paths, including the background refresh child. It returns cache_user_is_elevated for UID 0, and cache_root_owner_mismatch / cache_root_is_unsafe / cache_root_unavailable when the nearest existing ancestor of the cache directory is not a directory owned by the current UID. Automatic notices and refresh scheduling are skipped in that case. Nothing is chowned or chmodded to repair foreign-owned state.

Closes #57
Closes #62
Closes #70

Type

  • fix

Safety impact

No change to lock probing, owner validation, or signaling. JSON output changes are additive: checkUpdateResult gains optional cacheUpdated: boolean and cacheWarning: string | null. Both are optional in the schema and the TypeScript types and are documented in docs/json-v1.md as "Since 0.4.1"; the statement that cache-write failures exit 3 was removed.

Checklist

  • npm run check passes
  • npm run lint passes
  • npm test passes (95 pass, 0 fail)
  • npm run smoke:package passes
  • Commits follow Conventional Commits
  • Documentation is updated when behavior or output changed
  • No tokens, private paths, or unredacted process data are in the diff

Notes

Reject FIFOs and other special files at the cache and refresh-lease
paths with an lstat pre-check, O_NONBLOCK opens, and an fstat
device/inode revalidation so diagnostic commands never block on them.

Treat the cache as advisory for explicit check-update: an unavailable
lease or cache write no longer turns a successful registry check into
an error. The result adds optional cacheUpdated and cacheWarning fields
and human output prints one stderr warning.

Skip cache reads, writes, and automatic refreshes when running as UID 0
or when the nearest existing cache ancestor is not owned by the current
UID, without creating directories or repairing foreign-owned state.

Closes #57
Closes #62
Closes #70
@abruption
abruption force-pushed the fix/update-cache-boundary branch from 24c8e12 to d15c9f3 Compare September 29, 2026 00:23
@abruption
abruption merged commit 72d2b6e into main Sep 29, 2026
24 checks passed
@abruption
abruption deleted the fix/update-cache-boundary branch September 29, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant