News for hackers. Stuff that matters.
Re:Self Propagating NPM Malware Compromises over 40 Packages by Ajedi32 on Tuesday September 16, 2025 @03:48PM (#45267054)
If it's not feasible to audit every single dependency, it's probably even less feasible to rewrite every single dependency from scratch. Avoiding that duplicated work is precisely why we import dependencies in the first place.
Re:Self Propagating NPM Malware Compromises over 40 Packages by zelphirkalt on Tuesday September 16, 2025 @04:17PM (#45267415)
Most dependencies do much more than we need from them. Often it means we only need one or a few functions from them. This means one doesn't need to rewrite whole dependencies usually. Don't use dependencies for things you can trivially write yourself, and use them for cases where it would be too much work to write yourself.
Re:Self Propagating NPM Malware Compromises over 40 Packages by btown on Tuesday September 16, 2025 @04:38PM (#45267701)
A brief but important point is that this primarily holds true in the context of rewriting/vendoring utilities yourself, not when discussing importing small vs. large dependencies.

Just because dependencies do a lot more than you need, doesn't mean you should automatically reach for the smallest dependency that fits your needs.

If you need 5 of the dozens of Lodash functions, for instance, it might be best to just install Lodash and let your build step shake out any unused code, rather than importing 5 new dependencies, each with far fewer eyes and release-management best practices than the Lodash maintainers have.

Re:Self Propagating NPM Malware Compromises over 40 Packages by latexr on Tuesday September 16, 2025 @07:38PM (#45269728)
The argument wasn’t to import five dependencies, one for each of the functions, but to write the five functions yourself. Heck, you don’t even need to literally write them, check the Lodash source and copy them to your code.
Re:Self Propagating NPM Malware Compromises over 40 Packages by mandevil on Tuesday September 16, 2025 @08:03PM (#45269917)
This might be fine for some utility functions which you can tell at a glance have no errors, but for anything complex, if you copy you don't get any of the bug/security fixes that upstream will provide automatically. Oh, now you need a shim of this call to work on the latest Chrome because they killed an api- you're on your own or you have to read all of the release notes for a dependency you don't even have! But taking a dependency on some other library is, as you note, always fraught. Especially because of transitive dependencies, you end up having quite a target surface area for every dep you take.

Whether to take a dependency is a tricky thing that really comes down to engineering judgement- the thing that you (the developer) are paid to make the calls on.

Re:Self Propagating NPM Malware Compromises over 40 Packages by jonquest on Tuesday September 16, 2025 @10:24PM (#45270873)
The massive amount of transitive dependencies is exactly the problem with regard to auditing them. There are successful businesses built solely around auditing project dependencies and alerting teams of security issues, and they make money at all because of the labor required to maintain this machine.

It’s not even a judgement call at this point. It’s more aligned with buckling your seatbelt, pointing your car off the road, closing your eyes, flooring it and hoping for a happy ending.

Re:Self Propagating NPM Malware Compromises over 40 Packages by halflife on Tuesday September 16, 2025 @08:00PM (#45269898)
And then when node is updated and natively supports set intersections you would go back to your copied code and fix it?
Re:Self Propagating NPM Malware Compromises over 40 Packages by skydhash on Tuesday September 16, 2025 @08:54PM (#45270249)
If it works, why do so? Unless there's a clear performance boost, and if so you already know the code and can quickly locate your interpreted version.

Or At the time of adding you can add a NOTE or FIXME comment stating where you copied it from. A quick grep for such keyword can give you a nice overview of nice to have stuff. You can also add a ticket with all the details if you're using a project management tool and resuscitate it when that hypothetical moment happens.

Re:Self Propagating NPM Malware Compromises over 40 Packages by ClikeX on Wednesday September 17, 2025 @05:57AM (#45273825)
If you won't, do you expect the maintainer of some micro package to do that?
Re:Self Propagating NPM Malware Compromises over 40 Packages by cluckindan on Wednesday September 17, 2025 @02:07AM (#45272318)
You have obviously never checked the Lodash source.
Re:Self Propagating NPM Malware Compromises over 40 Packages by latexr on Wednesday September 17, 2025 @05:15AM (#45273560)
The point here isn’t a specific library. It’s not even one specific language or runtime. No one is talking about literally five functions. Let’s not be pedantic and lose sight of the major point.
Re:Self Propagating NPM Malware Compromises over 40 Packages by cluckindan on Wednesday September 17, 2025 @05:17AM (#45273568)
I get that, but if you’ve ever tried to extract a single utility function from lodash, you know that it may not be as simple as copy-pasting a single function.
Re:Self Propagating NPM Malware Compromises over 40 Packages by zelphirkalt on Wednesday September 17, 2025 @07:13AM (#45274322)
If you are going to be that specific, then it would be good to post an example. If I remember correctly, lodash has some functions, that would be table stakes in functional languages, or easily built in functional languages. If such a function is difficult to extract, then it might be a good candidate to write in JS itself, which does have some of the typical tools, like map, reduce, and things like compose are easy to write oneself and part of every FP beginner tutorial. If such a function is difficult to extract, then perhaps lodash's design is not all that great. Maybe one could also copy them from elsewhere, where the code is more modular.

But again, if the discussion is going to be that specific, then you would need to provide actual examples, so that we could judge, whether we would implement that ourselves or it would be difficult to do so. Note, that often it is also not required for ones use-case, to have a 100% matching behavior either. The goal is not to duplicate lodash. The purpose of the extracted or reimplemented function would still be ones own project, where the job of that function might be much more limited.

Re:Self Propagating NPM Malware Compromises over 40 Packages by cluckindan on Wednesday September 17, 2025 @09:37AM (#45275698)
Let’s start with something simple, like difference().

https://github.com/lodash/lodash/blob/main/dist/lodash.js#L7...

So you also need to copy isArrayLikeObject, baseDifference and baseFlatten.

For baseDifference, you also need to copy arrayMap and baseUnary.

For baseFlatten, you also need to copy arrayPush.

For isArrayLikeObject, you also need to copy isArrayLike and isObjectLike.

For isArrayLike, you also need to copy isLength and isFunction.

For isFunction, you also need to copy isObject and baseGetTag.

For baseGetTag, you also need to copy getRawTag and objectToString.

I don’t have time to dig any deeper, just use tree-shaking ffs.

Re:Self Propagating NPM Malware Compromises over 40 Packages by zelphirkalt on Wednesday September 17, 2025 @10:44AM (#45276479)
OK in this case it looks like it is doing a lot of at runtime checking of arguments to treat them differently, based on what type of argument they are. If we restrict use to only work with arrays, or whatever we have in our project, where we need `difference`, then it should become much simpler and an easy rewrite. An alternative could be to have another argument, that is the function that gives us the `next` thing. Then the logic for that is to be specified by the caller.

Tree shaking however, will not help you, if you have to first install a library using NPM. It will only help you reduce overhead in the code served to a browser. Malicious code can run much earlier, and would be avoided, if you rewrite or extract relevant code from a library, avoiding to install the library using NPM. Or is there some pre-installation tree shaking, that I am unaware of? That would actually be interesting.

Re:Self Propagating NPM Malware Compromises over 40 Packages by cluckindan on Wednesday September 17, 2025 @11:38AM (#45277142)
I guess that pre-installation tree shaking in this case is installing ’lodash.difference’ instead of ’lodash’. :)
Re:Self Propagating NPM Malware Compromises over 40 Packages by Terr_ on Tuesday September 16, 2025 @05:33PM (#45268399)
I think the level of protection you get from that depends on how the unused code detection interacts with whatever tricks someone is using for malicious code.
Re:Self Propagating NPM Malware Compromises over 40 Packages by jay_kyburz on Tuesday September 16, 2025 @05:22PM (#45268248)
Yes, fewer, larger, trustworthy dependencies with tree shaking is the way to go if you ask me.
Re:Self Propagating NPM Malware Compromises over 40 Packages by _puk on Tuesday September 16, 2025 @05:33PM (#45268390)
Almost like a standard library..
Re:Self Propagating NPM Malware Compromises over 40 Packages by jay_kyburz on Tuesday September 16, 2025 @06:00PM (#45268741)
Yeah, but perhaps we could have different flavors. If you like functional style you could have a very functional standard library that doesn't mutate anything, or if you like object oriented stuff you could have classes of object with methods that mutate themselves. And the Typescript folks could have a strongly typed library.
Re:Self Propagating NPM Malware Compromises over 40 Packages by baq on Wednesday September 17, 2025 @02:23AM (#45272423)
I wanted to make a joke about

   npm install stdlib 
…but double checked before and @stdlib/stdlib has 58 dependencies, so the joke preempted me.
Re:Self Propagating NPM Malware Compromises over 40 Packages by hshdhdhj4444 on Tuesday September 16, 2025 @10:47PM (#45271035)
I agree with this but the problem is that a lot of the extra stuff dependencies do is indeed to protect from security issues.

If you’re gonna reimplement only thr code you need from a dependency, it’s hard to know of the stuff you’re leaving out how much is just extra stuff you don’t need and how much might be security fixes that may not be apparent to you but the dependency by virtue of being worked upon and used by many people has fixed.

Re:Self Propagating NPM Malware Compromises over 40 Packages by vFunct on Tuesday September 16, 2025 @10:52PM (#45271065)
I'm using LLMs to write stuff that would normally be in dependencies, mostly because I don't want to learn how to use the dependency, and writing a new one from scratch is really easy with LLMs.
Re:Self Propagating NPM Malware Compromises over 40 Packages by baq on Wednesday September 17, 2025 @02:26AM (#45272434)
Age of bespoke software is here. Did you have any hard to spot non-obvious bugs in these code units?
Re:Self Propagating NPM Malware Compromises over 40 Packages by gameman144 on Tuesday September 16, 2025 @04:01PM (#45267222)
It isn't feasible to audit every line of every dependency, just as it's not possible to audit the full behavior of every employee that works at your company.

In both cases, the solution is similar: try to restrict access to vital systems only to those you trust,so that you have less need to audit their every move.

Your system administrators can access the server room, but the on-site barista can't. Your HTTP server is trusted enough to run in prod, but a color-formatting library isn't.

Re:Self Propagating NPM Malware Compromises over 40 Packages by autoexec on Tuesday September 16, 2025 @09:33PM (#45270529)
> It isn't feasible to audit every line of every dependency, just as it's not possible to audit the full behavior of every employee that works at your company.

Your employees are carefully vetted before hiring. You've got their names, addresses, and social security numbers. There's someone you're able to hold accountable if they steal from you or start breaking everything in the office.

This seems more like having several random contractors who you've never met coming into your business in the middle of night. Contractors that were hired by multiple anonymous agencies you just found online somewhere with company names like gkz00d or 420_C0der69 who you've also never even spoken to and who have made it clear that they can't be held accountable for anything bad that happens. Agencies that routinely swap workers into or out of various roles at your company without asking or telling you, so you don't have any idea who the person working in the office is, what they're doing, or even if they're supposed to be there.

"To make thing easier for us we want your stuff to require the use of a bunch of code (much of which does things you don't even need) that we haven't bothered looking at because that'd be too much work for us. Oh, and third parties we have no relationship with control a whole bunch of that code which means it can be changed at any moment introducing bugs and security issues we might not hear about for months/years" seems like it should be a hard sell to a boss or a client, but it's sadly the norm.

Assuming that something is going to go wrong and trying to limit the inevitable damage is smart, but limiting the amount of untrustworthy code maintained by the whims of random strangers is even better. Especially when the reasons for including something that carries so much risk is to add something trivial or something you could have just written yourself in the first place.

Re:Self Propagating NPM Malware Compromises over 40 Packages by skwashd on Wednesday September 17, 2025 @02:04AM (#45272298)
> This seems more like having several random contractors who you've never met coming into your business in the middle of night. [...] Agencies that routinely swap workers into or out of various roles at your company without asking or telling you, so you don't have any idea who the person working in the office is, what they're doing, or even if they're supposed to be there.

Sounds very similar to how global SIs staff enterprise IT contracts.

Re:Self Propagating NPM Malware Compromises over 40 Packages by xorcist on Wednesday September 17, 2025 @04:16AM (#45273210)
That hit much too close to reality. It's exactly like that. Even the names were spot on!
Re:Self Propagating NPM Malware Compromises over 40 Packages by curtisf on Tuesday September 16, 2025 @03:51PM (#45267090)
This is true to the extent that you actually _use_ all of the features of a dependency.

You only need to rewrite what you use, which for many (probably most) libraries will be 1% or less of it

Re:Self Propagating NPM Malware Compromises over 40 Packages by zahlman on Tuesday September 16, 2025 @04:26PM (#45267507)
Indeed. About 26% of the disk space for a freshly-installed copy of pip 25.2 for Python 3.13 comes from https://pypi.org/project/rich/ (and its otherwise-unneeded dependency https://pypi.org/project/Pygments/), "a Python library for rich text and beautiful formatting in the terminal", hardly any of the features of which are relevant to pip. This is in spite of an apparent manual tree-shaking effort (mostly on Pygments) — a separate installed copy of rich+Pygments is larger than pip. But even with that attempt, for example, there are hundreds of kilobytes taken up for a single giant mapping of "friendly" string names to literally thousands of emoji.

Another 20% or more is https://pypi.org/project/requests/ and its dependencies — this is an extremely popular project despite that the standard library already provides the ability to make HTTPS connections (people just hate the API that much). One of requests' dependencies is certifi, which is basically just a .pem file in Python package form. The vendored requests has not seen any tree-shaking as far as I can tell.

This sort of thing is a big part of why I'll be able to make PAPER much smaller.

Re:Self Propagating NPM Malware Compromises over 40 Packages by vasco on Tuesday September 16, 2025 @10:22PM (#45270855)
What paper?
Re:Self Propagating NPM Malware Compromises over 40 Packages by what on Tuesday September 16, 2025 @11:02PM (#45271127)
Re:Self Propagating NPM Malware Compromises over 40 Packages by zahlman on Wednesday September 17, 2025 @01:27PM (#45278782)
Yes, that. I didn't want to be too spammy, especially since I honestly haven't been getting much of anything done recently (personal reasons).
Re:Self Propagating NPM Malware Compromises over 40 Packages by AlecBG on Tuesday September 16, 2025 @03:51PM (#45267094)
Not sure I completely agree as you often use only a small part of a library
Re:Self Propagating NPM Malware Compromises over 40 Packages by lukan on Tuesday September 16, 2025 @03:54PM (#45267132)
"rewrite every single dependency from scratch"

No need to. But also no need to pull in a dependency that could be just a few lines of own (LLM generated) code.

Re:Self Propagating NPM Malware Compromises over 40 Packages by brianleb on Tuesday September 16, 2025 @04:01PM (#45267221)
>>a few lines of own (LLM generated) code.

... and now you've switched the attack vector to a hostile LLM.

Re:Self Propagating NPM Malware Compromises over 40 Packages by zelphirkalt on Tuesday September 16, 2025 @04:28PM (#45267528)
Though you will see the code at least, when you are copy pasting it and if it is really only a few lines, you may be able to review it. Should review it of course.
Re:Self Propagating NPM Malware Compromises over 40 Packages by LtWorf on Tuesday September 16, 2025 @06:30PM (#45269090)
If it's that little review the dependency.
Re:Self Propagating NPM Malware Compromises over 40 Packages by lukan on Wednesday September 17, 2025 @03:35AM (#45272950)
The difference is, the dependency can change and is usually way harder to audit. Subfolders in subfolder, 2 lines here in a file, 3 line there vs locking at some files and check what they do.
Re:Self Propagating NPM Malware Compromises over 40 Packages by appreciatorBus on Tuesday September 16, 2025 @06:30PM (#45269094)
Sure but that's a one time vector. If the attacker didn't infiltrate the LLM before it generated the code, then the code is not going to suddenly go hostile like an npm package can.
Re:Self Propagating NPM Malware Compromises over 40 Packages by lukan on Wednesday September 17, 2025 @01:40AM (#45272158)
I did not say to do blind copy paste.

A few lines of code can be audited.

Re:Self Propagating NPM Malware Compromises over 40 Packages by bennyg on Tuesday September 16, 2025 @04:23PM (#45267471)
Sounds like the job for an LLM tool to extract what's actually used from appropriately-licensed OSS modules and paste directly into codebases.
Re:Self Propagating NPM Malware Compromises over 40 Packages by shakna on Tuesday September 16, 2025 @05:18PM (#45268191)
Requiring you to audit both security and robustness on the LLM generated code.

Creating two problems, where there was one.

Re:Self Propagating NPM Malware Compromises over 40 Packages by bennyg on Tuesday September 16, 2025 @07:54PM (#45269859)
I didn't say generate :) - in all seriousness, I think you could reasonably have it copy the code for e.g. lodash.merge() and paste it into your codebase without the headaches you're describing. IMO, this method would be practical for a majority of npm deps in prod code. There are some I'd want to rely on the lib (and its maintenance over time), but also... a sort function is a sort function.
Re:Self Propagating NPM Malware Compromises over 40 Packages by shakna on Tuesday September 16, 2025 @08:44PM (#45270170)
LLMs don't copy and paste. They ingest and generate. The output will always be a generated something.
Re:Self Propagating NPM Malware Compromises over 40 Packages by TheBicPen on Tuesday September 16, 2025 @10:04PM (#45270709)
In 2022, sure. But not today. Even something as simple as generating and running a `git clone && cp xyz` command will create code not directly generated by the LLM.
Re:Self Propagating NPM Malware Compromises over 40 Packages by boomlinde on Thursday September 18, 2025 @06:56AM (#45288106)
In what way do you think this rebuts the message you responded to?
Re:Self Propagating NPM Malware Compromises over 40 Packages by lgas on Wednesday September 17, 2025 @05:44PM (#45281752)
You can give an LLM access to tools that it can invoke to actually copy and paste.
Re:Self Propagating NPM Malware Compromises over 40 Packages by vFunct on Tuesday September 16, 2025 @10:55PM (#45271077)
LLMs can do the audits now.
Re:Self Propagating NPM Malware Compromises over 40 Packages by philipwhiuk on Tuesday September 16, 2025 @04:39PM (#45267705)
Do you have any evidence it wouldn't just make up code.
Re:Self Propagating NPM Malware Compromises over 40 Packages by const_cast on Tuesday September 16, 2025 @06:22PM (#45269005)
This is already a thing, compiled languages have been doing this for decades. This is just C++ templates with extra steps.
Re:Self Propagating NPM Malware Compromises over 40 Packages by kristianbrigman on Tuesday September 16, 2025 @05:26PM (#45268298)
One interesting side effect of AI is that it makes it sometimes easy to just recreate the behavior, perhaps without even realizing it..
Re:Self Propagating NPM Malware Compromises over 40 Packages by reaperducer on Tuesday September 16, 2025 @06:37PM (#45269164)
it's probably even less feasible to rewrite every single dependency from scratch.

When you code in a high-security environment, where bad code can cost the company millions of dollars in fines, somehow you find a way.

The sibling commenter is correct. You write what you can. You only import from trusted, vetted sources.

Re:Self Propagating NPM Malware Compromises over 40 Packages by 8note on Tuesday September 16, 2025 @08:44PM (#45270175)
is it that infeasible with LLMs?

a lor of these dependencies are higher order function definitions, which never change, and could be copy/pasted around just fine. they're never gonna change

Re:Self Propagating NPM Malware Compromises over 40 Packages by motorest on Tuesday September 16, 2025 @09:13PM (#45270363)
> If it's not feasible to audit every single dependency, it's probably even less feasible to rewrite every single dependency from scratch.

There is no need to rewrite dependencies. Sometimes it just so happens that a project can live without outputting fancy colorful text to stdout, or doesn't need to spread transitive dependencies on debug utilities. Perhaps these concerns should be a part of the standard library, perhaps these concerns are useless.

And don't get me started on bullshit polyfill packages. That's an attack vector waiting to be exploited.

Re:Self Propagating NPM Malware Compromises over 40 Packages by smrtinsert on Tuesday September 16, 2025 @09:32PM (#45270519)
Its much more feasible these days. These days for my personal projects I just have CC create only a plain html file with raw JS and script links.