Skip to content

Ensure that importer names are sanitized before making REST requests. - #632

Merged
imantsk merged 5 commits into
corefrom
fix/rest-issue/core
Nov 24, 2026
Merged

imantsk merged 5 commits into
corefrom
fix/rest-issue/core

Conversation

@sheabunge

Copy link
Copy Markdown
Member

No description provided.

@TallblokeUK TallblokeUK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on a site with Header Footer Code Manager installed:

  • Opening the import page with ?from= set to a value containing path segments or other characters keeps both requests (loading the importer's snippets, and the import itself) under /code-snippets/v1/import/plugins/.
  • The three built-in importer names are unchanged by sanitizeImporterName(), so their request URLs are identical to before. An uppercase ?from= value still selects the right importer.
  • Choosing an importer from the dropdown, and arriving with a valid ?from=, both load the snippet list. Importing a selected snippet succeeds.
  • ESLint and the build pass. tsc reports no new errors.

Non-blocking suggestions:

  • A small Playwright check that a ?from= containing path segments keeps requests under the importer route would guard against this coming back.
  • The GET in WithMigrationData.tsx (line 133) builds its URL from selectedImporter without encodeURIComponent(). That's safe as it stands, because the value is already sanitised; encoding it would match the import request.

Separate from this PR: opening the import page with ?from= set to an importer whose plugin isn't active returns a 500 from /import/plugins/{name}, because the importer expects the plugin's classes to be loaded.

@lightbulbman

lightbulbman commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Code looks good and is okay to merge. It closes the path traversal via ?from=.

Agree with Tallbloke's review and suggestions (encoding the GET, adding a Playwright check, and handling the inactive-plugin 500 in a separate PR).

One small suggestion to consider - not urgent but we may want to sanitise setSelectedImporter as well, so every write to that state goes through sanitizeImporterName(), not just the query-param read, but its not a biggie so can be done later to not be a blocker

@lightbulbman lightbulbman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comments

@sheabunge

Copy link
Copy Markdown
Member Author

Appreciate the feedback!

@imantsk imantsk added the run-tests Trigger automated tests label Nov 24, 2026
@imantsk
imantsk merged commit e4e32d1 into core Nov 24, 2026
10 of 12 checks passed
@imantsk
imantsk deleted the fix/rest-issue/core branch November 24, 2026 23:32
@imantsk imantsk mentioned this pull request Nov 24, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-tests Trigger automated tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants