Skip to content

fix(site): XSS vectors in generated static site #468

Closed

Description

@Sinity

Problem

Three injection vectors in the generated static site:

  1. | safe in conversation page template (site/templates_conversation.py:215): {{ msg.html_content | safe }} strips all defense-in-depth from Jinja2 autoescaping. Same pattern in rendering/templates/conversation.html:376.

  2. innerHTML in search JS (site/search.py:134-143): Search results rendered via JavaScript template literals interpolating doc.title, doc.provider, and doc.preview from the database into innerHTML without sanitization. A conversation title containing </h2><script>alert(1)</script> executes when anyone loads the index page and searches.

  3. Search index JSON (site/models.py:80): The search index file contains full conversation previews for ALL conversations, placed in the static site output and served to any visitor without authentication.

While the user owns their own archive (self-XSS in local context), if the generated static site is published to a web server, these become stored XSS.

Affected code

  • site/templates_conversation.py:215 — {{ msg.html_content | safe }}
  • rendering/templates/conversation.html:376 — {{ msg.html_content | safe }}
  • site/search.py:134-143 — innerHTML with unsanitized ${doc.title}, ${doc.preview}
  • site/models.py:80 — search index contains full previews for all conversations

Fix direction

  • Replace | safe with proper HTML sanitization (e.g., bleach or markupsafe escape + selective unescape)
  • Escape conversation titles/previews in the search JS using textContent or a JS-side escape function
  • Consider truncating or omitting previews from the public search index
  • Add a CSP header to the generated site as defense-in-depth

Discovered during adversarial audit 2026-04-26.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions