[5.4] Fix path traversal in com_templates file operations#47851
Open
ManhThuan wants to merge 1 commit into
Open
[5.4] Fix path traversal in com_templates file operations#47851ManhThuan wants to merge 1 commit into
ManhThuan wants to merge 1 commit into
Conversation
Add Path::check() validation to file operation methods in TemplateModel that were missing it, consistent with getSource() which already uses it. Affected methods: save(), deleteFile(), renameFile(), cropImage(), resizeImage() all accepted a base64-encoded file parameter without validating the decoded path stays within the template directory, allowing directory traversal via sequences such as /../../../ to read, write, rename or delete files anywhere under JPATH_ROOT.
Contributor
|
If you have access to the template manager (restricted to super users) then you really can do anything you want |
Contributor
|
Thank you for your contribution, but please stop submitting AI PR proposals. See the AI policy you checked and hopefully read before. We're looking for thoughtful contributions. See this as a first warning. |
Member
|
In general it is not a bad idea to restrict the template manager to edit files only in its own directory. |
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.
Add Path::check() validation to file operation methods in TemplateModel
that were missing it, consistent with getSource() which already uses it.
Affected methods: save(), deleteFile(), renameFile(), cropImage(), resizeImage()
all accepted a base64-encoded file parameter without validating the decoded
path stays within the template directory, allowing directory traversal via
sequences such as /../../../ to read, write, rename or delete files anywhere
under JPATH_ROOT.
and my contribution is either not created with the help of AI or is
compatible with the policy and GNU/GPL 2 or later.
Summary of Changes
Path::check()validation has been added to five file operation methods inTemplateModelthat were missing it.Path::clean()alone only normalisespath separators; it does not prevent
../directory traversal.Path::check()resolves the path and verifies it stays within
JPATH_ROOT, throwing anexception on traversal attempts.
Methods patched:
save(),deleteFile(),renameFile(),cropImage(),resizeImage(). The fix follows the pattern already used bygetSource()inthe same class (line 945).
Testing Instructions
(e.g. Cassiopeia): System → Site Templates → Cassiopeia → Edit.
fileparameter (base64-encoded).base64_encode("/../../../configuration.php").Before patch: the operation proceeds on
configuration.phpoutside thetemplate directory.
After patch: Joomla displays an error message and refuses the operation.
Actual result BEFORE applying this Pull Request
File operations (
save,deleteFile,renameFile,cropImage,resizeImage)in the template editor accept a base64-encoded path parameter that is decoded
and used without traversal validation. A
/../sequence in the decoded valueallows the operation to target any file under
JPATH_ROOT, includingconfiguration.phpand files inlibraries/,plugins/, etc.Expected result AFTER applying this Pull Request
All five file operation methods reject paths containing
../sequences with anerror message, confining template file operations to the template directory.
Behaviour is now consistent with
getSource(), which already appliedPath::check().Link to documentations