Skip to content

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

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

[stable] Destabilize the Error::type_id function#8
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 linked page is a redirect and does not contain substantive content relevant to the pull request.

#2 #58048

🔍 The Error::type_id function is being destabilized due to a security vulnerability that arises from allowing users to implement custom return values for this function, which was first stabilized in Rust 1.34.0.

#3 #60784

🔍 The Error::type_id function is being destabilized due to a security vulnerability that allows users to return arbitrary TypeId values, enabling type confusion attacks.

#4 security mailing list

🔍 The Error::type_id function is being destabilized due to a security vulnerability that allows users to implement a custom return value for this function, which was first stabilized in Rust 1.34.0.

@c4rtune c4rtune closed this Apr 22, 2026
@c4rtune c4rtune deleted the pull/60785 branch April 22, 2026 09:33
@c4rtune c4rtune restored the pull/60785 branch April 22, 2026 09:33
@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