fix: validate hex colours in hexColor() to prevent XML injection#115
Merged
simongdavies merged 2 commits intohyperlight-dev:mainfrom May 7, 2026
Merged
Conversation
hexColor() previously did no validation — just stripped '#' and
uppercased. If a non-hex string (like gradient XML) was passed, it
was silently embedded as an srgbClr val attribute, producing corrupt
OOXML that PowerPoint would repair by stripping entire slides.
Bug reproduction: LLM passes gradient XML or background XML as a
'color' parameter → hexColor uppercases it → solidFill embeds it as
<a:srgbClr val='<P:BG>...'/> → PowerPoint repair strips the slide.
Fix: hexColor() now validates input against /^#?[0-9A-Fa-f]{6}$/
and throws a descriptive error on invalid input, matching the same
regex used by requireHex(). Error message truncates long strings to
avoid dumping XML fragments into the console.
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the ha:doc-core builtin module by validating hex colour inputs in hexColor() to prevent malformed OOXML (and potential XML injection via attribute values) when non-hex strings are passed.
Changes:
- Added runtime validation to
hexColor()and throws a descriptive error on invalid 6-char hex inputs. - Updated the
ha:doc-coretype docs to reflect the new validation/throw behavior. - Updated
doc-core.jsonhashes to match the modified source/types output.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| builtin-modules/src/doc-core.ts | Adds validation + error message behavior to hexColor() to block non-hex strings from being embedded into OOXML. |
| builtin-modules/src/types/ha-modules.d.ts | Updates the exported docs for hexColor() in the generated ha:* module typings. |
| builtin-modules/doc-core.json | Refreshes module metadata hashes after the doc-core source/types change. |
…tion
- Remove stale JSDoc ('lenient', 'does NOT throw') — now accurate
- Safely render non-string values in error message using typeof
instead of interpolating directly (prevents Symbol/object issues)
- Reuse shared HEX_RE constant (moved above hexColor, removed dupe)
- Add 8 unit tests: XML fragments, named colours, 3-char shorthand,
rgb() notation, empty string, long string truncation, non-string input
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
simongdavies
added a commit
that referenced
this pull request
May 7, 2026
* docs: update CHANGELOG.md for v0.2.1 through v0.5.0 Added missing entries for 7 releases (v0.2.1, v0.2.2, v0.2.3, v0.3.0, v0.4.0, v0.4.1, v0.4.2) and prepared v0.5.0 section with all changes since v0.4.2. Key additions documented: - PDF support, MCP integration, K8s deployment (v0.2.1) - Excel XLSX module, M365 MCP (v0.3.0) - Configurable plugin limits, skill clarifying questions (v0.5.0) - Cost estimation, actionable error messages (v0.5.0) - PPTX shape ID fix, native module validation fix (v0.5.0) Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> * docs: add hexColor XML injection fix to v0.5.0 changelog (#115) Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> --------- Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
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.
hexColor() previously did no validation — just stripped '#' and uppercased. If a non-hex string (like gradient XML) was passed, it was silently embedded as an srgbClr val attribute, producing corrupt OOXML that PowerPoint would repair by stripping entire slides.
Bug reproduction: LLM passes gradient XML or background XML as a 'color' parameter → hexColor uppercases it → solidFill embeds it as <a:srgbClr val='<P:BG>...'/> → PowerPoint repair strips the slide.
Fix: hexColor() now validates input against /^#?[0-9A-Fa-f]{6}$/ and throws a descriptive error on invalid input, matching the same regex used by requireHex(). Error message truncates long strings to avoid dumping XML fragments into the console.