Skip to content

fix: reject remote upgrade when throttle timestamp cannot be persisted (#636) - #650

Open
pithead-developer[bot] wants to merge 1 commit into
developfrom
agent/636-reject-remote-upgrade-attempts-when-thro-v2
Open

pithead-developer[bot] wants to merge 1 commit into
developfrom
agent/636-reject-remote-upgrade-attempts-when-thro-v2

Conversation

@pithead-developer

Copy link
Copy Markdown
Contributor

Closes #636

What's the problem

The remote-upgrade throttle's stamp file write silently ignored failures. When printf '%s\n' "$now" >"$stamp" could not write (e.g. read-only directory, filesystem full, or a symlinked path), the || true swallowed the error and the function returned 0 — as if the throttle state had persisted. A subsequent call would also fail to read the stamp (or read a stale zero), resetting the cooldown and allowing unlimited upgrade attempts.

How I fixed it

  1. Validate the state directory. The directory must be root-owned with mode 0700. A misconfigured or receiver-malleable state directory is rejected with rc 2.

  2. Validate the stamp path before reading. If a symlink points at the stamp file, it is rejected with rc 2 instead of silently reading a hostile path.

  3. Atomic stamp write. The timestamp is written to a temp file in the same directory, then atomically renamed via mv -f. If the write or rename fails, the lock is closed and rc 2 is returned. No descriptor leak.

  4. No comments in code. Deleted the 5-line function docstring and the 6-line lock failure comment. Explanations live in this PR body and the docs.

Here is the proof

  • bash -n rigforge.sh tests/run.sh — PASS.
  • shellcheck --severity=warning rigforge.sh tests/run.sh — PASS.
  • git diff --check — PASS.
  • FILE_BUDGET_REQUIRE_BASE=1 bash scripts/lint-file-budget.sh — FAIL (tests/run.sh is 9 lines over ceiling; the regression tests for this bug require new test lines). The code change is complete and correct; the budget ceiling would need to be raised.

Tests added for #636:

  • Symlink stamp pointing to an unwritable directory returns rc 2 (fail-closed).
  • Normal stamping with atomic tmpfile+rename works: first call stamps, second call is throttled.

🤖 Generated with Claude Code

#636)

The stamp file write silently ignored failures (printf ... || true).
When the write could not persist, the throttle state was effectively
disabled, allowing unlimited upgrade attempts.

Fix:
- Validate state directory is root-owned mode 0700
- Reject symlinked stamp paths
- Use atomic tmpfile+mv for stamp writes
- Close lock descriptor on any failure, return rc 2

Deleted explanatory comments per no-comments rule.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject remote upgrade attempts when throttle state cannot be persisted

0 participants