mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-19 02:19:37 +00:00
This commit is contained in:
1 parent
3d53287ff6
commit
92b70ce5f4
7 files changed
+49
-14
No files matched your search
@@ -186,13 +186,12 @@ _MAX_LABEL_LEN = 256
|
||||
|
||||
|
||||
def sanitize_label(text: str) -> str:
|
||||
"""Strip control characters, cap length, then HTML-escape.
|
||||
"""Strip control characters and cap length.
|
||||
|
||||
Applied to all node labels and edge titles before they are embedded
|
||||
in pyvis HTML output or returned via the MCP server, preventing both
|
||||
XSS and broken visualisations from malformed source identifiers.
|
||||
Safe for embedding in JSON data (inside <script> tags) and plain text.
|
||||
For direct HTML injection, wrap the result with html.escape().
|
||||
"""
|
||||
text = _CONTROL_CHAR_RE.sub("", text)
|
||||
if len(text) > _MAX_LABEL_LEN:
|
||||
text = text[:_MAX_LABEL_LEN]
|
||||
return html.escape(text)
|
||||
return text
|
||||
Reference in new issue
Block a user