Skip to content

Commit c9e2be5

Browse files
Alex Eaglecopybara-github
Alex Eagle
authored andcommitted
Add SHA-1 to subresource integrity format for download() checksums
npm packages commonly still use SHA-1. While it may be discouraged for its poor security, Bazel cannot enforce what external ecosystems currently do. I tested this locally against a feature we are working on in rules_nodejs. Closes bazelbuild#12777. PiperOrigin-RevId: 353633120
1 parent 60d6f78 commit c9e2be5

File tree

1 file changed

+6
-1
lines changed
  • src/main/java/com/google/devtools/build/lib/bazel/repository/downloader

1 file changed

+6
-1
lines changed

src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/Checksum.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public static Checksum fromSubresourceIntegrity(String integrity) {
4343
byte[] hash = null;
4444
int expectedLength = 0;
4545

46+
if (integrity.startsWith("sha1-")) {
47+
keyType = KeyType.SHA1;
48+
expectedLength = 20;
49+
hash = decoder.decode(integrity.substring(5));
50+
}
4651
if (integrity.startsWith("sha256-")) {
4752
keyType = KeyType.SHA256;
4853
expectedLength = 32;
@@ -63,7 +68,7 @@ public static Checksum fromSubresourceIntegrity(String integrity) {
6368
throw new IllegalArgumentException(
6469
"Unsupported checksum algorithm: '"
6570
+ integrity
66-
+ "' (expected SHA-256, SHA-384, or SHA-512)");
71+
+ "' (expected SHA-1, SHA-256, SHA-384, or SHA-512)");
6772
}
6873

6974
if (hash.length != expectedLength) {

0 commit comments

Comments
 (0)