Skip to content

fix(global-settings): the clock rule only reads the arguments of date itself (v2.8.1) - #938

Merged
rjzondervan merged 3 commits into
mainfrom
fix/hook-date-set-false-positive
Nov 13, 2026
Merged

rjzondervan merged 3 commits into
mainfrom
fix/hook-date-set-false-positive

Conversation

@WilcoLouwerse

@WilcoLouwerse WilcoLouwerse commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What

The hook rule that refuses a change of the system clock looked for the set flag anywhere on the command line. A read-only line such as curl -s <url>; date -u was therefore refused because of curl's own -s.

The rule now inspects each date invocation up to the next real command separator (;, &&, ||, |, |&, a lone &, a newline).

Behaviour

  • Passes now: curl -s x; date -u, date -u; grep -s x f, date -u 2>&1 | sort -s.
  • Still refused: every -s / --set form of date itself, also after ;, && or a pipe.
  • Does not end the inspected part: a quoted string, an escaped character, a redirection (2>&1, &>, >|), a quote that is never closed.
  • Fail closed: when the line holds a command or process substitution ($(, a backtick, <(), the whole line is read, as before. Such a line with another command's -s on it is still refused.
  • Unchanged: sudo date was not covered by this rule and still is not.

Verification

  • 33 new cases in global-settings/tests/test-block-write-commands.sh; see the review for the suite counts on the head.
  • tests/test-check-settings-version.sh passes 114 of 114.
  • bash -n clean. shellcheck was not run locally (not installed); the ShellCheck job in CI covers it.

Version 2.8.0 → 2.8.1 with a changelog entry.

🤖 Generated with Claude Code

WilcoLouwerse and others added 3 commits November 12, 2026 17:31
… itself (v2.8.1)

The rule that refuses a change of the system clock looked for the set
flag anywhere on the command line. A read-only line such as
`curl -s <url>; date -u` was therefore refused because of curl's own
`-s`.

The rule now inspects each `date` invocation up to the next `;`, `&`,
`|` or newline, with quoted strings consumed whole. Every form that was
refused before is still refused; `sudo date` was not covered and still
is not.

Adds 19 cases to the hook test suite (8691 of 8691 pass) and the 2.8.1
changelog entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…onger ends the inspected segment

The inspected `date` segment now ends only at a real separator: `;`, `&&`, `||`, `|`, `|&`, a lone `&` or a newline.
Escaped characters (`\;`, `\"`) and redirection operators (`2>&1`, `&>`, `&>>`, `>|`, `<&`) are blanked out first, and a quote that is never closed runs to the end of the line (fail closed).
Adds the six refused forms as deny cases and two allow cases to the date test section.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e count

A command or process substitution can carry its own `;` or `|`, which
the segment match cannot follow, so the set flag behind one slipped
through. When the line holds `$(`, a backtick or `<(` / `>(`, the rule
now reads the whole line, as it did before this pull request.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@WilcoLouwerse WilcoLouwerse changed the title fix(global-settings): the clock rule only reads the arguments of the clock command itself (v2.8.1) fix(global-settings): the clock rule only reads the arguments of date itself (v2.8.1) Nov 12, 2026

@WilcoLouwerse WilcoLouwerse left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE (Standard · full)

Self-review, so posted as a comment. The first commit narrowed the clock rule too far; the two follow-up commits on this branch close that, and on head 10c7ecd6 every line the rule refused on main is refused again, apart from the false positives this PR set out to remove.

🔴 Found and fixed before this verdict

  • f1 — a redirection, an escape or an open quote ended the inspected part too early. On 25f77e8a six valid forms that main refused passed the rule: -s behind 2>&1, &>, >|, an escaped \;, an escaped \" or \'. Fixed in 88a015c: escapes and redirection operators are blanked before the match, and a quote that is never closed runs to the end of the line.
  • f3 — a substitution carries its own separators. Found in the check of the f1 fix: -s behind $(a; b), a backtick substitution, $(a | b) or <(a; b) still passed. Fixed in 10c7ecd: with a substitution on the line, the rule reads the whole line, as on main.

Verification, old script (origin/main) against the head, each line fed to the hook as JSON on stdin: all ten forms above are refused by both; curl -s x; date -u, date -u; grep -s x f and date -u 2>&1 | sort -s are refused by the old script and pass on the head.

🟢 Minor

  • f2 — the PR title differed from the commit subject. Aligned.
  • A line that holds a substitution and another command's -s is still refused (for example date +%s; curl -s "$(…)"). That is the fail-closed choice of f3 and is named in the description.

Context

  • Tests: global-settings/tests/test-block-write-commands.sh passes 8705 of 8705 on the head; test-check-settings-version.sh 114 of 114; bash -n clean. shellcheck was not run locally.
  • CI: the 28 checks on 10c7ecd6 were still pending when this was posted.
  • Gates: the local gate run reported three failures (coding-standard-adoption, composer-cooldown-config, adr-number-collision). All three are repository-wide and unrelated to this diff.
  • Not covered, as before this PR: sudo date, $(date …), and escapes or quotes that span a newline.
  • Merge: needs an approving review from a colleague; this comment is not one.

@rjzondervan
rjzondervan merged commit 36e11ae into main Nov 13, 2026
57 of 59 checks passed
@WilcoLouwerse
WilcoLouwerse deleted the fix/hook-date-set-false-positive branch November 13, 2026 13:48
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.

2 participants