Fix review round 1 of the wait list and its hooks (issues 1629, 1743, 1744)
A session id reaching the Stop and SessionStart hooks was only checked for blank, so "../../x" or "a/b" could read or write outside the waits directory; both hooks now hold every session id to waitSessionID before building any path, and allow (saying why) rather than fail on a bad one. claude_code_wait's list/watched/done/said held only add to that same check, letting a malformed id through as an ordinary, always-empty key; they all refuse it now. The Stop hook's three-strikes cap could be bypassed forever if its counter file could not be written on a refusal: it now allows instead, saying so, so a wait can never hold a turn open indefinitely. Its advice offered mesh_wait on a wait's event family unconditionally, ignoring that the session's tool runner may not be granted it (ADR 0367 §2); it now offers mesh_wait only "if this session's tool runner is granted it, otherwise start a watcher", and drops the family entirely when a wait has none. Both hooks' fail-open and let-through notices were said only on stderr, which Claude Code does not show the operator on an allowed (exit 0) outcome; they now also print the same words as a "systemMessage" JSON object on stdout, which Claude Code does show.
This commit is contained in:
@@ -232,6 +232,27 @@ func TestAddRefusesOutsideItsBounds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Review round 1 item (b): list, watched, done and said refuse a session id that is not a plain one (the
|
||||
// same waitSessionID add already holds to), naming "session" — not silently treating it as just-another-key.
|
||||
func TestListWatchedDoneAndSaidRefuseABadSessionID(t *testing.T) {
|
||||
p, _ := node(t, "g14")
|
||||
for _, bad := range []string{"", "a/b", "../x"} {
|
||||
store := newMemWaits()
|
||||
if _, err := ListWaits(p, bad, store, t0); err == nil || !strings.Contains(err.Error(), "session") {
|
||||
t.Errorf("list %q: %v", bad, err)
|
||||
}
|
||||
if _, err := WatchedWait(p, bad, "w-1", "watcher", store, t0); err == nil || !strings.Contains(err.Error(), "session") {
|
||||
t.Errorf("watched %q: %v", bad, err)
|
||||
}
|
||||
if _, err := DoneWait(p, bad, "w-1", "outcome", store, t0); err == nil || !strings.Contains(err.Error(), "session") {
|
||||
t.Errorf("done %q: %v", bad, err)
|
||||
}
|
||||
if _, err := SaidWait(p, bad, "w-1", store, t0); err == nil || !strings.Contains(err.Error(), "session") {
|
||||
t.Errorf("said %q: %v", bad, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1629/AC6: the tool is served through the module's own dispatch.
|
||||
func TestTheWaitToolIsServedThroughTheModulesDispatch(t *testing.T) {
|
||||
p, _ := node(t, "g14")
|
||||
|
||||
Reference in New Issue
Block a user