Repository navigation
Constrain icon set paths to bundled files - #186
Merged
Merged
Conversation
Contributor
|
Released in Blockstudio 7.7.9. Thanks for the contribution. |
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.
bs_render_icon()and the/blockstudio/v1/iconsendpoint build the icon set file path fromsetandsubSetwithout checking them. Those values come from the stored attribute of an icon field (rendered throughbs_icon()on every render) and from request parameters. A value such as../../../../wp-content/uploads/xmade the server read another.jsonfile and print its<icon>.svgentry. Exposure is small: it needs an account that can edit a post, and only values stored under*.svgkeys are printed. The path should still not leave the icons folder.This adds
Utils::icon_set_path(), used by both call sites. A name resolves only if it matches[a-z0-9-]+and the file exists inincludes/icons(all 44 bundled files and every value the picker stores fit that). Anything else behaves like a missing set:bs_render_icon()prints nothing, and the REST endpoint returns the existing "Invalid icon set or subset" error. Output and caching of valid icons are unchanged. The change inbs_render_icon()is a single line, so it merges cleanly with #185.Found while working on #185.
Tests:
tests/unit/icons/IconSetPathTest.phpcovers valid sets and sub sets, traversal and absolute paths, other characters, a valid set with an unknown sub set, and the REST callback. The traversal case fails against the previous code (the old code prints the outside file's entry). PHPCS and PHPStan are clean on the changed files.