Skip to content

fix(user,group): execute useradd/groupadd via argv instead of /bin/sh -c#31

Open
ratazzi wants to merge 1 commit into
masterfrom
fix/user-group-shell-injection
Open

fix(user,group): execute useradd/groupadd via argv instead of /bin/sh -c#31
ratazzi wants to merge 1 commit into
masterfrom
fix/user-group-shell-injection

Conversation

@ratazzi

@ratazzi ratazzi commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Problem

The user and group resources built management commands as shell strings and ran them through /bin/sh -c:

  • The username/group name was interpolated without any quoting, so a resource name like "foo; touch /tmp/pwned" executed the injected command — typically as root.
  • comment/home/shell/password were wrapped in single quotes without escaping embedded quotes, so a benign GECOS comment like O'Reilly broke 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/gpasswd all accept their flags directly.

This also drops the gpasswd append-flag prepend, which produced an invalid duplicated -a when append true was set.

Testing

  • New unit tests cover argv construction, including values containing shell metacharacters (;, $(), quotes) which now stay single literal argv elements.
  • zig build test — 12 tests pass (3 new).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant