Skip to content

fix: validate hex colours in hexColor() to prevent XML injection#115

Merged
simongdavies merged 2 commits intohyperlight-dev:mainfrom
simongdavies:fix-hexcolor-validation
May 7, 2026
Merged

fix: validate hex colours in hexColor() to prevent XML injection#115
simongdavies merged 2 commits intohyperlight-dev:mainfrom
simongdavies:fix-hexcolor-validation

Conversation

@simongdavies
Copy link
Copy Markdown
Member

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.

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>
Copilot AI review requested due to automatic review settings May 7, 2026 19:05
@simongdavies simongdavies added the bug Something isn't working label May 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-core type docs to reflect the new validation/throw behavior.
  • Updated doc-core.json hashes 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.

Comment thread builtin-modules/src/doc-core.ts
Comment thread builtin-modules/src/doc-core.ts Outdated
Comment thread builtin-modules/src/doc-core.ts Outdated
Comment thread builtin-modules/src/doc-core.ts
…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 simongdavies merged commit ac576c0 into hyperlight-dev:main May 7, 2026
12 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants