fix(renderer): disable executable !!js/function by default in YAML renderer - #5827
Open
jabrailkhalil wants to merge 1 commit into
Open
jabrailkhalil wants to merge 1 commit into
jabrailkhalil wants to merge 1 commit into
Conversation
…nderer Fixes hexojs#5801 Signed-off-by: jabrailkhalil <jabrailkhalil@gmail.com>
How to testgit clone -b fix/yaml-js-function https://github.com/jabrailkhalil/hexo.git
cd hexo
npm install
npm test |
Author
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.
Summary
The YAML renderer previously extended
yaml.DEFAULT_SCHEMAwithjs-yaml-js-types.all, which enables the executable!!js/functiontag. Anysource/_data/*.ymlfile (or config/theme data) could then define a real JavaScript function that gets invoked when the data is rendered, allowing arbitrary Node.js code to run in the Hexo process.With this change only the safe JS types are enabled:
!!js/regexpand!!js/undefined. The executable!!js/functiontag is no longer accepted and now throws a YAML parsing error instead of constructing a function. The#4917workaround (catch around schema creation) is preserved.Tests
Added three tests to
test/scripts/renderers/yaml.ts:!!js/regexpstill parses into aRegExpwith the right source/flags.!!js/undefinedstill parses intoundefined.!!js/functionis rejected (throws).Verification
npm test -- --grep yaml- 7/7 passing (including the 3 new tests)npm run eslint- cleannpm run build(tsc -b) - cleannpm test: 1294 passing, 5 pending, 1 failingThe single failing test is pre-existing and unrelated to this change:
test/scripts/console/generate.ts-> "generate - future posts -> reprocesses future posts after publish date passes" fails on this machine (Windows 10, Node v22.21.1) with "expected [ _Document{...(21)} ] to have a length of +0 but got 1". It also fails on a pristine checkout ofmasterwithout this change, including when run in isolation via--grep. The sinon fake-timer clock (fakeDatearound year 2098) does not appear to take effect in this environment.Fixes #5801