Skip to content

Document lack of sanitization of HTML output #1479

Closed

Description

@MaddyGuthridge

Like many other Markdown processors, Python-Markdown does not sanitize its output, meaning that malicious code can be embedded within markdown documents.

# Some markdown document

<script>alert("Evil laughter")</script>

If this isn't made clear to users, there is a risk that they will unintentionally create opportunities for XSS attacks. It would be worthwhile documenting the lack of sanitization, and perhaps recommend an HTML sanitization library, such as bleach.

Activity

  1. waylan commented on Sep 10, 2024

    @waylan
    Member

    Hmm, this used to me mentioned in our documentation. Not sure when or why it was removed. But, yes, I agree, we should be documenting this. Although, an argument has been made by some in the past that as all markdown parsers do not sanitize, there is no need to document this as there should be no expectation from users anyway. Personally, I recognize that not all users know or understand that and so we should be expressly stating as much.

    By the way, we used to recommend bleach as a solution. We stopped making that recommendation as the bleach project has been deprecated. That still appears to be the case.

  2. added
    docs
    confirmed
    on Oct 1, 2024
  3. waylan commented on Apr 26, 2025

    @waylan
    Member

    nh3 is great, but as it consists of bindings to a Rust package, that means it is not a pure Python package and not universally installable---and that gives me pause. I should also mention that we actually used to recommend yourcelf/bleach-allowlist, which is a set of config options for Bleach which makes sense for HTML generated from Markdown. A similar package for nh3 might be more useful to users that the raw package. 🤷‍♂

  4. added a commit that references this issue on Feb 6, 2026
    6301833
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmeddocs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions