Skip to content

fix(viewer): escape run data in the trends charts - #742

Open
omkargaikwad23 wants to merge 1 commit into
mainfrom
fix/viewer-chart-untrusted-data
Open

omkargaikwad23 wants to merge 1 commit into
mainfrom
fix/viewer-chart-untrusted-data

Conversation

@omkargaikwad23

@omkargaikwad23 omkargaikwad23 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The trends charts put run data into the page with no escape. Product and dataset names come from the config of each run.

  • generate_d3_chart wrote the data as JSON into a <script> block. json.dumps does not escape </script>, so a name could end the block and start a new script.
  • The tooltip in chart.js used .html(...) with the product name and the run ID, so a name could add an HTML element.

Change

  • generate_d3_chart escapes <, >, and & in the JSON as \uXXXX. JavaScript reads the same string. The chart config uses the same function.
  • The tooltip adds the labels and the values as text nodes.

Tests

  • .ci/verify_viewer.py has a new check: a chart page with </script> in the run data must have 3 script blocks and no raw copy of that data.
  • Browser check with headless Chrome, with a crafted product name. This is a local run. CI does not have a browser test for the tooltip.
Before After
Script from the product name runs Yes No
HTML element from the product name runs in the tooltip Yes No
Chart draws its points with that data No Yes
Tooltip shows the product name as text No Yes

The trends charts put run data into the page with no escape. Product
and dataset names come from the config of each run.

generate_d3_chart wrote the data as JSON into a script block, and
json.dumps does not escape "</script>". The JSON now has "<", ">", and
"&" as \uXXXX, which JavaScript reads as the same string.

The tooltip in chart.js used .html() with the product name and the run
ID. It now adds the labels and the values as text nodes.
@omkargaikwad23
omkargaikwad23 marked this pull request as ready for review November 26, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant