Most active commenters
  • bflesch(4)
  • oblio(4)
  • bugtodiffer(3)
  • (3)

←back to thread

Deno 2.4

(deno.com)
132 points hackandthink | 38 comments | | HN request time: 1.772s | source | bottom
1. bflesch ◴[] No.44488699[source]
Big fan of deno, congrats on shipping.

From a security standpoint it really icks me when projects prominently ask their users to do the `curl mywebsite.com/foo.sh | sh` thing. I know risk acceptance is different for many people, but if you download a file before executing it, at least you or your antivirus can check what it actually does.

As supply chain attacks are a significant security risks for a node/deno stack application, the `curl | sh` is a red flag that signals to me that the author of the website prefers convenience over security.

With a curl request directly executed, this can happen:

- the web server behind mywebsite.com/foo.sh provides malware for the first request from your IP, but when you request it again it will show a different, clean file without any code

- MITM attack gives you a different file than others receive

Node/deno applications using the npm ecosystem put a lot of blind trust into npm servers, which are hosted by microsoft, and therefore easily MITM'able by government agencies.

When looking at official docs for deno at https://docs.deno.com/runtime/getting_started/installation/ the second option behind `curl | sh` they're offering is the much more secure `npm install -g deno`. Here at least some file integrity checks and basic malware scanning are done by npm when downloading and installing the package.

Even though deno has excellent programmers working on the main project, the deno.land website might not always be as secure as the main codebase.

Just my two cents, I know it's a slippery slope in terms of security risk but I cannot say that `curl | sh` is good practice.

replies(10): >>44488723 #>>44488744 #>>44488758 #>>44488836 #>>44489041 #>>44489128 #>>44489256 #>>44489488 #>>44489530 #>>44489730 #
2. methyl ◴[] No.44488723[source]
Has any attack like this been ever seen in the wild? Not saying it's impossible – but I'm just curious if this vector was ever successfully exploited.
replies(1): >>44488785 #
3. whyever ◴[] No.44488744[source]
All the attacks you described also apply to downloading and executing a file. I don't think `curl | sh` is worse in this regard.
replies(2): >>44488755 #>>44488793 #
4. davedx ◴[] No.44488755[source]
If you download it first, you can at least eyeball what's been downloaded to check it doesn't start by installing a bitcoin miner
replies(1): >>44489213 #
5. bugtodiffer ◴[] No.44488758[source]
using deno isn't good security practice, their sandbox is implemented like stuff from the 90s
replies(3): >>44488797 #>>44488852 #>>44488903 #
6. bflesch ◴[] No.44488785[source]
I'm sure there are cases where the website CMS was hacked and then malware served instead of the normal install script. The `curl | sh` approach has been around forever.

And depending on what "interesting" IP address you are coming from, NSA/Microsoft/Apple will MITM your npm install / windows update / ios update accordingly.

Same in the linux ecosystem, if you look at the maintainers of popular distributions, some of them had .ru / .cn email addresses before switching to more official email addressess using the project domain - IMO this change of email addressess happened due to public pressure on russia after the Ukraine invasion. Having access to main package signing keys for a linux distribution, you can provide special packages from your linux package mirror to interesting targets.

All of these scenarios are extremely hard to prove after the fact and the parties involved are not the type of people who do public writeups.

replies(1): >>44488898 #
7. bflesch ◴[] No.44488793[source]
With a downloaded file your antivirus will run automated checks on it, you can calculate a hash signature and compare the value with others who also download the file, and you will notice if the file changes after you execute it.
8. bflesch ◴[] No.44488797[source]
Is node "sandbox" different? Does it even have a sandbox?
replies(1): >>44494016 #
9. oulipo ◴[] No.44488836[source]
how is it more or less good practice than running any untrusted binary on your system? the only possible stuff would be that the script download is broken midway and it becomes a "dangerous script" because eg of a `rm -rf /some/path` which would become a `rm -rf /` but other than that, it's just the same as downloading any executable on your laptop and running them... any attacks you described on the shell download would work with any other binary, which users routinely do
10. homebrewer ◴[] No.44488852[source]
If you're writing server stuff, at the coarse-grained level of isolation that Deno provides you're better off using just about anything else and restricting access to network/disks/etc through systemd. Unlike Deno, it can restrict access to specific filesystem paths and network addresses (whitelist/blacklist, your choice), and you're not locked into using just Deno and not forced to write JS/TS.

See `man systemd.exec`, `systemd-analyze security`, https://wiki.archlinux.org/title/Systemd/Sandboxing

replies(3): >>44489232 #>>44489298 #>>44489306 #
11. oblio ◴[] No.44488898{3}[source]
If the website CMS is hacked, they can just swap the installable binary to one's that's hacked, too.
replies(1): >>44489082 #
12. oblio ◴[] No.44488903[source]
Can you expand on this please? Also curious which 90s tech there inspired by.
replies(1): >>44488981 #
13. bugtodiffer ◴[] No.44488981{3}[source]
It is matching strings instead of actually blocking things. That's how sandboxes were implemented when I was a kid.

E.g. --allow-net --deny-net=1.1.1.1

You cannot fetch "http://1.1.1.1" but any domain that resolves to 1.1.1.1 is a bypass...

It's crap security

replies(3): >>44489091 #>>44489110 #>>44493725 #
14. CJefferson ◴[] No.44489041[source]
The problem is getting the new users onboarded. Telling people to use 'npm' doesn't help if you don't have npm installed.

How do I install npm? The npm webpage tells me to go and install nvm. At that tells me to use curl | sh .

So using npm for a new user is still requiring a curl | sh, just in a different place.

replies(3): >>44489374 #>>44489738 #>>44489751 #
15. pcl ◴[] No.44489082{4}[source]
That’s why downloading and then executing is preferable — as the GP pointed out, you or your machine’s antivirus can have an opportunity to inspect the file prior to execution, whereas that is not an option when the bytes are streamed directly to the interpreter.
16. jeltz ◴[] No.44489091{4}[source]
That isn't 90s security, that is just bad code. And bad code was written in the 90s and is still written today.
17. whizzter ◴[] No.44489110{4}[source]
If security principles are important they should be on a deny-default basis with allow-lists rather than the other way around.

If the deno runtime implements the fetch module itself, then post-resolution checking definitely should be done though. It's more of an bug though than a principled security lapse.

replies(1): >>44491115 #
18. geysersam ◴[] No.44489128[source]
> much more secure `npm install -g deno`. Here at least some file integrity checks and basic malware scanning are done by npm when downloading and installing the package.

It boils down to the question "is it more likely the attacker can impersonate or control `npm` servers or our own servers. If the answer to that question is "No" then curl pipe sh is not less secure than `npm install`.

This is security theater. If you're assuming an attacker can impersonate anyone in the internet your only secure option is to cut the cable.

19. geysersam ◴[] No.44489213{3}[source]
How often do people do that when they install a package from npm, pypi, or other package repository? In practice never.
replies(1): >>44489719 #
20. crabmusket ◴[] No.44489232{3}[source]
Deno can restrict access to filesystem files or directories, and to particular network domains, see docs for examples. https://docs.deno.com/runtime/fundamentals/security/#file-sy...

However in general I don't think Deno's permission system is all that amazing, and I am annoyed that people call it "capability-based" sometimes (I don't know if this came from the Deno team ever or just misinformed third parties).

I do like that "deno run https://example.com/arbitrary.js" has a minimum level of security by default, and I can e.g. restrict it to read and write my current working dir. It's just less helpful for combining components of varying trust levels into a single application.

21. troupo ◴[] No.44489256[source]
> ask their users to do the `curl mywebsite.com/foo.sh | sh` thing.

Because it's easier than maintaining packages across 10+ package managers. And in case of Linux it might not require sudo to install something.

22. vorticalbox ◴[] No.44489298{3}[source]
> Unlike Deno, it can restrict access to specific filesystem paths and network addresses

deno can do this via --(allow/deny)-read and --(allow/deny)-write for the file system.

You can do the same for net too

https://docs.deno.com/runtime/fundamentals/security/#permiss...

23. mk12 ◴[] No.44489306{3}[source]
Bubblewrap is another convenient sandboxing tool for Linux: https://wiki.archlinux.org/title/Bubblewrap
24. calrain ◴[] No.44489374[source]
Security is either taken seriously, or it isn't.

If security shortcuts are taken here, trust nothing else.

25. jgalt212 ◴[] No.44489488[source]
It would be great if curl could take file integrity hash value as a command line argument.
replies(1): >>44489877 #
26. ◴[] No.44489530[source]
27. ◴[] No.44489719{4}[source]
28. dicytea ◴[] No.44489730[source]
I really never understood the threat model behind this often repeated argument.

Most of these installation scripts are just simple bootstappers that will eventually download and execute millions lines of code authored and hosted by the same people behind the shell script.

You simply will not be capable of personally auditing those millions lines of code, so this problem boils down to your trust model. If you have so little trust towards the authors behind the project, to the point that you'd suspect them pulling absurdly convoluted ploys like:

> the web server behind mywebsite.com/foo.sh provides malware for the first request from your IP, but when you request it again it will show a different, clean file without any code

How can you trust them to not hide even more malicious code in the binary itself?

I believe the reason why this flawed argument have spread like a mind virus throughout the years is because it is something that is easy to do and easy to parrot in every mildly-relevant thread.

It is easy to audit a 5-line shell script. But to personally audit the millions lines of code behind the binary that that script will blindly download and run anyways? Nah, that's real security work and no one wants to actually do hard work here. We're just here to score some easy points and signal that we're a smart and security-conscious person to our peers.

> which are hosted by microsoft, and therefore easily MITM'able by government agencies.

If your threat model includes government agencies maliciously tampering your Deno binaries, you have far more things to worry about than just curl | sh.

replies(1): >>44491823 #
29. ◴[] No.44489738[source]
30. pxc ◴[] No.44489751[source]
If the actual installation process can be made simple, you can have users copy/paste the whole installation script rather than pulling it down with curl.

See for instance...

Setup instructions for Pkgsrc on macOS with the SmartOS people's binary caches: https://pkgsrc.smartos.org/install-on-macos/

Spack installation instructions: https://spack-tutorial.readthedocs.io/en/latest/tutorial_bas...

Guix setup used to look like this but now they have a shell script for download. Even so, the instructions advise saving it and walk you through what to expect so you can have reasonable expectations while installing it.

Anyway, my point is that there are other ways to instruct people about the same kind of install process.

31. lioeters ◴[] No.44489877[source]
I'd like to practice verifying file integrity, instead of running `curl | sh`. I see that sha256sum (or 512) is the standard command people use.

    # Download package and its checksum
    curl -fsSLO https://example.com/example-1.0.0.tar.gz
    curl -fsSLO https://example.com/example-1.0.0.tar.gz.sha256

    # Verify the checksum
    sha256sum -c example-1.0.0.tar.gz.sha256
But if the server is compromised, the malicious actor would likely be able to serve a matching hash to their file?
32. bugtodiffer ◴[] No.44491115{5}[source]
The thing is that this applies to all parts of the sandbox https://secfault-security.com/blog/deno.html
33. gr4vityWall ◴[] No.44491823[source]
I think bflesch's reasoning comes from the idea that the website developers may not hold their website to the same security standards as their software, and not from a trust issue. Nor from thinking the author themselves are malicious.

FWIW, I don't have a strong opinion here, besides that I like Debian's model the most. Just felt that it was worth to point out the above.

replies(1): >>44493557 #
34. captn3m0 ◴[] No.44493557{3}[source]
See the codecov incident, where exactly this happened: https://about.codecov.io/security-update/
35. oblio ◴[] No.44493725{4}[source]
Ah, so by default it's default deny everything but once you need to open up categories, you can't just allow exact what you need in that category? You have to allow the entire category and then deny everything you don't want/need?

That's a bit of a silly model.

replies(1): >>44493924 #
36. throwitaway1123 ◴[] No.44493924{5}[source]
> you can't just allow exact what you need in that category? You have to allow the entire category and then deny everything you don't want/need?

No, you can allow access to specific domains, IP addresses, filesystem paths, environment variables, etc, while denying everything else by default. You can for instance allow access to only a specific IP (e.g. `deno run --allow-net='127.0.0.1' main.ts`), while implicitly blocking every other IP.

What the commenter is complaining about is the fact that Deno doesn't check which IP address a domain name actually resolves to using DNS resolution. So if you explicitly deny '1.1.1.1', and the script you're running fetches from a domain with an A record pointing to '1.1.1.1', Deno will allow it.

In practice, I usually use allow lists rather than deny lists, because I very rarely have an exhaustive list on hand of every IP address or domain I'm expecting a rogue script to attempt to access.

replies(1): >>44494381 #
37. throwitaway1123 ◴[] No.44494016{3}[source]
Node does have a permissions system, but it's opt in. Many runtimes/interpreters either have no sandbox at all, or they're opt in, which is why Deno's sandbox is an upgrade, even if it's not as hardened as iptables or Linux namespaces.
38. oblio ◴[] No.44494381{6}[source]
Yeah, that was my point, default deny vs default allow.

If you can default deny, then you're good. It's kind of a junior sysadmin mistake, otherwise, I would say.