Skip to content

Nix accepts invalid SRI hashes (MD5 and SHA-1) #8982

@nicoonoclaste

Description

@nicoonoclaste

Describe the bug

Nix accepts outputHash values that resemble the SRI hash format but use invalid hash-algo values, such as md5 or sha1. (hash-algo refering to the term in the SRI grammar)

Steps To Reproduce

Evaluate the following expressions:

fetchurl {
  url = "https://www.perdu.com";
  hash = "md5-rrdBU2a35b2PM2ZO+n/zGw==";
}

Expected behavior

Nix should error out, probably with something like « 'md5' is not an SRI hash algorithm. »

nix-env --version output

nix-env (Nix) 2.17.0

Additional context

  • The SRI hash format's specification refers to “CSP Level 2” for the definition of hash-algo and base64-value, as used in its grammar. In turn, the CSP spec defines hash-algo to be one of sha256, sha384 or sha512.
  • Furthermore, the SRI spec explicitly disallows MD5 and SHA-1:

User agents SHOULD refuse to support known-weak hashing functions like MD5 or SHA-1 and SHOULD restrict supported hashing functions to those known to be collision-resistant.

Priorities

Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions