Skip to content

D bindings interpolate WIT documentation as executable D source #1789

Open

Description

@Eh2406

Hi,

I am the Co-Lead of the Cargo Team and was recently hired by the Rust Foundation to help triage AI discovered bugs. This bug was found with AI, namely scrutineer and fable. Except where specifically labeled this report was written by me. @alexcrichton asked me to file this one as an issue so that it doesn't get lost.

AI text:

Summary

Code injection in generated D bindings through WIT documentation. The D backend inserts WIT documentation directly into /++ ... +/ comments; a malicious WIT supplier can include +/ to terminate the comment, inject D declarations or compiler directives, and use /+ to balance the generated closing delimiter. The record formatter at crates/d/src/lib.rs:1746–1749 demonstrates the issue, with the same raw-documentation convention used for other generated documentation.

Proof of concept

input.wit:

package audit:injection;
interface payload {
    /// +/ pragma(msg, "WIT_DOC_CODE_EXECUTED"); /+
    record value { x: u32 }
}
world victim { import payload; }

Activity

  1. alexcrichton commented on Nov 13, 2026

    @alexcrichton
    Member
  2. QuantumSegfault commented on Nov 13, 2026

    @QuantumSegfault
    Contributor

    Ah, that's a good point.

    I've been contemplating just switching to /// single-line doc-comments anyway. Always shorter by two lines, doesn't look too bad. And not any more difficult to edit/maintain since it's all code-genned anyway.

    Would solve this issue since /// is a one way trip.

    I'll touch this up...probably tonight.

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

    gen-dRelated do the D code generator

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions