Skip to content

security: replace eval() with json_encode/decode in ezcCacheStorageFileEvalArray#5

Open
se7enxweb wants to merge 1 commit intozetacomponents:masterfrom
se7enxweb:security/fix-eval-cache
Open

security: replace eval() with json_encode/decode in ezcCacheStorageFileEvalArray#5
se7enxweb wants to merge 1 commit intozetacomponents:masterfrom
se7enxweb:security/fix-eval-cache

Conversation

@se7enxweb
Copy link
Copy Markdown

Reported-by: CJW Network security audit 2026-03-01

Problem

ezcCacheStorageFileEvalArray::fetchData() used eval(file_get_contents($filename)). If an attacker can write to the cache directory (e.g. via a separate path traversal or file upload vulnerability), they can achieve Remote Code Execution by placing malicious PHP in a cache file.

Changes

src/storage/file/eval_array.php

  • fetchData(): eval()json_decode(). Throws ezcCacheInvalidDataException on parse failure.
  • prepareData(): var_export()+PHP suffix → json_encode() with JSON_UNESCAPED_UNICODE. Throws on encode failure.
  • Class docblock updated to reflect JSON storage format.

BC note

Existing cache files written in the old return <php>;?> format are not compatible. Clear the cache directory when deploying.

Security fixes

  • RCE via eval() (CWE-94)

…ageFileEvalArray

eval() on file contents is a direct RCE vector if an attacker can write
to the cache directory. JSON carries no code execution risk.

fetchData(): use json_decode(); throw ezcCacheInvalidDataException on
parse failure instead of silently returning null.

prepareData(): use json_encode() with JSON_UNESCAPED_UNICODE; throw on
encode failure.

BC note: existing cache files written by the old eval()-based format
("return <php_value>;\n?>\n") are not compatible with JSON decoding.
Clear the cache directory when deploying this change.

Reported-by: CJW Network security audit 2026-03-01
Security-fixes: RCE via eval() (CWE-94)
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.

1 participant