Skip to content

Validate the module name used to pick an install directory - #590

Open
silug wants to merge 1 commit into
OpenVoxProject:mainfrom
silug:validate-module-install-dir
Open

Validate the module name used to pick an install directory#590
silug wants to merge 1 commit into
OpenVoxProject:mainfrom
silug:validate-module-install-dir

Conversation

@silug

@silug silug commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Short description

A module's name is read from its own metadata.json, so for a locally supplied tarball it is entirely under the control of whoever built the tarball. The installer appended the portion after the first dash to the install directory with Pathname#+ and then removed whatever that resolved to, having filtered the name only with tr('/', '-'). Since Pathname#+ resolves ".." lexically and lets an absolute operand replace the base, a name such as "evil-.." resolved to the parent of the install directory, and installing the module deleted the entire module tree before moving the new module into its place.

Route the three sites that derive an install directory from a module name through Puppet::ModuleTool.module_dir_for. It validates the name via Metadata, which already knows what a well-formed namespaced module name looks like and parses the module portion out of it, and then confirms the resulting path really is a direct child of the install directory. The second check is redundant given the first, but it keeps the guarantee next to the path arithmetic it protects rather than in another file.

Metadata's validation is stricter than what these paths accepted before: a name whose module portion contains anything other than letters, digits and underscores is now refused. A module installed under such a name could not be referenced from Puppet code anyway.

Generated by Claude Code

Checklist

I have:

A module's name is read from its own metadata.json, so for a locally
supplied tarball it is entirely under the control of whoever built the
tarball. The installer appended the portion after the first dash to the
install directory with Pathname#+ and then removed whatever that
resolved to, having filtered the name only with tr('/', '-'). Since
Pathname#+ resolves ".." lexically and lets an absolute operand replace
the base, a name such as "evil-.." resolved to the parent of the install
directory, and installing the module deleted the entire module tree
before moving the new module into its place.

Route the three sites that derive an install directory from a module
name through Puppet::ModuleTool.module_dir_for. It validates the name
via Metadata, which already knows what a well-formed namespaced module
name looks like and parses the module portion out of it, and then
confirms the resulting path really is a direct child of the install
directory. The second check is redundant given the first, but it keeps
the guarantee next to the path arithmetic it protects rather than in
another file.

Metadata's validation is stricter than what these paths accepted before:
a name whose module portion contains anything other than letters,
digits and underscores is now refused. A module installed under such a
name could not be referenced from Puppet code anyway.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Steven Pritchard <steven.pritchard@gmail.com>
@binford2k

Copy link
Copy Markdown
Contributor

should we also fix things like

def dashed_name
@data['name'].tr('/', '-') if @data['name']
end
?

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.

2 participants