Skip to content

Commit 84f3737

Browse files
authored
Don't use CARGO_REGISTRIES_* configuration in hash keys (#2308)
1 parent 989e7e3 commit 84f3737

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/compiler/rust.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,12 +1466,21 @@ where
14661466
.collect();
14671467
env_vars.sort();
14681468
for (var, val) in env_vars.iter() {
1469+
if !var.starts_with("CARGO_") {
1470+
continue;
1471+
}
1472+
14691473
// CARGO_MAKEFLAGS will have jobserver info which is extremely non-cacheable.
1470-
if var.starts_with("CARGO_") && var != "CARGO_MAKEFLAGS" {
1471-
var.hash(&mut HashToDigest { digest: &mut m });
1472-
m.update(b"=");
1473-
val.hash(&mut HashToDigest { digest: &mut m });
1474+
// CARGO_REGISTRIES_*_TOKEN contains non-cacheable secrets.
1475+
// Registry override config doesn't need to be hashed, because deps' package IDs
1476+
// already uniquely identify the relevant registries.
1477+
if var == "CARGO_MAKEFLAGS" || var.starts_with("CARGO_REGISTRIES_") {
1478+
continue;
14741479
}
1480+
1481+
var.hash(&mut HashToDigest { digest: &mut m });
1482+
m.update(b"=");
1483+
val.hash(&mut HashToDigest { digest: &mut m });
14751484
}
14761485
// 8. The cwd of the compile. This will wind up in the rlib.
14771486
cwd.hash(&mut HashToDigest { digest: &mut m });
@@ -3397,6 +3406,10 @@ proc_macro false
33973406
(OsString::from("CARGO_PKG_NAME"), OsString::from("foo")),
33983407
(OsString::from("FOO"), OsString::from("bar")),
33993408
(OsString::from("CARGO_BLAH"), OsString::from("abc")),
3409+
(
3410+
OsString::from("CARGO_REGISTRIES_A_TOKEN"),
3411+
OsString::from("ignored"),
3412+
),
34003413
]
34013414
.to_vec(),
34023415
false,

0 commit comments

Comments
 (0)