Most active commenters

    ←back to thread

    1208 points jamesberthoty | 30 comments | | HN request time: 0.956s | source | bottom
    Show context
    codemonkey-zeta ◴[] No.45261026[source]
    I'm coming to the unfortunate realizattion that supply chain attacks like this are simply baked into the modern JavaScript ecosystem. Vendoring can mitigate your immediate exposure, but does not solve this problem.

    These attacks may just be the final push I needed to take server rendering (without js) more seriously. The HTMX folks convinced me that I can get REALLY far without any JavaScript, and my apps will probably be faster and less janky anyway.

    replies(18): >>45261086 #>>45261121 #>>45261140 #>>45261165 #>>45261220 #>>45261265 #>>45261285 #>>45261457 #>>45261571 #>>45261702 #>>45261970 #>>45262601 #>>45262619 #>>45262851 #>>45267210 #>>45268405 #>>45269073 #>>45273081 #
    1. jeswin ◴[] No.45261970[source]
    Traditional JS is actually among the safest environments ever created. Every day, billions of devices run untrusted JS code, and no other platform has seen sandboxed execution at such scale. And in nearly three decades, there have been very few incidents of large successful attacks on browser engines. That makes the JS engine derived from browsers the perfect tool to build a server side framework out of.

    However, processes and practices around NodeJS and npm are in dire need of a security overhaul. leftpad is a cultural problem that needs to be addressed. To start with, snippets don't need to be on npm.

    replies(6): >>45262184 #>>45262208 #>>45262220 #>>45262223 #>>45262238 #>>45264048 #
    2. spankalee ◴[] No.45262184[source]
    Sandboxing doesn't do any good if the malicious code and target data are in the same sandbox, which is the whole point of these supply-chain attacks.
    replies(3): >>45262918 #>>45266847 #>>45267459 #
    3. kortilla ◴[] No.45262208[source]
    None of those security guarantees matter when you take out the sandbox, which is exactly what server-side JS does.

    The isolated context is gone and a single instance of code talking to an individual client has access to your entire database. It’s a completely different threat model.

    replies(1): >>45262925 #
    4. WD-42 ◴[] No.45262220[source]
    Javascript doesn't have a standard library, until it does the 170 million[1] weekly downloads of packages like UUID will continue. You can't expect people to re-write everything over and over.

    [1]https://www.npmjs.com/package/uuid

    replies(5): >>45262335 #>>45262791 #>>45263174 #>>45263227 #>>45264429 #
    5. mewpmewp2 ◴[] No.45262223[source]
    Interestingly AI should be able to help a lot with desire to load those snippets.

    What I'm wondering if it would help the ecosystem, if you were able to rather load raw snippets into your codebase, and source control as opposed to having them as dependencies.

    So e.g. shadcn component pasting approach.

    For things like leftPad, cli colors and others you would just load raw typescript code from a source, and there you would immediately notice something malicious or during code reviews.

    You would leave actual npm packages to only actual frameworks / larger packages where this doesn't make sense and expect higher scrutiny, multi approvals of releases there.

    6. skydhash ◴[] No.45262238[source]
    I think the smallest C library I’ve seen was a single file to include on your project if you want terminal control like curses on windows. A lot of libraries on npm (and cargo) should be gist or a blog post.
    replies(2): >>45266658 #>>45272307 #
    7. skydhash ◴[] No.45262335[source]
    You have the DOM and Node APIs. Which I think cover more than C library or Common Lisp library. Adding direct dependencies is done by every project. The issue is the sprawling deps tree of NPM and JS culture.

    > You can't expect people to re-write everything over and over.

    That’s the excuse everyone is giving, then you see thousands of terminal libraries and calendar pickers.

    replies(2): >>45263264 #>>45274064 #
    8. jmull ◴[] No.45262791[source]
    FYI, there's crypto.randomUUID()

    That's built in to server side and browser.

    9. pixl97 ◴[] No.45262918[source]
    I mean, what does do good if your supply chain is attacked?

    This said, less potential vendors supplying packages 'may' reduce exposure, but doesn't remove it.

    Either way, not running the bleeding edge packages unless it's a known security fix seems like a good idea.

    replies(1): >>45265911 #
    10. galaxyLogic ◴[] No.45262925[source]
    So maybe the solution would be to sandbox Node.js?

    I'm not quite sure what that would mean, but if it solves the problem for browsers, why not for server?

    replies(2): >>45263228 #>>45263300 #
    11. simiones ◴[] No.45263174[source]
    That's not the problem. There is a cultural (and partly technical) aversion in JavaScript to large libraries - this is where the issue comes from. So, instead of having something like org.apache.commons in Java or Boost in C++ or Posix in C, larger libraries that curate a bunch of utilities missing from the standard library, you get an uncountable number of small standalone libraries.

    I would bet that you'll find a third party `leftpad` implementation in org.apache.commons or in Spring or in some other collection of utils in Java. The difference isn't the need for 3rd party software to fix gaps in the standard library - it's the preference for hundreds of small dependencies instead of one or two larger ones.

    replies(2): >>45264977 #>>45268119 #
    12. ◴[] No.45263227[source]
    13. simiones ◴[] No.45263228{3}[source]
    You can't sandbox the code that is supposed to talk to your DB from your DB.

    And even on client side, the sandboxing helps isolate any malicious webpage, even ones that are accidentally malicious, from other webpages and from the rest of your machine.

    If malicious actors could get gmail.com to run their malicious JS on the client side through this type of supply-chain attack, they could very very easily steal all of your emails. The browser sandbox doesn't offer any protection from 1st party javascript.

    14. chamomeal ◴[] No.45263264{3}[source]
    When I was learning JS/node/npm as a total programming newbie, a lot of the advice online was basically “if you write your own version of foobar when foobar is already available as an npm package, you’re stupid for wasting your time”.

    I’d never worked in any other ecosystem, and I wish I realized that advice was specific to JS culture

    replies(1): >>45263944 #
    15. int_19h ◴[] No.45263300{3}[source]
    Deno does exactly that.

    But in practice, to do useful things server-side you generally need quite a few permissions.

    16. jlarocco ◴[] No.45263944{4}[source]
    It's not really bad advice, it just has different implications in Javascript.

    In other languages, you'd have a few dependencies on larger libraries providing related functionality, where the Javascript culture is to use a bunch of tiny libraries to give the same functionality.

    replies(1): >>45264086 #
    17. lenerdenator ◴[] No.45264048[source]
    > Traditional JS is actually among the safest environments ever created.

    > However, processes and practices around NodeJS and npm are in dire need of a security overhaul. leftpad is a cultural problem that needs to be addressed. To start with, snippets don't need to be on npm.

    Traditional JS is the reason we have all of these problems around NodeJS and npm. It's a lot better than it was, but a lot of JS tooling came up in the time when ES5 and older were the standard, and to call those versions of the language lacking is... charitable. There were tons of things that you simply couldn't count on the language or its standard library to do right, so a culture of hacks and bandaids grew up around it. Browser disparities didn't help either.

    Then people said, "Well, why don't we all share these hacks and bandaids so that we don't have to constantly reinvent the wheel?", and that's sort of how npm got its start. And of course, it was the freewheeling days of the late 00s/early 10s, when you were supposed to "move fast and break things" as a developer, so you didn't have time to really check if any of this was secure or made any sense. The business side wanted the feature and they wanted it now.

    The ultimate solution would be to stop slapping bandaids and hacks on the JS ecosystem by making a better language but no one's got the resolve to do that.

    replies(1): >>45269574 #
    18. lenerdenator ◴[] No.45264086{5}[source]
    Sometimes I wonder how many of these tiny libraries are just the result of an attempt to have something ready for a conference talk and no one had the courage to say "Uh, Chris, that already exists, and the world doesn't need your different approach on it."
    19. lupusreal ◴[] No.45264429[source]
    > You can't expect people to re-write everything over and over.

    Call me crazy but I think agentic coding tools may soon make it practical for people to not be bogged down by the tedium of implementing the same basic crap over and over again, without having to resort to third party dependencies.

    I have a little pavucontrol replacement I'm walking Claude Code through. It wanted to use pulsectl but, to see what it could do, I told it no. Write your own bindings to libpulse instead. A few minutes later it had that working. It can definitely write crap like leftpad.

    20. knert ◴[] No.45264977{3}[source]
    1000% agree. Javascript is weak in this regard if you compare it to major programming languages. It just adds unnecessary security risks not having a language with built in imports for common things like making API calls out or parsing JSON, for example.
    replies(1): >>45268156 #
    21. spankalee ◴[] No.45265911{3}[source]
    The supply chain infrastructure needs to stop being naive and allowing for insecure publishing.

    - npm should require 2FA disallow tokens for publishing. This is an option, but it should be a requirement.

    - npm should require using a trusted publisher and provenance for package with over 100k downloads a week and their dependencies.

    - Github should require a 2FA step for automated publishing

    - npm should add a cool down period where if won't install brand new packages without a flag

    - npm should stop running postinstall scripts.

    - npm should have an option to not install packages without provenance.

    replies(1): >>45268709 #
    22. mhitza ◴[] No.45266658[source]
    15+ years ago used to copy paste utility functions from stackoverflow, now people npm installing packages for a function or two.
    23. AlienRobot ◴[] No.45266847[source]
    I think the sandbox they're talking about is the browser, not the server (which runs node).
    24. tetha ◴[] No.45267459[source]
    But if we think about a release publishing chain like a BSD process separation, why do they have to be?

    Sure, there will be a step/stage that will require access to NPM publish credentials to publish to NPM. But why does this stage need to execute any code except a very small footprint of vetted code? It should just pickup a packaged, signed binary and move it to NPM.

    The compilation/packaging step on the other hand doesn't need publishing rights to NPM. Ideally, it should only get a filesystem with the sources, dependencies and a few shared libraries and /sys or /proc dependencies it may need to function. Why does some dependency downloading need access to your entire filesystem? Maybe it needs some allowed secrets, but eh.

    It's certainly a lot of change into existing pipelines and ideas, and it's certainly possible to poke holes into there if you want things to be easy. But it'd raise the bar quite a bit.

    25. anon7000 ◴[] No.45268119{3}[source]
    Lodash is a good counterpoint, but it’s falling out of style since the JS runtimes support more basic things now.

    JS apps, despite the HN narrative, have a much stronger incentive to reduce bundle/“executable” size compared to most other software, because the expectation is for your web app to “download” nearly instantly for every new user. (Compare to nearly any other type of software, client or server, where that’s not an expectation.)

    JS comes with exactly zero tools out of the box to make that happen. You have to go out of your way to find a modern toolchain that will properly strip out dead code and create optimized scripts that are as small as possible.

    This means the “massive JS library which includes everything” also depends on having a strong toolchain for compiling code. And while may professional web projects have that, the basic script tag approach is still the default and easiest way to get started… and pulling in a massive std library through that is just a bad idea.

    This baseline — the web just simply having different requirements around runtime execution — is part of where the culture comes from.

    And because the web browser traditionally didn’t include enough of a standard library for making apps, there’s a strong culture of making libraries and frameworks to solve that. Compare to native apps, where there’s always an official sdk or similar for building apps, and libraries like boost are more about specific “lower level” language features (algorithms, concurrency, data structures, etc) and less about building different types of software like full-blown interactive applications and backend services.

    There are attempts to solve this (Deno is probably the best example), but buy-in at a professional level requires a huge commitment to migrate and change things, so there’s a lot of momentum working against projects like that.

    26. anon7000 ◴[] No.45268156{4}[source]
    It does have functions for that, “fetch” and “JSON.parse,” available in most JS runtimes.
    27. raxxorraxor ◴[] No.45268709{4}[source]
    The reality is that for a huge crowd of developers 2FA doesn't do shit.
    28. com2kid ◴[] No.45269574[source]
    Python is the other extreme, with an incredibly heavy weight standard library with a built in function to do just about anything.

    E.g. there is a built in function that takes elements pairwise from a list! That level of minutia being included feels nuts having come from other languages.

    29. deelowe ◴[] No.45272307[source]
    It shouldn't matter how many libraries npm supports.
    30. user34283 ◴[] No.45274064{3}[source]
    It's a waste of time to strictly vet dependencies on my side when adding the standard test runner by Meta - jest - alone adds 300 packages to my dependency graph.

    So yes, the sprawling deps tree and culture is the problem. We would need to start reducing dependencies of the basic tools first. Otherwise it seems rather pointless to bother app developers with reducing dependencies.