Skip to content

Commit bc8e4c8

Browse files
committed
Auto merge of #7619 - ehuss:beta-registry-doc, r=Eh2406
[beta] Extend documentation on security concerns of crate names in a registry. Beta backport of #7616 requested at #7616 (comment).
2 parents 5da4b4d + 0ab0b8f commit bc8e4c8

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

src/doc/src/reference/registries.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,23 @@ directories:
159159
> package names in `Cargo.toml` and the index JSON data are case-sensitive and
160160
> may contain upper and lower case characters.
161161
162-
Registries may want to consider enforcing limitations on package names added
163-
to their index. Cargo itself allows names with any [alphanumeric], `-`, or `_`
164-
character. For example, [crates.io] imposes relatively strict limitations,
165-
such as requiring it to be a valid Rust identifier, only allowing ASCII
166-
characters, under a specific length, and rejects reserved names such as
167-
Windows special filenames like "nul".
162+
Registries should consider enforcing limitations on package names added to
163+
their index. Cargo itself allows names with any [alphanumeric], `-`, or `_`
164+
characters. [crates.io] imposes its own limitations, including the following:
165+
166+
- Only allows ASCII characters.
167+
- Only alphanumeric, `-`, and `_` characters.
168+
- First character must be alphabetic.
169+
- Case-insensitive collision detection.
170+
- Prevent differences of `-` vs `_`.
171+
- Under a specific length (max 64).
172+
- Rejects reserved names, such as Windows special filenames like "nul".
173+
174+
Registries should consider incorporating similar restrictions, and consider
175+
the security implications, such as [IDN homograph
176+
attacks](https://en.wikipedia.org/wiki/IDN_homograph_attack) and other
177+
concerns in [UTR36](https://www.unicode.org/reports/tr36/) and
178+
[UTS39](https://www.unicode.org/reports/tr39/).
168179

169180
Each line in a package file contains a JSON object that describes a published
170181
version of the package. The following is a pretty-printed example with comments

tests/testsuite/cache_messages.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ fn color() {
9595
// Check enabling/disabling color.
9696
let p = project().file("src/lib.rs", "fn a() {}").build();
9797

98+
// Hack for issue in fwdansi 1.1. It is squashing multiple resets
99+
// into a single reset.
100+
// https://github.com/kennytm/fwdansi/issues/2
101+
fn normalize(s: &str) -> String {
102+
#[cfg(windows)]
103+
return s.replace("\x1b[0m\x1b[0m", "\x1b[0m");
104+
#[cfg(not(windows))]
105+
return s.to_string();
106+
};
107+
108+
let compare = |a, b| {
109+
assert_eq!(normalize(a), normalize(b));
110+
};
111+
98112
let agnostic_path = Path::new("src").join("lib.rs");
99113
let agnostic_path_s = agnostic_path.to_str().unwrap();
100114
// Capture the original color output.
@@ -121,21 +135,21 @@ fn color() {
121135
.cargo("check -q --color=always")
122136
.exec_with_output()
123137
.expect("cargo to run");
124-
assert_eq!(rustc_color, as_str(&cargo_output1.stderr));
138+
compare(rustc_color, as_str(&cargo_output1.stderr));
125139

126140
// Replay cached, with color.
127141
let cargo_output2 = p
128142
.cargo("check -q --color=always")
129143
.exec_with_output()
130144
.expect("cargo to run");
131-
assert_eq!(rustc_color, as_str(&cargo_output2.stderr));
145+
compare(rustc_color, as_str(&cargo_output2.stderr));
132146

133147
// Replay cached, no color.
134148
let cargo_output_nocolor = p
135149
.cargo("check -q --color=never")
136150
.exec_with_output()
137151
.expect("cargo to run");
138-
assert_eq!(rustc_nocolor, as_str(&cargo_output_nocolor.stderr));
152+
compare(rustc_nocolor, as_str(&cargo_output_nocolor.stderr));
139153
}
140154

141155
#[cargo_test]

0 commit comments

Comments
 (0)