Repository navigation
Escape embedded JSON in TimestampedGeoJson, Vega and VegaLite - #2364
Open
KhadeerBasha1232 wants to merge 1 commit into
Open
KhadeerBasha1232 wants to merge 1 commit into
KhadeerBasha1232 wants to merge 1 commit into
Conversation
These three put their data into the map's script block with plain json.dumps (or the raw file contents), which doesn't escape "<". A string value containing "</script>" ended the script block early, and whatever followed was parsed as new HTML, so a value from the data could run its own script and the map was never drawn. Serialize the data with _to_escaped_json, the helper tojavascript already uses, so <, >, & and ' inside strings are written as \u escapes. File contents for TimestampedGeoJson are now parsed as JSON first, with a leading UTF-8 BOM stripped. A str is still passed through as-is, as documented. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KhadeerBasha1232
temporarily deployed
to
pypi
November 20, 2026 03:19 — with
GitHub Actions
Inactive
This branch was previously deployed
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.
Escape embedded JSON in TimestampedGeoJson, Vega and VegaLite
TimestampedGeoJson,VegaandVegaLiteput their data into the map's<script>block with plainjson.dumps.json.dumpsdoesn't escape<, so a string value containing</script>ends the script block early. Whatever follows is then parsed as new HTML, so a value in the data can run its own script, and the map itself is never drawn.The same happens with a Vega or Vega-Lite spec whose data contains such a value, for example a chart built from a DataFrame. This matters when the data comes from outside, such as a scraped dataset or user uploads.
GeoJson,TopoJson,HeatMap,Timelineand the other plugins already avoid this by rendering data withtojson/tojavascript, which escape<,>,&and'. These three were missed.Before / after
The value in the data is
</script><script>...</script>, where the script adds a red "Injected script ran" banner to the page.TimestampedGeoJsonVegaLitein a popupChange
TimestampedGeoJson: dict and file data are serialized with_to_escaped_json(the helpertojavascriptalready uses) instead ofjson.dumps/ the raw file contents. File contents are now parsed withjson.loadsfirst, with a leading UTF-8 BOM stripped. Astris still passed through as-is, as documented.VegaandVegaLite:self.jsonuses_to_escaped_jsoninstead ofjson.dumps.The escaped output is still valid JSON and parses to the same value, so maps render the same. Only
<,>,&and'inside strings are written as Unicode escapes, for example\u003cfor<.One difference: a
TimestampedGeoJsonfile that isn't valid JSON now raises when the plugin is created, instead of producing a broken map.Tests
test_timestamped_geo_json_escapes_script_tagstest_timestamped_geo_json_from_file_escapes_script_tags(UTF-8 and UTF-8 with BOM)test_vegalite_escapes_script_tagstest_vega_escapes_script_tagsThe new tests fail without the change.