Add text_direction_codepoint lint (CVE-2021-42574) #16451
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR try to resolve?
This PR implements the text_direction_codepoint lint for
Cargo.tomlfiles:Fixes #16373 and #16374
lint detects Unicode BiDi (bidirectional) control codepoints that can be used in "Trojan Source" attacks. These invisible characters can alter the visual display of text without changing its underlying representation, potentially making malicious manifest content appear benign. All like descritped in rustc's text_direction_codepoint_in_comment/literal lint but for Cargo manifests.
Detected codepoints:
U+202ALEFT-TO-RIGHT EMBEDDINGU+202BRIGHT-TO-LEFT EMBEDDINGU+202CPOP DIRECTIONAL FORMATTINGU+202DLEFT-TO-RIGHT OVERRIDEU+202ERIGHT-TO-LEFT OVERRIDEU+2066LEFT-TO-RIGHT ISOLATEU+2067RIGHT-TO-LEFT ISOLATEU+2068FIRST STRONG ISOLATEU+2069POP DIRECTIONAL ISOLATEDefault level:
denyHow to test and review this PR?
cargo test -p cargo --test testsuite -- lints::text_direction_codepointManual testing:
Create a manifest with BiDi codepoint (U+202E)
The lint can be configured via
[lints.cargo]: