Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel allows users to use sha1 Hash for Jar Verification #8880

Closed
JLLeitschuh opened this issue Jul 12, 2019 · 8 comments
Closed

Bazel allows users to use sha1 Hash for Jar Verification #8880

JLLeitschuh opened this issue Jul 12, 2019 · 8 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request

Comments

@JLLeitschuh
Copy link

JLLeitschuh commented Jul 12, 2019

This is a public disclosure of a 0-day vulnerability in Bazel that has not been fixed within the 90-day vulnerability disclosure window given to the Google security team.

The original report to the Google Security Team can be found here:
https://issuetracker.google.com/issues/130163464

Summary: CWE-327: Use of a Broken or Risky Cryptographic Algorithm for Security Verification of Build Dependencies

Bazel's build uses SHA-1 hashes to verify the integrity of build artifacts resolved from artifact servers to ensure that they haven't been maliciously compromised.

https://docs.bazel.build/versions/master/be/workspace.html#maven_jar_args

sha1 String; optional

A SHA-1 hash of the desired jar.
If the downloaded jar does not match this hash, Bazel will error out. It is a security risk to omit the SHA-1 as remote files can change. At best omitting this field will make your build non-hermetic. It is optional to make development easier but should be set before shipping.

The specific quote that's important here is "It is a security risk to omit the SHA-1 as remote files can change."

According to Wikipedia: https://en.wikipedia.org/wiki/SHA-1
"Since 2005 SHA-1 has not been considered secure against well-funded opponents"

A practical SHA-1 attack has been demonstrated by Google:
https://shattered.io/

I want to note that some uses of Bazel I've found in Non-Google public repositories are using HTTP to resolve dependencies from artifact server, thus opening them to MITM attacks where an SHA-1 collision artifact is served. See #8607

Attack scenario:

Large, well-funded organizations with the capabilities to invest lots of CPU time into this attack.

Who is capable of mounting this attack?
This attack required over 9,223,372,036,854,775,808 SHA1 computations. This took the equivalent processing power as 6,500 years of single-CPU computations and 110 years of single-GPU computations.

https://shattered.io/

By creating an SHA-1 collision of some JAR file, hacking a popular artifact server (like JFrog or Maven Central) and replacing those artifacts, Bazel users may be using maliciously compromised artifacts without knowing that's what they are doing.


The second preimage attack now only costs ~$100,000 according to new research published May 13th, 2019.

Our initial estimations were $1 million to compute the chosen-prefix collision, which is an amount of money we simply don't have. Thanks to our latest improvements, the cost went down below $100,000 and we are currently working on computing the first chosen-prefix collision for SHA-1.
- https://www.zdnet.com/article/sha-1-collision-attacks-are-now-actually-practical-and-a-looming-danger/

As such, this attack is now financially feasible against the Basel Build Infrastructure. Such an attack would only cost ~ the average 1 year salary of your average software engineer in the US.

@laurentlb laurentlb added the P0 This is an emergency and more important than other current work. (Assignee required) label Jul 12, 2019
@laurentlb
Copy link
Contributor

cc @aehlig

Is it going to be fixed with #8607 or do we need another change?

@laurentlb
Copy link
Contributor

Related: #6799

The vulnerability affects the function maven_jar which is deprecated. The replacement doesn't support sha1, only sha256.

@aehlig
Copy link
Contributor

aehlig commented Jul 12, 2019

Is it going to be fixed with #8607 or do we need another change?

The native maven_jar function (which is deprecated anyway) is not affected by #8607, as that only changes the way how starlark repository rules (which, in the long run, should be the only repository rules, besides local_repository) download files.

@laurentlb
Copy link
Contributor

I think the next steps are:

  • Update the documentation. maven_jar documentation doesn't contain any warning.
  • Check that the maven_jar replacement is production-ready.
  • Flip the flag incompatible_remove_native_maven_jar to disable maven_jar by Bazel 1.0 (September) or before.

@dslomov
Copy link
Contributor

dslomov commented Jul 12, 2019

This is not a security bug, and and not a vulnerability. sha1 function and maven_jar exist in Bazel, similar to how SHA1 functions are available to Java , C++ and other major languages. Its existence does not constitute vulnerability - if users do not want to use it, they are free to not to.

@dslomov dslomov added P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Starlark type: feature request and removed P0 This is an emergency and more important than other current work. (Assignee required) team-Starlark labels Jul 12, 2019
@dslomov dslomov changed the title [SECURITY] 0-Day Bazel Relies on Deprecated SHA1 Hash for Jar Verification Bazel allows users to use sha1 Hash for Jar Verification Jul 12, 2019
@laurentlb
Copy link
Contributor

At least, the documentation is misleading:

It is a security risk to omit the SHA-1 as remote files can change.

It is also a security risk to specify SHA-1, as far as I understand.

@JLLeitschuh
Copy link
Author

Should a CVE be issued for this report?

bazel-io pushed a commit that referenced this issue Jul 15, 2019
…of security as a cryptographic hash.

See #8880.

RELNOTES: None.
PiperOrigin-RevId: 258186415
@jin
Copy link
Member

jin commented Jul 16, 2019

We have added guidance in the documentation that SHA-1 is no longer considered a strong cryptographic hash, but it is still better than not using any. We have also added a recommendation to switch from maven_jar to rules_jvm_external, which supports a stronger SHA-256 hash verification.

See https://docs.bazel.build/versions/master/be/workspace.html#maven_jar.sha1 for more information.

Based on the above, I believe we have achieved remediation ("Add and recommend usage of stronger hashes (e.g. sha256)") and we can close this issue.

The next steps from here will be to remove the maven_jar feature from Bazel altogether. This work can be tracked in #6799.

@jin jin closed this as completed Jul 16, 2019
bazel-io pushed a commit that referenced this issue Aug 26, 2019
..and print warnings if sha256 or sha256_src aren't used, like this:

> `WARNING: /usr/local/google/home/jingwen/code/copybara/WORKSPACE:192:1: maven_jar rule @junit//jar: Not using a checksum to verify the integrity of the artifact or the usage of SHA-1 is not secure (see https://shattered.io) and can result in an non-reproducible build. Please specify the SHA-256 checksum with: sha256 = "90a8e1603eeca48e7e879f3afbc9560715322985f39a274f6f6070b43f9d06fe",`

> `WARNING: /usr/local/google/home/jingwen/code/copybara/WORKSPACE:192:1: maven_jar rule @junit//jar: Not using a checksum to verify the integrity of the artifact or the usage of SHA-1 is not secure (see https://shattered.io) and can result in an non-reproducible build. Please specify the SHA-256 checksum with: sha256_src = "694f4694a51f67dadea4d2045742d38fb4efb92d82d42744b15e26ce653bcd3e",`

The warning message is designed to be copy paste-able directly into the WORKSPACE file.

#6799
#8880

RELNOTES: Added `sha256` and `sha256_src` attributes to `maven_jar`. Please consider migrating to SHA-256 as SHA-1 has been deemed cryptographically insecure ([https://shattered.io]()). Or, use [`rules_jvm_external`](https://github.com/bazelbuild/rules_jvm_external) to manage your transitive Maven dependencies with artifact pinning and SHA-256 verification support.

Closes #9237.

Change-Id: I17ef2f88911efbb4527303b1dc1bcb827cc5e308
PiperOrigin-RevId: 265530046
@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
@philwo philwo removed the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Nov 29, 2021
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
… of security as a cryptographic hash.

    See bazelbuild/bazel#8880.

    RELNOTES: None.
    PiperOrigin-RevId: 258186415
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants