Skip to content

'sanitize_label' double-encodes HTML entities in 'to_html' JSON output #66

Description

@flexmox

Bug

sanitize_label() in security.py calls html.escape() on all node labels and community names. These sanitized strings are then passed through json.dumps() and embedded inside a <script> tag in to_html().

This causes double-encoding: & becomes &amp; in the JSON string values, which vis.js then renders literally as &amp; in the browser instead of &.

Reproduction

Any node label containing & (e.g. "Abercrombie & Fitch", "CX & Behavioral Data") will display as Abercrombie &amp; Fitch in the interactive graph.

Root cause

security.py:198html.escape() is appropriate for text injected into raw HTML, but the labels in to_html() are embedded inside json.dumps() within a <script> block (export.py:370-372). JavaScript string literals don't need HTML-escaping — json.dumps already handles the necessary escaping for that context.

Note:

I found this issue myself but I had Claude Opus 4.6 write it up

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions