Skip to content

[stable] Destabilize the Error::type_id function#10

Closed
c4rtune wants to merge 1 commit intomainfrom
pull/60785
Closed

[stable] Destabilize the Error::type_id function#10
c4rtune wants to merge 1 commit intomainfrom
pull/60785

Conversation

@c4rtune
Copy link
Copy Markdown
Owner

@c4rtune c4rtune commented Apr 22, 2026

This commit destabilizes the Error::type_id function in the standard library.
This does so by effectively reverting #58048, restoring the #[unstable]
attribute. The security mailing list has recently been notified of a
vulnerability relating to the stabilization of this function. First stabilized
in Rust 1.34.0, a stable function here allows users to implement a custom
return value for this function:

struct MyType;

impl Error for MyType {
fn type_id(&self) -> TypeId {
    // Enable safe casting to `String` by accident.
    TypeId::of::<String>()
}
}

This, when combined with the Error::downcast family of functions, allows
safely casting a type to any other type, clearly a memory safety issue! A
formal announcement has been made to the security mailing list as well as the blog

This commit simply destabilizes the Error::type_id which, although breaking
for users since Rust 1.34.0, is hoped to have little impact and has been deemed
sufficient to mitigate this issue for the stable channel. The long-term fate of
the Error::type_id API will be discussed at #60784.

@MonnetalX
Copy link
Copy Markdown

🔍 PR Link Analysis

🔗 Ranked Links

#1 the blog

🔍 The webpage content is not accessible, but the pull request context indicates that the Error::type_id function is being destabilized due to a security vulnerability related to allowing custom return values.

#2 #58048

🔍 This commit destabilizes the Error::type_id function due to a security vulnerability that allows users to implement a custom return value for the function, enabling type confusion attacks.

#3 #60784

🔍 The security vulnerability arises because stabilizing Error::type_id allows user-defined types to return arbitrary TypeId values, enabling type confusion attacks by bypassing the compiler's type safety guarantees.

#4 security mailing list

🔍 The Error::type_id function is being destabilized because its stable implementation allows users to return arbitrary TypeId values, enabling type confusion vulnerabilities.

@c4rtune c4rtune closed this Apr 23, 2026
@c4rtune c4rtune deleted the pull/60785 branch April 23, 2026 05:48
@c4rtune c4rtune restored the pull/60785 branch April 23, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants