GeezerVison is showing github.com — fix: Preserve XML structural entities during decode by camdecoster · Pull Request #7838 · plotly/plotly.js
Conversation
camdecoster
commented
Jun 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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:" onmouseover="alert(1)" a="">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 " / " / " 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:
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
1 more reviewer
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
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.
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.
|