Skip to content

rustdoc: parenthetical after attribute syntax breaks HTML #14814

Closed
@kmcallister

Description

@kmcallister
/// Declare with
/// #[foo] (my favorite attribute)
#[foo]
pub fn main() { }

produces

<pre class='rust fn'>pub fn main()</pre><div class='docblock'><p>Declare with</p>

<h1 id="<a-href="my%20favorite%20attribute">foo</a>" class='section-header'><a
                           href="#<a-href="my%20favorite%20attribute">foo</a>"><a href="my%20favorite%20attribute">foo</a></a></h1>

because it parses as a Markdown link. The right thing to do is put backtics around the attribute syntax, but this is still a really confusing failure.

It would also be an XSS vulnerability if we hosted docs generated from user contributed libraries:

/// Declare with
/// #[foo] (my favorite attribute) <script>alert(document.cookie)</script>

But the conservative solution there is to put user content on another origin (e.g. rust-user-content.org) which doesn't hold any credentials.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions