fix(operations.files): shell-quote files.block content#10
Closed
wowi42 wants to merge 1 commit into
Closed
Conversation
files.block passed the block content to awk as a positional argument
wrapped in raw quote characters via string concatenation instead of
proper shell quoting. Content containing double quotes, single quotes,
$(...) or backticks broke the generated command, e.g.
eval "$(zoxide init --cmd cd bash)"
failed on the second run with `sh: Syntax error: "(" unexpected`. The
create path used a heredoc so the first run succeeded, masking the bug
until the block needed updating.
Content is now passed through QuoteString (shlex.quote) on the update
and line-match paths, and the create-path heredoc delimiter is quoted
(<<'PYINFRAHERE'), so content is always written verbatim and is never
expanded on the remote host. This also removes the previous limitation
where content containing raw single quotes could break.
try_prevent_shell_expansion no longer affects quoting (content is always
literal); it is kept and accepted for backwards compatibility and
documented as deprecated.
Upstream issue: pyinfra-dev#1758
Author
|
Superseded by upstream PR pyinfra-dev#1759. |
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.
Summary
files.blockpassed the block content toawkas a positional argument wrapped in raw quote characters via string concatenation instead of proper shell quoting. Any content containing double quotes, single quotes,$(...)or backticks broke the generated command.Reproduction (from upstream issue):
The create path used a heredoc, so the first run succeeded; the second run (update existing block) failed with
sh: Syntax error: "(" unexpected. The line-match path was affected the same way. Unquoted content was also a shell-injection vector.Fix
QuoteString(shlex.quote).<<'PYINFRAHERE') so the body is literal too.try_prevent_shell_expansionno longer affects quoting (content is always literal); it is kept and accepted for backwards compatibility and documented as deprecated.Tests
",'and$(...)in the content (written test-first, confirmed failing before the fix).1737 passed);scripts/dev-lint.shclean (ruff, format, mypy, arguments-sync).Fixes the bug reported upstream: pyinfra-dev#1758