Fix shell injection in Installer.user_set_shell and Installer.chown#4443
Open
Softer wants to merge 1 commit intoarchlinux:masterfrom
Open
Fix shell injection in Installer.user_set_shell and Installer.chown#4443Softer wants to merge 1 commit intoarchlinux:masterfrom
Softer wants to merge 1 commit intoarchlinux:masterfrom
Conversation
Use argv list with run() instead of sh -c with f-string interpolation, fix mutable default argument in chown, add debug logging on failure.
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.
Installer.user_set_shellandInstaller.chownbuilt shell commands via f-string interpolation insidesh -c "...", allowing command injection via caller-supplied username, shell, path, or options.Replaced both with argv lists passed directly to
run(), matching the pattern already used byuser_set_password. The full string is now a single argv element and cannot be shell-parsed.Both methods are public API of the
Installerclass and are reachable from custominstall.pyscripts and plugin code. Any caller that passes unsanitized strings (e.g. a username containing;,$(), backticks, or spaces) would execute arbitrary shell commands in the chroot. The fix removes the shell layer entirely.Changes
user_set_shell:sh -c "chsh -s {shell} {user}"->run(['arch-chroot', '-S', target, 'chsh', '-s', shell, user])chown:sh -c 'chown {options} {owner} {cleaned_path}'->run(['arch-chroot', '-S', target, 'chown', *options, owner, path])cleaned_pathquote-escape hack (no longer needed).options: list[str] = []->options: list[str] | None = None.debug()log onCalledProcessErrorin both methods.Tests
; rm -rf /,$(id), backticks, spaces, quotes) confirms the entire string stays a single argv element and is never shell-parsed