Repository navigation
fix: sanitize and escape motion type names from G-code - #31
Merged
Merged
Conversation
Feature names read from ;TYPE:, ; FEATURE: and FibreSeeker "start" headers flowed unsanitized into innerHTML and inline handlers (DOM injection via a crafted G-code file). - parser: fold free-form type names to a safe token (A-Z 0-9 _ space . / -) - parser: use Object.hasOwn for type-map lookups; require ';' for FibreSeeker headers; replace quadratic regex; track inset state in a local - ui/stats-overlay: add escapeHtml; pass types to handlers via data-type - tests: 16 new cases covering hostile payloads, prototype keys, insets Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Owner
Author
|
Fixing some sanitization issues. |
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
Feature names read from
;TYPE:,; FEATURE:and FibreSeeker; X startheaders flowed unsanitized intoinnerHTMLand inlineonchangehandlers, so a crafted G-code file could inject markup/script into the page. This was a pre-existing pattern (Cura/S3D fallbacks); #30 added a third source. Follow-up to the review of #30.Changes
A-Z 0-9 _ space . / -, max 40 chars, fallbackCUSTOM). Known mapped names are unchanged.Object.hasOwnfor type-map lookups (; constructor start/; __proto__ startare plain text); FibreSeeker header match requires a leading;and no longer uses a quadratic regex; inset state is a local instead of a field on the layer object.escapeHtml; motion legend and pressure-advance table pass types to handlers viadata-type/this.dataset.typeinstead of building JS strings; hover tooltip escapes the type.test/parser-type-sanitization.test.js(hostile payloads on;TYPE:and FibreSeeker paths, prototype keys, non-comment lines ending in "start", inset outer/inner logic, slash preservation).Testing
node --test test/*.test.js: 365/365 pass (349 existing + 16 new). The new hostile-payload tests failed before the parser fix.node build.jsre-run; bundle committed and its script parses.Known limitation
A name made up entirely of non-ASCII characters (e.g. a localized feature name) collapses to
CUSTOM, so such features share one type.🤖 Generated with Claude Code