Skip to content

Constrain icon set paths to bundled files - #186

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:fix/icon-set-path
Oct 26, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:fix/icon-set-path

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

bs_render_icon() and the /blockstudio/v1/icons endpoint build the icon set file path from set and subSet without checking them. Those values come from the stored attribute of an icon field (rendered through bs_icon() on every render) and from request parameters. A value such as ../../../../wp-content/uploads/x made the server read another .json file and print its <icon>.svg entry. Exposure is small: it needs an account that can edit a post, and only values stored under *.svg keys 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 in includes/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 in bs_render_icon() is a single line, so it merges cleanly with #185.

Found while working on #185.

Tests: tests/unit/icons/IconSetPathTest.php covers 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.

@dnnsjsk
dnnsjsk merged commit e35754a into inline0:main Oct 26, 2026
@dnnsjsk

dnnsjsk commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Released in Blockstudio 7.7.9. Thanks for the contribution.

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.

2 participants