Ensure configuration files are always written within ${karaf.etc} - #2867
Open
jbonofre wants to merge 1 commit into
Open
Ensure configuration files are always written within ${karaf.etc}#2867jbonofre wants to merge 1 commit into
jbonofre wants to merge 1 commit into
Conversation
ConfigRepositoryImpl derived the target file from caller-supplied input
(the felix.fileinstall.filename property and the PID / factory alias used
to build the file name) without checking that the result stayed inside
${karaf.etc}. Add a canonical-path containment check, shared through a new
org.apache.karaf.util.PathUtils helper, and reuse it in
ConfigMBeanImpl.install() and the config:install command in place of the
weaker finalname.contains("..") string check.
jbonofre
force-pushed
the
config-etc-path-containment
branch
2 times, most recently
from
September 8, 2026 17:47
83d9181 to
d138329
Compare
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.
Motivation
ConfigRepositoryImplbuilds the file it persists a configuration to from caller-supplied input and never checks that the result stays inside${karaf.etc}:felix.fileinstall.filenameentry in the property map is turned into aFileas-is (getCfgFileFromProperty), so it can point anywhere;generateConfigFilename,createFactoryConfiguration), so a name containing..segments resolves outside the folder.These paths are reachable from the
configMBean and theconfig:*shell commands.ConfigMBeanImpl.install()and theconfig:installcommand already tried to guard against this, but only with afinalname.contains("..")string test, which does not cover absolute paths or symlinks.Changes
org.apache.karaf.util.PathUtilswithisWithin(parent, child)/checkWithin(parent, child), doing an element-wisestartsWithcomparison on canonical paths.ConfigRepositoryImpl.update()andcreateFactoryConfiguration()now verify the target file is inside${karaf.etc}before writing. The branch that reuses an already-persistedfelix.fileinstall.filenamecoming from Configuration Admin is left untouched so multi-directory Felix FileInstall setups keep working.ConfigMBeanImpl.install()andInstallCommand(config:install) usePathUtils.checkWithin(...)instead of thecontains("..")check.PathUtilsTest,ConfigRepositoryImplContainmentTest.ConfigMBeanImplTest.testInstallWithNonAuthorizePathnow expectsMBeanException(the rejection is raised inside the method's existingtry).