From 25f77e8a7235bcc3dd55f9a46f60cdb4df94b91a Mon Sep 17 00:00:00 2001 From: WilcoLouwerse Date: Thu, 12 Nov 2026 17:31:45 +0100 Subject: [PATCH 1/3] fix(global-settings): the clock rule only reads the arguments of date 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 ; 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 --- global-settings/CHANGELOG.md | 4 ++++ global-settings/VERSION | 2 +- global-settings/block-write-commands.sh | 7 +++++- .../tests/test-block-write-commands.sh | 23 +++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/global-settings/CHANGELOG.md b/global-settings/CHANGELOG.md index 97181368b..509fa74c5 100644 --- a/global-settings/CHANGELOG.md +++ b/global-settings/CHANGELOG.md @@ -6,6 +6,10 @@ One entry per released `VERSION`, newest first. The heading is the version numbe Versions 1.0.0 to 1.3.0 were released from the now archived `ConductionNL/claude-code-config` repository, and their date is the day they reached that repository's `main`. A few versions reached `main` together with the next one instead of on their own; their entry says so, and carries the date they reached `main`. Numbers that `main` never carried (1.5.0, 1.5.2, 1.5.3, 2.4.3) are listed under a `###` heading with a note on where their changes went. The update notice reads only `##` headings, so it skips them. +## 2.8.1 — 2026-11-12 + +A read-only command is no longer blocked as a clock change when another command on the same line has a `-s` flag, as in `curl -s … ; date -u`; only the arguments of `date` itself are checked. + ## 2.8.0 — 2026-10-02 The update notice is now short at session start and says in one sentence what each pending version adds. Ask Claude how to update for the full steps, or for the details of the changes with links to the pull requests. diff --git a/global-settings/VERSION b/global-settings/VERSION index 834f26295..dbe590065 100644 --- a/global-settings/VERSION +++ b/global-settings/VERSION @@ -1 +1 @@ -2.8.0 +2.8.1 diff --git a/global-settings/block-write-commands.sh b/global-settings/block-write-commands.sh index 87e81eb0d..fbce2206f 100644 --- a/global-settings/block-write-commands.sh +++ b/global-settings/block-write-commands.sh @@ -584,8 +584,13 @@ if echo "$cmd" | grep -qE '(^|[;&|]\s*)env\b'; then fi # ── date (HARD BLOCK: modifying system time — no legitimate use case) ───────── +# Only the arguments of a `date` invocation are inspected (up to the next +# `;`, `&`, `|` or newline; a quoted string never ends it), so another +# command's `-s` (as in `curl -s x; date -u`) is not mistaken for `date -s`. if echo "$cmd" | grep -qE '(^|[;&|]\s*)date\b'; then - if echo "$cmd" | grep -qE '(^|\s)(-s\s|--set[[:space:]=])'; then + _q="'"; _dq='"' + _date_segments=$(echo "$cmd" | grep -oE "(^|[;&|][[:space:]]*)date\b([^;&|${_dq}${_q}]|${_dq}[^${_dq}]*${_dq}|${_q}[^${_q}]*${_q})*") + if echo "$_date_segments" | grep -qE '(^|\s)(-s\s|--set[[:space:]=])'; then hard_deny "Blocked: date -s / --set modifies the system clock. This is never allowed." fi fi diff --git a/global-settings/tests/test-block-write-commands.sh b/global-settings/tests/test-block-write-commands.sh index f364f6765..473bd0d85 100644 --- a/global-settings/tests/test-block-write-commands.sh +++ b/global-settings/tests/test-block-write-commands.sh @@ -634,6 +634,29 @@ done add_ask "order v2.7.3: two asks" "rm build.log && npm install" add_ask "order v2.7.3: three asks" "gh pr create --title t --body b; docker compose up -d && echo x > out.txt" +# ── date -s: only the arguments of `date` itself count ──────────────────────── +# Another command's `-s` / `--set` on the same line (curl -s, sort -s, grep -s) +# is not a clock change. Every real `date -s` / `--set` form stays hard-denied. +add_allow "date: plain" "date" +add_allow "date: -u +%s" "date -u +%s" +add_allow "date: +%F" "date +%F" +add_allow "date: curl -s before it" "curl -s x; date -u" +add_allow "date: curl -s -o, date, docker exec tail" "curl -s -o /dev/null http://x/; date -u +%FT%T; docker exec c sh -c 'tail -n 4 f'" +add_allow "date: grep -s after it" "date -u; grep -s x f" +add_allow "date: sort -s after a pipe" "ls | sort -s" +add_allow "date: piped into a -s command" "date -u | sort -s" +add_allow "date: quoted ; in -d is not the end" "date -d 'a;b' +%s" +add_deny "date: -s quoted value" 'date -s "2020-01-01"' +add_deny "date: --set=" 'date --set="2020-01-01"' +add_deny "date: --set " "date --set 2020-01-01" +add_deny "date: -u -s" "date -u -s 2020-01-01" +add_deny "date: after ;" "foo; date -s x" +add_deny "date: after &&" "true && date -s x" +add_deny "date: after a pipe" "echo x | date -s x" +add_deny "date: after a harmless date" "date -u; date -s x" +add_deny "date: after curl -s" "curl -s x; date -s x" +add_deny "date: -s behind a quoted ;" "date -d 'a;b' -s now" + # ── v2.7.3 git push: `push` must end the word ───────────────────────────────── add_allow "push v2.7.3: git push-notes is another command" "git push-notes" add_allow "push v2.7.3: -C repo push-notes (asks, no deny)" "git -C repo push-notes" From 88a015cbc980519dbcbaec92e5aa7efb93d8a8bd Mon Sep 17 00:00:00 2001 From: WilcoLouwerse Date: Thu, 12 Nov 2026 18:12:20 +0100 Subject: [PATCH 2/3] =?UTF-8?q?fix(review):=20#938=20f1=20=E2=80=94=20a=20?= =?UTF-8?q?redirection,=20an=20escape=20or=20an=20open=20quote=20no=20long?= =?UTF-8?q?er=20ends=20the=20inspected=20segment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- global-settings/block-write-commands.sh | 13 +++++++++---- global-settings/tests/test-block-write-commands.sh | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/global-settings/block-write-commands.sh b/global-settings/block-write-commands.sh index fbce2206f..933917582 100644 --- a/global-settings/block-write-commands.sh +++ b/global-settings/block-write-commands.sh @@ -584,12 +584,17 @@ if echo "$cmd" | grep -qE '(^|[;&|]\s*)env\b'; then fi # ── date (HARD BLOCK: modifying system time — no legitimate use case) ───────── -# Only the arguments of a `date` invocation are inspected (up to the next -# `;`, `&`, `|` or newline; a quoted string never ends it), so another -# command's `-s` (as in `curl -s x; date -u`) is not mistaken for `date -s`. +# Only the arguments of a `date` invocation are inspected, so another command's +# `-s` (as in `curl -s x; date -u`) is not mistaken for `date -s`. The segment +# ends at a real separator only: `;`, `&&`, `||`, `|`, `|&`, a lone `&` or a +# newline. It does NOT end at a quoted string, an escaped character (`\;`, `\"`), +# or a redirection operator (`2>&1`, `&>`, `>|`, `<&`); a quote that is never +# closed runs to the end of the line (fail closed). The two sed steps below +# blank out escapes and redirections so the segment grep only sees real separators. if echo "$cmd" | grep -qE '(^|[;&|]\s*)date\b'; then _q="'"; _dq='"' - _date_segments=$(echo "$cmd" | grep -oE "(^|[;&|][[:space:]]*)date\b([^;&|${_dq}${_q}]|${_dq}[^${_dq}]*${_dq}|${_q}[^${_q}]*${_q})*") + _norm=$(echo "$cmd" | sed -E -e 's/\\./xx/g' -e 's/[0-9]*(>&|<&|&>>|&>|>\|)/RR/g') + _date_segments=$(echo "$_norm" | grep -oE "(^|[;&|][[:space:]]*)date\b([^;&|${_dq}${_q}]|${_dq}[^${_dq}]*${_dq}|${_q}[^${_q}]*${_q}|${_dq}[^${_dq}]*\$|${_q}[^${_q}]*\$)*") if echo "$_date_segments" | grep -qE '(^|\s)(-s\s|--set[[:space:]=])'; then hard_deny "Blocked: date -s / --set modifies the system clock. This is never allowed." fi diff --git a/global-settings/tests/test-block-write-commands.sh b/global-settings/tests/test-block-write-commands.sh index 473bd0d85..da8beb7ca 100644 --- a/global-settings/tests/test-block-write-commands.sh +++ b/global-settings/tests/test-block-write-commands.sh @@ -656,6 +656,16 @@ add_deny "date: after a pipe" "echo x | date -s x" add_deny "date: after a harmless date" "date -u; date -s x" add_deny "date: after curl -s" "curl -s x; date -s x" add_deny "date: -s behind a quoted ;" "date -d 'a;b' -s now" +# A redirection, an escape or an open quote does not end the inspected segment. +add_allow "date: redirection then ; then curl -s" "date -u 2>/dev/null; curl -s x" +add_allow "date: 2>&1 piped into sort -s" "date -u 2>&1 | sort -s" +add_deny "date: -s behind 2>&1" "date -u 2>&1 -s 2020-01-01" +add_deny "date: -s behind &>" "date -u &>/dev/null -s 2020-01-01" +add_deny "date: -s behind >|" 'date >|/tmp/x -s 2020-01-01' +add_deny "date: -s behind an escaped ;" 'date +a\;b -s 2020-01-01' +add_deny "date: -s behind an escaped \"" 'date +\" -s 2020-01-01' +add_deny "date: -s behind an escaped '" "date +\\' -s 2020-01-01" +add_deny "date: -s inside an unclosed quote" 'date -d "a -s now' # ── v2.7.3 git push: `push` must end the word ───────────────────────────────── add_allow "push v2.7.3: git push-notes is another command" "git push-notes" From 10c7ecd6038adeb10afef634cee0547f18961631 Mon Sep 17 00:00:00 2001 From: WilcoLouwerse Date: Thu, 12 Nov 2026 18:22:03 +0100 Subject: [PATCH 3/3] =?UTF-8?q?fix(review):=20#938=20f3=20=E2=80=94=20a=20?= =?UTF-8?q?substitution=20on=20the=20line=20makes=20the=20whole=20line=20c?= =?UTF-8?q?ount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- global-settings/block-write-commands.sh | 5 +++++ global-settings/tests/test-block-write-commands.sh | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/global-settings/block-write-commands.sh b/global-settings/block-write-commands.sh index 933917582..6efbaac8a 100644 --- a/global-settings/block-write-commands.sh +++ b/global-settings/block-write-commands.sh @@ -595,6 +595,11 @@ if echo "$cmd" | grep -qE '(^|[;&|]\s*)date\b'; then _q="'"; _dq='"' _norm=$(echo "$cmd" | sed -E -e 's/\\./xx/g' -e 's/[0-9]*(>&|<&|&>>|&>|>\|)/RR/g') _date_segments=$(echo "$_norm" | grep -oE "(^|[;&|][[:space:]]*)date\b([^;&|${_dq}${_q}]|${_dq}[^${_dq}]*${_dq}|${_q}[^${_q}]*${_q}|${_dq}[^${_dq}]*\$|${_q}[^${_q}]*\$)*") + # A command or process substitution can hold its own `;` or `|`, which the + # segment grep cannot follow: with one on the line, the whole line counts. + if echo "$cmd" | grep -qE '\$\(|`|[<>]\('; then + _date_segments="$_norm" + fi if echo "$_date_segments" | grep -qE '(^|\s)(-s\s|--set[[:space:]=])'; then hard_deny "Blocked: date -s / --set modifies the system clock. This is never allowed." fi diff --git a/global-settings/tests/test-block-write-commands.sh b/global-settings/tests/test-block-write-commands.sh index da8beb7ca..5d6ee22b0 100644 --- a/global-settings/tests/test-block-write-commands.sh +++ b/global-settings/tests/test-block-write-commands.sh @@ -666,6 +666,12 @@ add_deny "date: -s behind an escaped ;" 'date +a\;b -s 2020-01- add_deny "date: -s behind an escaped \"" 'date +\" -s 2020-01-01' add_deny "date: -s behind an escaped '" "date +\\' -s 2020-01-01" add_deny "date: -s inside an unclosed quote" 'date -d "a -s now' +# A substitution can hold its own separator; with one on the line the whole line counts. +add_deny "date: -s behind a \$( ; ) substitution" 'date $(echo +%F; true) -s 2020-01-01' +add_deny "date: -s behind a backtick substitution" 'date `echo +%F; true` -s 2020-01-01' +add_deny "date: -s behind a \$( | ) substitution" 'date $(echo a | cat) -s 2020-01-01' +add_deny "date: -s behind a process substitution" 'date <(echo a; echo b) -s 2020-01-01' +add_allow "date: substitution on the line, no -s" 'date -d "$(echo now)" +%s; curl x' # ── v2.7.3 git push: `push` must end the word ───────────────────────────────── add_allow "push v2.7.3: git push-notes is another command" "git push-notes"