Skip to content

Escape strings in VectorGrid, TimestampedGeoJson and FloatImage - #2363

Open
KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:escape-plugin-strings
Open

KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:escape-plugin-strings

Conversation

@KhadeerBasha1232

Copy link
Copy Markdown
Contributor

Escape strings in VectorGrid, TimestampedGeoJson and FloatImage

Three plugins put user-supplied strings into their templates without escaping. A quote in the value ends the surrounding string and breaks the map, or in the FloatImage case adds new HTML attributes. This is the same kind of problem as #2357 (Search).

Plugin Value Before After
VectorGridProtobuf url with ', e.g. ...?name=O'Neil placed in '...'; JS syntax error, the layer is never created quoted as JSON; the layer gets the URL unchanged
TimestampedGeoJson date_options with " placed in "..."; JS syntax error, the time control never appears quoted as JSON; the format string reaches moment.js unchanged
FloatImage image with " placed in src="..." as-is; the rest becomes new attributes on the <img>, so x.png" onerror="..." runs code HTML-escaped; the whole value stays in src

The FloatImage case matters when the image URL comes from data or user input.

Change

  • vectorgrid_protobuf.py: '{{ this.url }}' → {{ this.url|tojson }}
  • timestamped_geo_json.py: "{{this.date_options}}" → {{ this.date_options|tojson }}
  • float_image.py: src="{{ this.image }}" → src="{{ this.image|e }}"

Values without quotes or & render exactly as before. In FloatImage a & in a URL becomes &amp;, which is the correct form inside an HTML attribute and gives the browser the same URL.

Tests

  • test_vectorgrid_url_with_quote
  • test_timestamped_geo_json_date_options_with_quotes
  • test_float_image_escapes_src
  • I updated the template copy in test_timestamped_geo_json to match.

The new tests fail without the change. I also opened the generated maps in a browser before and after the change, with the values from the table. Before, the VectorGrid layer and the time control were missing, and the onerror handler in the FloatImage page ran. After, all three maps work and nothing extra runs.

Three plugins put user-supplied strings into their templates without
escaping:

- VectorGridProtobuf put `url` inside single quotes, so a URL with an
  apostrophe ended the JS string and the layer was never created.
- TimestampedGeoJson put `date_options` inside double quotes, so a
  format with a double quote broke the script and no time control
  appeared.
- FloatImage put `image` into the img src attribute as-is, so a double
  quote ended the attribute and the rest was parsed as new HTML
  attributes, such as an onerror handler that runs code.

Use tojson for the two JS strings and HTML-escape the src attribute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
pypi — 91047880 Deployed Nov 19, 2026 by KhadeerBasha1232 via packages #2118
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