GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: Preserve XML structural entities during decode by camdecoster · Pull Request #7838 · plotly/plotly.js

Conversation

@camdecoster

@camdecoster camdecoster commented Jun 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Description

Preserve XML structural entities during decode when exporting SVG.

Changes

  • Update htmlEntityDecode to preserve the five XML structural entities (&, ", ', <, >) in named, decimal, and hex numeric forms instead of decoding them
  • Add tests to check if entities are preserved decoding

Testing

  • Be on master
  • Open Plotly devtools
  • In browser devtools, enter the following in the console:
    const fig = {
      data: [{ x: [1], y: [1], type: "scatter" }],
      layout: {
        annotations: [
          {
            x: 1,
            y: 1,
            showarrow: false,
            text: '<span style="x:&#34; onmouseover=&#34;alert(1)&#34; a=&#34;">Zoidberg</span>',
          },
        ],
      },
    };
    
    Plotly.newPlot(gd, fig)
      .then(() =>
        Plotly.toImage(gd, {
          format: "svg",
          imageDataOnly: true,
        }),
      )
      .then((svg) => console.log(decodeURIComponent(svg)));
  • Toward the end of the log statement, note that onmouseover has been injected into the SVG as an attribute
  • Switch to this branch
  • Go through the same process
  • Toward the end of the log statement, note that onmouseover is only part of the style attribute

Notes

  • Attack path. htmlEntityDecode in tosvg.js ran after XMLSerializer.serializeToString and decoded &quot; / &#34; / &#x22; back to literal " chars in attribute values the serializer had safely escaped, letting the payload break out of style="..." and inject arbitrary attributes (onmouseover=, onclick=, …).
  • Affected callers. Plotly.toImage, Plotly.downloadImage, and downstream products that embed user-authored figure SVG into a privileged origin (shared-plot previews, dashboards, exported-image galleries).
  • Non-browser SVG renderers. htmlEntityDecode exists partly so exported SVG renders correctly in Batik / Illustrator / kaleido (for PDF/EPS). The fix preserves five more entities in the output; SVG is still valid XML.
  • References:
    • XML 1.0 §4.6 – Predefined Entities
    • WHATWG DOM-Parsing – XMLSerializer

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
camdecoster added 3 commits June 10, 2026 16:28
@camdecoster
Linting/formatting
058da08
@camdecoster
fix: Preserve XML structural entities during decode
6dfed31
@camdecoster
Add tests
47763c2
@camdecoster
camdecoster marked this pull request as ready for review June 11, 2026 21:45
emilykl
emilykl previously approved these changes Jun 15, 2026
View reviewed changes

@emilykl emilykl left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good to me, thanks @camdecoster 🚀 Can you add a draftlog?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@camdecoster
Add draftlog
67cd1de
@camdecoster
camdecoster dismissed emilykl’s stale review via 67cd1de June 16, 2026 20:21
emilykl
emilykl approved these changes Jun 16, 2026
View reviewed changes
@camdecoster
camdecoster merged commit 1a7dcfd into master Jun 16, 2026
83 of 84 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@camdecoster
camdecoster deleted the cam/avoid-decoding-unsafe-characters-tosvg branch June 16, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@emilykl emilykl emilykl approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@camdecoster @emilykl
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.