security: replace create_function(); add path traversal guard in render()#38
Open
se7enxweb wants to merge 1 commit intozetacomponents:masterfrom
Open
Conversation
…er() svg.php — create_function() removed (PHP 8.0+): preg_replace_callback() callback converted from deprecated create_function() to a proper anonymous function (closure). create_function() uses eval() internally and was removed in PHP 8.0. svg.php render($file) + gd.php render($file) — path traversal: Added null-byte check + realpath(dirname($file)) validation before writing the output file. The destination directory must exist and must be reachable without '..' traversal escape. The final write path is reconstructed from the resolved directory + basename() to prevent any remaining traversal. Before: dom->save($file) / imagepng($image, $file) called with an unvalidated caller-controlled path — an attacker could pass '../../../../var/www/evil.php' and write arbitrary content. Reported-by: CJW Network security audit 2026-03-01 Security-fixes: RCE via create_function (CWE-94), path-traversal (CWE-22)
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.
Reported-by: CJW Network security audit 2026-03-01
Changes
src/driver/svg.php—create_function()removed (PHP 8.0+)The
preg_replace_callback()callback usedcreate_function(), which was deprecated in PHP 7.2 and removed in PHP 8.0. It useseval()internally and is an RCE vector. Replaced with a proper anonymous function (closure).src/driver/svg.php+src/driver/gd.php— path traversal inrender($file)The
render()method wrote the output image to a caller-supplied$filepath without any validation. An attacker passing../../../../var/www/evil.phpcould write arbitrary content outside the intended directory.Fix applied to both drivers:
realpath(dirname($file))— destination directory must exist and must resolve without escaping.$resolvedDir . DIRECTORY_SEPARATOR . basename($file).Security fixes
create_function()/eval()(CWE-94)