News for hackers. Stuff that matters.
Re:A web of trust for NPM by 7373737373 on Saturday October 03, 2020 @03:33PM (#24674161)
> Some have argued that the ill health of the npm registry is a social, rather than a technical problem

In some cases it is, yes, for packages that require so many access privileges that they can subvert the entire system they run on.

But this is not the case for (I'd estimate) the majority of libraries, because they are purely computational, they only transform data and do not need access rights to any external interfaces (filesystem, network, user input, displays, ...). Malicious data generated by sandboxed programs is still a problem, still the problem would be localized.

There are efforts underway that would allow Javascript programs to effectively and economically sandbox each other and grant only the minimum number of privileges they need to perform their tasks: https://medium.com/agoric/pola-would-have-prevented-the-even...

Avoiding global mutable state and https://en.wikipedia.org/wiki/Ambient_authority, being able to grant rights in an opt-in fashion and to transfer them in a way that is robust in multi-party settings in accordance with https://en.wikipedia.org/wiki/Capability-based_security

This is the https://en.wikipedia.org/wiki/Principle_of_least_privilege and I encourage every language, virtual machine and operating system designer to understand it and implement it in their systems.

Then, the social attack surface can be technically minimized.

Re:A web of trust for NPM by inopinatus on Saturday October 03, 2020 @04:50PM (#24674574)
So basically, rely on about 5% of JavaScript (my copy of JavaScript: The Good Parts is looking slimmer every day) and hope that everything you’re either directly or transitively exposed to has exactly the same standards you do and will continue to do so in perpetuity, and/or build tons of additional scaffolding to try to sandbox violators, because that has always been such a sure fire path to secure code.

The language, and it’s ecosystem, is a baroque Gormenghast of curiosities built on an ancient sewer where nightmare beasts still roam, and you’ll never stop it stinking just by holing up in the throne room and hoping a few trusted paladins will decontaminate the rest.

Re:A web of trust for NPM by cgh on Saturday October 03, 2020 @06:05PM (#24675029)
An excellent comment that merits upvotes based on the Gormenghast reference alone.
Re:A web of trust for NPM by markholmes on Saturday October 03, 2020 @05:12PM (#24674711)
So what’s the best way out?
Re:A web of trust for NPM by inopinatus on Saturday October 03, 2020 @05:33PM (#24674823)
New languages, new paradigms at the foundations.

We keep throwing new shit at the wall, eventually something sticks. To a whole generation of developers it might like like JavaScript is the One True Web Programming Language but anyone whose lived through a few transitions knows that we replace entrenched technologies on the scale of decades, it has come and it will go like everything else, sic transit gloria lingua.

The usual (but not universal) trigger is a technological arms race between three or more competing firms attached to a compelling new idea.

Re:A web of trust for NPM by alquemist on Saturday October 03, 2020 @11:45PM (#24676395)
Not sure how a new language can help with an ecosystem problem. In the old days, people write your own code and relied on a vendor provided standard lib, for example C++ stdlib, Java platform or Python's batteries included. Since software is expensive, to save time and money people started to rely on 3rd party libraries, conveniently delivered by package repositories, for example CPAN, PyPI or npm. A new language will be subject to the exact same cost and delivery deadline pressures. If anything, newer languages tend to have ecosystems even more dependent of 3rd party modules. The PL problem is largely solved, the ecosystem problem is not.
Re:A web of trust for NPM by inopinatus on Sunday October 04, 2020 @05:05AM (#24677412)
I think the fragmented chaos of the JS ecosystem arises as much from the structure of the language as it does the dismal standard library.

That said, I don't buy that language vendors skimp on their standard library due to some marginal cost issue. Quite the opposite, commercial PLs like Go, Kotlin, Swift and the .NET CLI family come with extensive and often surprisingly well-considered standard libraries, and even open-source projects do better than JS (the standout being probably Elixir since it inherits Erlang/OTP). The idea that JS's ecosystem is the template for future languages seems unsound, which is thankfully a relief since it would also be so disheartening.

Re:A web of trust for NPM by cxr on Sunday October 11, 2020 @04:43PM (#24748930)
> chaos of the JS ecosystem arises as much from the structure of the language as it does[...]

Not really. It arises from Sturgeon's law and the matter of accessibility/popularity. The problems of "the JS ecosystem" (correctly stated: the problems with the NPM and its community) are the same problems that plagued Java 15 years ago. (On the other hand, Java at least attempted in its design to enforce good practices at the language level instead of giving everyone an empty canvas, which in the JS world has been considered to be an endorsement that one can and should go absolutely nuts.)

Related: http://mnielsen.github.io/notes/engelbart/engelbart.html#sli...

Re:A web of trust for NPM by inopinatus on Wednesday October 14, 2020 @07:58AM (#24775541)
Sturgeon's law is universal, and it doesn't explain differences in the distribution of the crap.

> Java at least attempted in its design to enforce good practices at the language level instead of giving everyone an empty canvas

I put it to you that this is recognising that the structure of the language is significant in the emergent behaviours and consequences.

> problems with the NPM and its community

I think it is scoped much more broadly. The major browser vendors are all horrendously self-serving, for example.

Re:A web of trust for NPM by cxr on Wednesday October 14, 2020 @09:33AM (#24776316)
> Sturgeon's law is universal, and it doesn't explain differences in the distribution of the crap.

What differences in distribution? You're either not absorbing what I wrote, or what Sturgeon said, or some combination of both. Sturgeon was responding to the criticism that sci-fi as a genre is bad because of how much of it is crud. Sturgeon's retort was that "Ninety percent of everything is crud."

JS is incredibly accessible and, as a result, massively popular (just like Java). 90% of a large number is a large number.

> I put it to you that this is recognising that the structure of the language is significant in the emergent behaviours and consequences.

Have a reread. Java attempted to enforce good practices by language design. And yet, Java is the posterchild of the sentiment that goes, roughly, "Java sucks—after all just look at its programmers and the ecosystem is has produced". (I.e., the same thing people say about JS.) But Sturgeon's law is inescapable. Despite the attempt, the Java ecosystem looks like crud. Why? Because Java is extremely popular, and 90% of everything is crud, and 90% of a large number is a large number.

> The major browser vendors are all horrendously self-serving, for example.

They are. It has very little to do with the NPM mess. NodeJS and the browser are at odds, with NodeJS having forked the language. (Just look at modules: NodeJS has a known-bad, non-standard module system, and there was serious discussion about whether it would even ever support ECMAScript's standard modules.)

Re:A web of trust for NPM by RL_Quine on Saturday October 03, 2020 @03:40PM (#24674190)
I don't think that the same community producing huge quantities of single use libraries for the sake of padding their resumes will get involved with sandboxing. I recently installed a relatively simply piece of software using NPM and was stunned when it downloaded hundreds dependencies from god knows where, there's simply no ability for anybody to ever evaluate the security risk of NodeJS applications.

https://npm.anvaka.com/#/view/2d/zigbee2mqtt

Re:A web of trust for NPM by Chyzwar on Saturday October 03, 2020 @04:09PM (#24674354)
This module use widely used packages in node. In any non-trivial node project you would already have these. Whole point of small single use packages is to prevent from re-inventing a wheel. People are bashing node community without understanding.

Typical you would have people publish hundreds similar packages to solve a specific problem. Over time, best maintained, feature complete would "win" and become a standard, at this point other packages would converge and use these 1/2 top solutions. This process allow exploring large space of possible solutions and prevent app developers from NIH. There is more churn, but also more innovation and productivity.

See for example css-in-js evolution story. https://www.youtube.com/watch?v=75kmPj_iUOA

Re:A web of trust for NPM by 7373737373 on Saturday October 03, 2020 @03:41PM (#24674197)
Then perhaps single use libraries should be limited to 'computation only' by default :)
Re:A web of trust for NPM by cxr on Saturday October 03, 2020 @06:55PM (#24675285)
> there's simply no ability for anybody to ever evaluate the security risk of NodeJS applications

So don't. Tell people that you're not going to run their NodeJS crud and let them know it would be better to write their scripts wherever possible to be able to run on the sandboxed JS runtime that everyone already happens to have installed: the browser.

https://news.ycombinator.com/item?id=24495646

Re:A web of trust for NPM by IggleSniggle on Saturday October 03, 2020 @07:20PM (#24675401)
I really like this idea, but it misses the appeal of nodejs and its ilk...that you can speak the same JSON-native language on the backend as the front.

I think it’s a VERY interesting idea to use a browser for running some tooling, but that’s really just what the idea behind nodejs and deno etc are, aren’t they? It’s just that node tries to be convenient by providing access to things that would need in a non-user context (like filesystem and C interop), thereby breaking the sandbox. Deno tries to give you the best of both.

Running this stuff in the browser is still “just running on V8”, but with extra steps. If you don’t like the npm ecosystem, I get it, but then running nodejs without any packages is comparable to what you’re describing in the link, isn’t it?

Re:A web of trust for NPM by cxr on Sunday October 11, 2020 @04:30PM (#24748844)
> that’s really just what the idea behind nodejs and deno etc are, aren’t they?

Yeah, I guess they're pretty much the same thing, except for all the stuff I mentioned.

> Running this stuff in the browser is still “just running on V8”, but with extra steps.

I don't know what this is supposed to mean. I don't know where this quote comes from, or what it's even trying to say. Nobody starts out with a computer with NodeJS and Deno installed and then has to go install a browser. Everyone already has a browser, on the other hand, and it's standardized and forward-compatible by design/commitment. From that perspective, NodeJS and Deno are '"just running on V8", but with extra steps' (truly—V8 exists for the Web browser and has only incidentally been lifted out and made to drive NodeJS, too—after a lot of contortions).

> you can speak the same JSON-native language on the backend as the front

Huh? Not only does this not make sense, but the backend appeal of NodeJS is completely irrelevant in matters of metatooling, aka "devDependencies" in NodeJS terms.

Re:A web of trust for NPM by IggleSniggle on Saturday October 03, 2020 @07:03PM (#24675320)
It looks like the library you are referencing touches lots of different proprietary hardware? While I agree with your overall point, a “universal wrapper” for lots of different things is exactly the sort of thing I would expect to have dependencies from who the heck knows where.
Re:A web of trust for NPM by slaymaker1907 on Saturday October 03, 2020 @03:37PM (#24674181)
More languages should really be doing this and encouraging it. The JVM can sandbox pretty well using a security manager, but most people don't use the sandbox.
Re:A web of trust for NPM by 7373737373 on Saturday October 03, 2020 @03:41PM (#24674192)
Only very few language also provide the type of security the JVM (partially) protects against: resource exhaustion attacks. Being able to prevent time (e.g. infinite loops) and space (memory allocation) exhaustion by being able to specify absolute or relative limits on these.

Stackless Python is able to limit the number of instruction steps that are run in a tasklet: https://stackless.readthedocs.io/en/latest/library/stackless...

With some ugly hacks, Lua can do it too.

But no language I know of can do all these things, I tried to build one once: https://esolangs.org/wiki/RarVM

Re:A web of trust for NPM by geofft on Saturday October 03, 2020 @04:08PM (#24674350)
The principle of least privilege/authority has been around for a while, and the reason we don't see much adoption of it in real-world systems is not because it's unknown.

The first question is overhead: it's true that the majority of libraries are purely computational, but that means that there's frequent interaction between code written by the end developer and code from the library. If every call to, say, lodash's _.filter goes through a process to marshal the programmer's list, send it to a separate execution environment, and then marshal it right back in the other direction to call the predicate, people would choose not to use it. I do agree that the proposal in the post you link to seems to be on the right track - directly run the code in the current execution environment if it can be statically demonstrated that the code has no access to dangerous capabilities.

The second question is making the policy decision about whether to grant privileges. You might be familiar with this from your mobile phone: the security architecture is miles better than that of your desktop OS, but still, most people do say "yes" when asked to let Facebook, Twitter, Slack, etc. access their photos and their camera and their microphone, because they intentionally want those apps to have some access. What do you do in the above model when, say, the "request" library wants access to the network? Now it can exfiltrate all of your data. (The capability-based model is that you pass into the library a capability to access the specific host it should talk to, instead of giving it direct access, but again, if it did this, people would choose not to use it - the whole point of these libraries is to make writing code more convenient.)

The other problem, and perhaps the most important, is that purely-computational libraries can still be dangerous. Yes, _.filter (and perhaps all of lodash) is purely computational, but if you're using it to, say, restrict which user records are visible on a website, and someone malicious takes over lodash, they can edit the filter function to say, "if the username is me, don't filter anything at all." Or if you had a capability-based HTTP client that only talked to a single server, the library could still lie about the results that it got from the server.

I think the way to think about it is that the principle of least privilege is a mitigation strategy, like ASLR or filtering out things that look like SQL statements from web requests. ASLR mitigates not being able to guarantee that your code is memory-safe; if you could, you wouldn't need it. SQL filtering mitigates making mistakes with string interpolation (but it comes with a significant cost, so you really want to avoid it if you can). Least privilege mitigates the reality that you cannot code-review all of your code and its dependencies to ensure that it's free of bugs. But, on the other hand, a mitigation is not a license to stop doing the thing you can't do perfectly - it's just a safety measure. You can still have serious security bugs from buffer overflows even with ASLR; you just have fewer. You should not use ASLR as an excuse to write memory-unsafe code. You can still have SQL injection attacks from people being clever about smuggling strings. You should not use a WAF as an excuse to not use parametrization in SQL queries. And you can still have malicious dependencies cause problems even in a least-privilege situation, because they still have some privilege. You should not use it as a reason to run dependencies you don't trust.

Re:A web of trust for NPM by 7373737373 on Sunday October 04, 2020 @04:39AM (#24677326)
> there's frequent interaction between code written by the end developer and code from the library

Microkernel operating systems that use capability security like KeyKOS or one of its distant successors, sel4 focus on optimizing the call procedure as best as they can. A small performance overhead for guaranteed security properties shouldn't be seen as a tradeoff.

>send it to a separate execution environment, and then marshal it right back[...]

Current runtimes of all kinds always need new instances of something to sandbox things, which incurs a big overhead everytime. But it doesn't have to be this way. The KeyKOS kernel was of fixed size, I built my https://esolangs.org/wiki/RarVM to be so, too, it is stateless. No need for several instances of the interpreter itself, and minimal overhead in the process snapshots.

>policy decision about whether to grant privileges [...] people would choose not to use it

The advantage of capability systems (that start with all rights given in every call by default) is that even if people do not initially use it, they can restrict rights later - "hollow out the attack surface", when this makes economical sense - when a library becomes popular, laws or contracts require it etc.

While users may not interact with it directly or choose not to use it, such systems grant developers at least the ability to secure their software internally, something that is not even possible now.

> [...] it's just a safety measure [...] purely-computational libraries can still be dangerous

But this argument doesn't attack the central point. Yes, this is true, but has nothing to do with the security properties offered by POLA architectures like capability security. It's an orthogonal problem, which has to be mitigated by other mechanisms, possibly social.

Re:A web of trust for NPM by geofft on Sunday October 04, 2020 @12:02PM (#24679971)
I think we're disagreeing on what the central point is, then. I think least-privilege architectures are great, and I use them for many things. I think they do not save you from the problem being addressed in this article. That is, do not read what I'm saying as an argument against least-privilege architectures: read it as an argument against using that hammer to drive in this screw.

In turn, I think that means that there isn't enough justification for using them in this case that users will feel like the additional complexity of wiring through least-privilege across their libraries is worth it. Even if you take the approach of incrementally adding the security to the existing design, the implication is it won't actually be securing end users for a long time, and only against minor and unlikely threats at first, but it will impose increasing complexity all along.

See also this excellent post about mitigations: http://addxorrol.blogspot.com/2020/03/before-you-ship-securi...

KeyKOS is great and I've read about it and tried to adopt its lessons in my own designs, but the fact remains that KeyKOS is dead. And I certainly agree that a small performance overhead for guaranteed security properties shouldn't be seen as a tradeoff (assuming it is in fact solely a performance overhead, and not a developer mental burden, nor a reviewer mental burden, nor an operational burden) - but I'm not commenting on what I see, I'm commenting that the vast majority of NPM users will see it as a tradeoff, regardless of what you and I believe.

Re:A web of trust for NPM by sergeykish on Saturday October 03, 2020 @04:37PM (#24674507)
Reminds of Gilad Bracha Newspeak.
Re:A web of trust for NPM by 7373737373 on Sunday October 04, 2020 @05:39AM (#24677596)
While most Smalltalk-like languages are good candidates for such security mechanisms, they have never been integrated, perhaps because the mostly academic environment in which they are developed is more cooperative than malicious.
Re:A web of trust for NPM by stefan_ on Saturday October 03, 2020 @05:27PM (#24674794)
Trying to solve the halting problem are we. Remember that one of the most dangerous JavaScript APIs turned out to be a sub-millisecond monotonically increasing time source.
Re:A web of trust for NPM by samatman on Saturday October 03, 2020 @05:50PM (#24674929)
Solving the halting problem is quite tractable.

You can do it the right way, by using total functional programming. Or you can do it the wrong way, by providing a time budget or "gas", and yanking the process if and when it's exceeded.

No, this is more of a Rice's Theorem kind of situation...

Re:A web of trust for NPM by 7373737373 on Sunday October 04, 2020 @04:20AM (#24677279)
Why do you think using 'gas' is the wrong way? Not only does it solve this problem, it solves it in a deterministic way, which has many applications, for example deterministic debugging and replicable computation!
Re:A web of trust for NPM by samatman on Sunday October 04, 2020 @04:09PM (#24681899)
I don't, actually.

What I really meant was that total functional programming is the MIT way to do it, and gas caps or supervisors are the New Jersey way to do it.

Re:A web of trust for NPM by matheusmoreira on Saturday October 03, 2020 @08:08PM (#24675660)
> one of the most dangerous JavaScript APIs turned out to be a sub-millisecond monotonically increasing time source

Details?

Re:A web of trust for NPM by acemarke on Saturday October 03, 2020 @09:03PM (#24675874)
Pretty sure that's a reference to the Spectre CPU timing attacks and JS's SharedArrayBuffer type being used to construct timers as an attack vector:

https://v8.dev/blog/spectre