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

fetchurl not check certificate: possible address malicious redirects #5837

Open
psydvl opened this issue Dec 28, 2021 · 6 comments
Open

fetchurl not check certificate: possible address malicious redirects #5837

psydvl opened this issue Dec 28, 2021 · 6 comments
Labels

Comments

@psydvl
Copy link
Member

psydvl commented Dec 28, 2021

Describe the bug

For now, fetchurl not check certificate and can make malicious redirects.
Like I faced just now, when nix tried to download package source from URL blocked in my country, and there are fully accessible second one.

More details in NixOS/nixpkgs#152281

Steps To Reproduce
Known for me:

  1. Move to Russia(?), or launch VPN to Russia, or create some DNS rule(?)
  2. Try to install nixpkgs.tor-browser-bundle-bin

Expected behavior

Nix find out certificate replacement and try to download from next available src source.

nix-env --version output

$ nix-env --version
nix-env (Nix) 2.4
$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.3-zen1, NixOS, 21.11 (Porcupine)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.4`
 - channels(root): `"nixos-21.11.334797.6979c0e49bb, nixos-unstable-22.05pre340469.cb372c3b888"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos

Additional context
Possibly related #4173

@psydvl
Copy link
Member Author

psydvl commented Dec 29, 2021

There are a lot of update scripts, which update sha256 with nix-prefetch-url:
Like this one:
https://github.com/NixOS/nixpkgs/blob/8a54f4c0bbef28976f69347c458ce74ed98e0234/pkgs/applications/networking/cluster/terraform-providers/update-provider#L140

@SuperSandro2000
Copy link
Member

nix-prefetch-url checks the ssl certificate, fetchurl does not.

$ nix-prefetch-url https://untrusted-root.badssl.com/
warning: error: unable to download 'https://untrusted-root.badssl.com/': SSL peer certificate or SSH remote key was not OK (60); retrying in 345 ms
warning: error: unable to download 'https://untrusted-root.badssl.com/': SSL peer certificate or SSH remote key was not OK (60); retrying in 528 ms
warning: error: unable to download 'https://untrusted-root.badssl.com/': SSL peer certificate or SSH remote key was not OK (60); retrying in 1051 ms
warning: error: unable to download 'https://untrusted-root.badssl.com/': SSL peer certificate or SSH remote key was not OK (60); retrying in 2680 ms
error: unable to download 'https://untrusted-root.badssl.com/': SSL peer certificate or SSH remote key was not OK (60)

@SuperSandro2000
Copy link
Member

This is not a problem in nix. The root cause lays in fetchurl which only sets the path to the certificates if the hash is empty https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/fetchurl/default.nix#L142 . This is always the case except when generating the hash for the first time and setting the output hash to empty which does not even work with all functions. In practice it is never checked. This is not easily fixable because cacert uses buildcatrust https://github.com/NixOS/nixpkgs/blob/master/pkgs/data/misc/cacert/default.nix#L5 which means we would need to bootstrap the entirety of python without cacert.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/question-about-fetchers-and-tls/18243/1

@TLATER
Copy link

TLATER commented Mar 18, 2022

@SuperSandro2000 as mentioned on discourse, it not being a problem is not wrong, but also not entirely true either. An insecure hash can be abused by a particularly crafty adversary here, and there are at least a few packages that use sha1 in nixpkgs (apparently anything using yarn/npm): https://github.com/NixOS/nixpkgs/search?q=sha1&type=

I still think the risk is quite low, but it does exist. Maybe insecure checksums should be deprecated?

@stale stale bot added the stale label Sep 21, 2022
@timbertson
Copy link
Contributor

timbertson commented Nov 30, 2023

This is not easily fixable because cacert uses buildcatrust https://github.com/NixOS/nixpkgs/blob/master/pkgs/data/misc/cacert/default.nix#L5 which means we would need to bootstrap the entirety of python without cacert.

@SuperSandro2000 It looks like fetchurl allows the cacert dependency to be null. Could the branching logic be that we use --insecure when cacert == null? Then the bootstrapping issue could be resolved by passing cacert = null in the one relevant place (buildcatrust?), but everywhere else it's the real cacert, and performs certificate checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants