fix(user,group): execute useradd/groupadd via argv instead of /bin/sh -c#31
Open
ratazzi wants to merge 1 commit into
Open
fix(user,group): execute useradd/groupadd via argv instead of /bin/sh -c#31ratazzi wants to merge 1 commit into
ratazzi wants to merge 1 commit into
Conversation
User and group management commands were built as shell strings and run through /bin/sh -c. The username/group name was interpolated without any quoting, and comment/home/shell/password were wrapped in single quotes without escaping embedded quotes. A resource name like "foo; touch /tmp/pwned" therefore executed the injected command (typically as root), and a benign GECOS comment such as "O'Reilly" broke the command line. Build argv vectors and pass them directly to std.process.run so no field is ever parsed by a shell. This also drops the gpasswd append flag prepend, which produced an invalid duplicated "-a" when append was true. Covers argv construction with tests, including values containing shell metacharacters.
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.
Problem
The
userandgroupresources built management commands as shell strings and ran them through/bin/sh -c:"foo; touch /tmp/pwned"executed the injected command — typically as root.comment/home/shell/passwordwere wrapped in single quotes without escaping embedded quotes, so a benign GECOS comment likeO'Reillybroke the command line.Fix
Build argv vectors and pass them directly to
std.process.run, so no field is ever parsed by a shell.useradd/usermod/userdel/groupadd/groupmod/groupdel/passwd/gpasswdall accept their flags directly.This also drops the
gpasswdappend-flag prepend, which produced an invalid duplicated-awhenappend truewas set.Testing
;,$(), quotes) which now stay single literal argv elements.zig build test— 12 tests pass (3 new).