Repository navigation
Conversation
…and line (#577) build_remember_entry() interpolated the plugin's install path into a `bash "{path}"` shell command line with only hand-written double quotes. A literal double quote in the path broke the command outright, and double quotes still permit POSIX $(...) command substitution, so a path containing one was executed rather than treated as literal. Replace the whole construction with shlex.quote() applied to the entire argument, rather than nesting shlex.quote()'s output inside the existing double-quote wrapper -- shlex.quote() switches to single-quoting when the path holds a double quote, and embedding that inside another pair of double quotes reopens the exact same hole. Extend the existing test file with real-bash execution controls for the quote and $(...) hazards (red before the fix, green after) plus a positive control for an ordinary path, and update the two tests that parsed the emitted command by splitting on a literal '"' to use shlex.split() instead, since the ordinary case is now emitted unquoted. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Bv6BGZD2EdZ9EuJ7tPDTb7
Self-review (Explore + oss:auditor) on the #577 quoting commit found four issues, all in the test file's own new subprocess-based controls, not in the fix itself: - The new tests wrote their marker script with `open(..., "w")` and no `newline=""`, so Python's default text-mode translation turns every `\n` into `\r\n` on Windows -- a stray CR right after a closing quote is not IFS whitespace to bash, so it corrupts the redirect target and the marker file is never created there. Fixed with `newline=""`. - The new tests used `shutil.which("bash")`/literal `"bash"` to find and invoke a shell, which this repo's own tests/_bash_runner.py and test_hooks_json.py already document as unreliable on Windows (PATH's "bash" there commonly resolves to the WSL launcher, not Git Bash -- the exact ambiguity #432 previously fixed for other test modules). Migrated to the shared `resolve_bash()` helper every sibling subprocess-bash test module already uses. - `test_build_entry_command_survives_windows_shell_quoting`'s docstring still described the test above it as `command.split('"')[1]`, which that test no longer does after the #577 diff rewrote it to use `shlex.split()`. Updated to match. - The comment justifying shlex.quote() as the right quoting model overstated its own confidence: it is only established that POSIX quoting is correct for bash's OWN parsing of the command string once bash receives it, not that a Windows-hosted agy install's own hook executor tokenizes the raw string with bash rather than something else (e.g. cmd.exe) before that point. Narrowed to say so explicitly and marked REASONED not observed, consistent with the rest of this file's Windows caveats. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Bv6BGZD2EdZ9EuJ7tPDTb7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #577.
build_remember_entry()interpolated the plugin's install path into a shell command line asbash "{command_path}", with hand-written double quotes as the only protection. A literal double quote in the install path broke the command outright (a shell syntax error), and a$(...)sequence in the path was still executed as a POSIX command substitution -- double quotes do not suppress that, only single quotes do.plugin_rootis always the user's own checkout path (os.path.abspath(os.path.dirname(__file__)/'..')), never remote-controlled, so this is a low-severity hardening fix rather than a real injection vector -- the audit that filed #577 says the same.Fix: replace the whole construction with
shlex.quote()applied to the entire command_path, then interpolated asbash {command_path}-- not nested inside the oldbash "{...}"wrapper. Nesting is unsafe on its own:shlex.quote()switches to single-quoting whenever the path needs it, and a path containing a literal double quote produces a single-quoted string that still embeds that", which breaks out of an outer pair of double quotes exactly the same way the original bug did. Quoting the whole argument, rather than only the interpolated segment, is what actually closes the hole.Tests (TDD, red before the fix): three new tests in
tests/test_install_agy_hooks_563.pyactually invoke a real, correctly-resolved bash (via this repo's own_bash_runner.resolve_bash(), sinceshutil.which("bash")is documented unreliable on Windows) against a root containing a literal", a root containing$(...), and an ordinary root as a positive control. Two pre-existing tests that parsed the emitted command by splitting on a literal"were migrated toshlex.split(), since the ordinary case is now emitted with no quotes at all (shlex.quote()leaves a metacharacter-free path unquoted).Self-review (Explore + oss:auditor, against the first commit) found four issues, all fixed in a second commit, all in the new tests rather than in the fix itself: a Windows CRLF hazard in the marker-script helper (
newline=""now used), theshutil.which("bash")/literal-"bash"unreliability just mentioned, a docstring left describing pre-diff test internals, and a comment overclaiming that POSIX quoting is safe for every step a Windows-hostedagyinstall might take before reaching bash (narrowed toREASONED, not observed, matching this file's existing Windows caveats).below-bar item (not filed, recorded here per the audit bar): the reviewer also raised whether
shlex.quote()'s single-quoting could itself be mis-tokenized bycmd.exeif some other, unconfirmed invocation path spawns this command line throughcmd.exebefore bash ever sees it, rather than exec'ing bash directly. This is a real, stateable concern but not a reachable one from anything this diff can observe: nothing in this codebase or its docs establishes that agy invokes hook commands viacmd.exeon Windows at all (Windows agy support isREASONED, not observedthroughout this file already), so there is no input in hand that reaches the class -- it is a hypothesis about a mechanism nobody has confirmed exists, not a defect with a caller.Changelog:
changelog.d/577.fixed.mdadded and passesassemble_changelog.py --check. No README change needed -- internal hardening, no interface change.[AI-generated]