Validate the module name used to pick an install directory - #590
Open
silug wants to merge 1 commit into
Open
Conversation
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>
Contributor
|
should we also fix things like openvox/lib/puppet/module_tool/metadata.rb Lines 35 to 37 in 79dd6c0 |
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.
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 withPathname#+and then removed whatever that resolved to, having filtered the name only withtr('/', '-'). SincePathname#+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 viaMetadata, 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:
Signed-off-byannotation to each of my commitsGenerated-byorAssisted-byannotations to each of my commits created with the help of an AI agent