News for hackers. Stuff that matters.
Re:Dozens of malicious PyPI packages discovered targeting de... by erustemi on Wednesday November 02, 2022 @05:29PM (#33443167)
I think a proper way to solve this issue, not specific to python but languages running in a VM in general, would be to have some sort of language support where you specifically define what access rights/ system resources you allow for any given dependency.

Example of defining project dependencies:

  {
    "apollo-client": {
      "version": "...",
      "access": ["fetch"] // only fetch allowed
    },
    "stringutils": {
       "version": "...",
       "access": [] // no system resources allowed for this dependency, own or transitive
    },
    ...
  }
It would probably require the language to limit monkey-patching core primitives (such as Object.prototype in javascript), and it would be more cumbersome for the developer to define the permissions it gives to each dependency. These required permissions could be listed on the package site (eg npm or PyPI) and the developer would just copy paste the permissions when adding the dependency. But if you upgrade a dependency version and it now requires a permission that seems suspicious (eg "stringutils" needing "filesystem"), it would prompt the developer to stop and investigate, or if it seems justified add the permission to "access" list.
Re:Dozens of malicious PyPI packages discovered targeting de... by louislang on Wednesday November 02, 2022 @05:38PM (#33443270)
This is one of the projects we're working on (and open sourcing)!

Currently allows you to specify allowed resources during the package installation in a way very similar to what you've outlined [1].

The sandbox itself lives here [2] and can be integrated into other projects.

1. https://github.com/phylum-dev/cli/blob/main/extensions/npm/P...

2. https://github.com/phylum-dev/birdcage

Re:Dozens of malicious PyPI packages discovered targeting de... by c0balt on Wednesday November 02, 2022 @05:42PM (#33443301)
At the beginning the permissions aspect of deno[0] was actually on of the major selling points for me. The approach used there was to begin at zero and offer granular permission control, e.g. `--allow-read=data.csv`, for filesystem, network etc. I would love to have this for, e.g., python or npm packages.

[0]: https://deno.land/[email protected]/getting_started/permissions

Re:Dozens of malicious PyPI packages discovered targeting de... by jens0 on Wednesday November 02, 2022 @05:44PM (#33443322)
Doesn't this only apply to the entire process? Not the individual dependencies, right? Just confirming, Deno was my first thought with this, it requires the developer to deliberately enable permissions needed.
Re:Dozens of malicious PyPI packages discovered targeting de... by SahAssar on Wednesday November 02, 2022 @06:26PM (#33443761)
Yes, it applies to the whole process. It's incredibly hard to sandbox dependencies individually since you don't know how your code or other dependencies interact with it. If you want you can run dependencies in a worker process and sandbox that tighter, but that is quite a bit of work.
Re:Dozens of malicious PyPI packages discovered targeting de... by ashishbijlani on Wednesday November 02, 2022 @07:24PM (#33444253)
That’s exactly why I use strace-based to sandbox ALL dependencies: https://github.com/ossillate-inc/packj
Re:Dozens of malicious PyPI packages discovered targeting de... by juancampa on Wednesday November 02, 2022 @09:37PM (#33445632)
This is exactly what I've done for Membrane[0]. It's capabilities based, even to get the time (and thus introduce non-determinism) you need a capability. Dependencies run as separate processes and everything is orthogonally persistent. It's a typescript/javascript system for personal automation built entirely within VSCode. Stay tuned, I'll be posting a video this week.

[0] https://membrane.io

Re:Dozens of malicious PyPI packages discovered targeting de... by uhhyeahdude on Thursday November 03, 2022 @04:44AM (#33448487)
Hi there! I just wanted to let you know that I read the blog posts, and membrane sounds extremely cool. Ambitious, though. If you don’t mind a small bit of feedback: it would be encouraging to potential users or testers to see some semi-regular posts related to development. It would also be great to see how membrane might work to build a tool using current APIs. I know there is video forthcoming, and perhaps this will be addressed. I didn’t look at the GitHub, where I probably could glean some additional info. But from my perspective, a development blog builds trust and anticipation. It’s also a great way to check your assumptions (or have them checked, rather).

Good luck with the project. I hope it delivers, because I’d love to use it. Signed up for the mailing list.

Re:Dozens of malicious PyPI packages discovered targeting de... by louislang on Wednesday November 02, 2022 @05:50PM (#33443388)
Phylum's extension framework is built on Deno for this exact reason. The ability to provide granular permissions was something we were really interested in.

Deno is a really cool project, imo.

Re:Dozens of malicious PyPI packages discovered targeting de... by comprev on Wednesday November 02, 2022 @06:26PM (#33443750)
Interesting read, thanks.
Re:Dozens of malicious PyPI packages discovered targeting de... by berniedurfee on Wednesday November 02, 2022 @05:52PM (#33443404)
Yep, a declarative mechanism would be nice like OAuth scopes.

Though, like scopes, I think many times packages would need broad access, but maybe not?

Re:Dozens of malicious PyPI packages discovered targeting de... by rileymat2 on Wednesday November 02, 2022 @05:52PM (#33443414)
I thought that Java Applets (and maybe flash, I am less familiar) had an advanced security model, but it was exploit after exploit because of the huge attack surfaces?

I suspect you may run into similar sandbox escapes once things are complicated enough. So it seems like a good idea if they can be made bug free, but good luck with that?

Re:Dozens of malicious PyPI packages discovered targeting de... by erustemi on Wednesday November 02, 2022 @06:06PM (#33443573)
Maybe the issue was with how powerful and unrestricted reflection was in java before introduction of modules.
Re:Dozens of malicious PyPI packages discovered targeting de... by insanitybit on Wednesday November 02, 2022 @05:58PM (#33443476)
Part of the problem with the Java sandbox is that it was enforced entirely by the VM + the VM is written in C++. The idea is not inherently bad.
Re:Dozens of malicious PyPI packages discovered targeting de... by nl on Wednesday November 02, 2022 @06:21PM (#33443715)
It's been a while since I worked in this area but my recollection was that most JVM security issues in this areas were bypasses of the Java Security Manager often by confusing it about code origin. That's all Java code, not C++.
Re:Dozens of malicious PyPI packages discovered targeting de... by insanitybit on Wednesday November 02, 2022 @06:26PM (#33443752)
It's been so long I could be remembering incorrectly.
Re:Dozens of malicious PyPI packages discovered targeting de... by int_19h on Thursday November 03, 2022 @06:52AM (#33449251)
For both Java and .NET, there were actual verification bugs, as well - when bytecode that's not supposed to be valid gets past the verifier and results in e.g. mistyped references (which can then be used for all kinds of creative vtable abuse). Sometimes it can even be a bug in the VM spec itself, because implications of two different features interacting weren't fully considered.

But, yes, we've tried this idea many times now, and it never held up for long.

Re:Dozens of malicious PyPI packages discovered targeting de... by jjav on Wednesday November 02, 2022 @05:53PM (#33443419)
This is essentially the fine-grained control the Java Security Manager enabled. But hardly anyone used it and it was deprecated sadly.
Re:Dozens of malicious PyPI packages discovered targeting de... by charleslmunger on Wednesday November 02, 2022 @07:34PM (#33444364)
And it didn't really work in practice. Every callback or thread hop is a security vulnerability by default.
Re:Dozens of malicious PyPI packages discovered targeting de... by uncletammy on Wednesday November 02, 2022 @05:54PM (#33443442)
Your proposed solution sounds an awful lot like a manifest file

https://en.wikipedia.org/wiki/Manifest_file

Re:Dozens of malicious PyPI packages discovered targeting de... by insanitybit on Wednesday November 02, 2022 @05:56PM (#33443454)
I've been messing around with some ideas.

1. `autobox` (to be renamed lol) [0]. It's basically a Rust interpreter that performs taint and effect analysis, reporting on both, allowing you to use that information to generate sandboxes. ie: "autobox sees you used the string '~/.config' to read a file, and that is all the IO performed, so that is all the IO you get".

2. I'm working on a container based `cargo` with `riff` built in that aims to work for the vast majority of projects and sandbox your build with a defined threat model.

The goal is to be able to basically `alias cargo=cargo-sandboxed` and have the same experience but with a restricted container environment + better auditing of things happening in the container.

3. I previously built a POC of a `Sandbox.toml` and `Sandbox.lock` with a policy language that allowed you to specify a policy for a given build step. Unfortunately, I couldn't decide on how I wanted it to work in terms of "do I generate a single sandbox for the entire build, or do I run each build stage in its own sandbox" - there are tradeoffs for both.

Here's a lil snippet:

    [build-permissions.file-system]
    // All paths are relative to the project directory unless they start with `/`
    "../" = {permissions = ["read"]}
    // "$target" being a special path
    "$target" = {permissions = ["read", "write"]}
    // Source this path from the environment at build time, `optional` means it's
    // ok if it isn't available
    "$env::PROTOC_PATH" = {permissions = ["read", "execute"], optional=true}
    // Default protobuf installation paths, via regex
    "^(/usr)?/bin/protoc" = {permissions = ["read", "execute"], regex=true}

Once I'm done with (2) though I think I'll tackle (3).

`autobox` is fun but I think it may be impractical without more language level support and no matter what I'd end up having to implement it in the compiler at some point, which means it would be unusable without nightly or a fork.

I'm going to try to wrap up an autobox POC that handles branching and loops, publish it, and see if someone who does more compilery things is willing to pick it up. As for (2) and (3) I believe I can build practical implementations for both.

[0] https://github.com/insanitybit/autobox/

Re:Dozens of malicious PyPI packages discovered targeting de... by louislang on Wednesday November 02, 2022 @05:59PM (#33443495)
This is really cool work! Also a fan of Grapl.
Re:Dozens of malicious PyPI packages discovered targeting de... by insanitybit on Wednesday November 02, 2022 @06:01PM (#33443508)
:D Thanks!
Re:Dozens of malicious PyPI packages discovered targeting de... by nicoty on Wednesday November 02, 2022 @06:04PM (#33443552)
I watched a video[0] about the Roc language recently, and they do something interesting to address this: they have a layer in their language called "platforms" and the idea behind these are that there are many different platforms that you can choose between to run code with and each one has different permissions. So one platform might be sandboxed and disallow the use of certain unsafe APIs whereas another might be less sandboxed.

[0] https://m.youtube.com/watch?v=cpQwtwVKAfU

Re:Dozens of malicious PyPI packages discovered targeting de... by nijave on Wednesday November 02, 2022 @06:12PM (#33443642)
I saw a similar proposal (I think with JavaScript/node) not too long ago that deacribed limiting packages to data in their own namespace. For instance third-party-dep-a would only have access to data it created or was passed in versus indiscriminately accessing anything in the language VM. Even this would be a good step in the right direction although you'd likely still need something like you e described for accessing shared system resources (aka the mobile phone security model)
Re:Dozens of malicious PyPI packages discovered targeting de... by Legogris on Wednesday November 02, 2022 @06:13PM (#33443653)
For JS, You are basically talking about Lavamoat. It provides tooling and policies for SES, which aims to make it into standards.

https://github.com/LavaMoat/LavaMoat

https://github.com/endojs/endo/tree/master/packages/ses

Re:Dozens of malicious PyPI packages discovered targeting de... by dheera on Wednesday November 02, 2022 @06:16PM (#33443679)
Another thing I think might help is

(a) Discourage any future use of ">=" in version dependencies. Specify an exact version. That way a future compromised version doesn't get pulled

(b) Every build system needs better ways of having multiple versions of a same dependency coexist. I should be able to have one of my project's dependencies depend on "numpy==1.15" and another dependency depend on "numpy==1.16" and they should be able to coexist in the SAME environment and "see" exactly the numpy versions they requested.

For python we should think about how to support something like this in the future:

    import numpy==1.15
and have it just work.

That way if a hacker compromises PyPI and releases a malicious numpy 1.19 it won't get pulled in accidentally.

Here's a bit of a joke I made before that might be an interesting starting point, though since it uses virtualenv behind the hood it doesn't have a way for multiple versions of one package to exist. I don't think it's impossible to do though with some additional work.

https://github.com/dheera/magicimport.py

Sample code:

    from magicimport import magicimport
    tornado = magicimport("tornado", version = "4.5")
Re:Dozens of malicious PyPI packages discovered targeting de... by cozzyd on Wednesday November 02, 2022 @06:56PM (#33444020)
Would you run into dynamic linker problems in this case due to symbol conflicts? Or does symbol versioning magically resolve that somehow?
Re:Dozens of malicious PyPI packages discovered targeting de... by dheera on Wednesday November 02, 2022 @07:21PM (#33444239)
Prefix all symbols with versions?

foo() becomes v1_15_4_foo() automatically

Re:Dozens of malicious PyPI packages discovered targeting de... by MikePlacid on Wednesday November 02, 2022 @07:00PM (#33444059)
> I should be able to have one of my project's dependencies depend on "numpy==1.15" and another dependency depend on "numpy==1.16" and they should be able to coexist in the SAME environment

Now I see what people at one respectable, big project were thinking when they allowed 7 different versions of OpenSSL to be statically linked to the same executable…

Seriously, this idea may save you from some not very interesting work, but it will create the need of much bigger amount of work which while potentially interesting is not very productive. You are toying with exponential growth here, like a chain reaction - like a bomb.

Re:Dozens of malicious PyPI packages discovered targeting de... by rollcat on Wednesday November 02, 2022 @06:32PM (#33443806)
Check out OpenBSD's pledge(2): https://man.openbsd.org/pledge.2

It does exactly that (although on a per-process basis).

I don't think this kind of permission system can be retrofitted into an existing language without direct OS support, and probably not at the library level (you'd need something like per-page permissions which would get hairy real fast).

Re:Dozens of malicious PyPI packages discovered targeting de... by musicale on Wednesday November 02, 2022 @06:51PM (#33443968)
I like this. I'd try to keep the permission sets as small, limited, and simple as possible though.
Re:Dozens of malicious PyPI packages discovered targeting de... by rollcat on Wednesday November 02, 2022 @06:52PM (#33443975)
> I'd try to keep the permission sets as small and simple as possible though.

You've described OpenBSD in general. I recommend a deeper dive - it's fantastically refreshing, how simple yet functional an OS can be.

Re:Dozens of malicious PyPI packages discovered targeting de... by paulmd on Wednesday November 02, 2022 @11:37PM (#33446683)
Same for FreeBSD. Incredibly code-stable and well-documented by Linux standards.

I often use the FreeBSD Handbook as an example of first-party documentation done right, and that's only possible because of deliberately limited "churn for churn's sake". The kinds of regular code rot and attrition that Linux suffers just does not take place on BSD systems because if you contribute something new you're expected to make your thing mesh with the ecosystem, they don't tolerate the "I'm gonna churn everyone's environments because my version is 10% better than the existing one" that tends to take place on Linux.

As an example, the amount of init systems that Ubuntu has gone through over the last 20 years is completely insane by BSD standards. They've gone from sysvinit to upstart to systemd. You don't have people ripping out the graphics and audio subsystems and doing total rewrites, either. It's nuts that a lot of Linux people don't even realize that it doesn't have to be that way - that's not "just how maintenance is supposed to work", that's a bunch of incredibly bad behavior on the parts of distros and Poettering specifically that has become highly normalized and overlooked. Maintenance shouldn't be breaking things like that. "we never break userland" doesn't have to be a suicide pact either - BSD has actually maintained a much more stable ABI than the linux kernel without crystallizing a bunch of shitty bug-compatibility stuff like Linux is doing either. It's all insanely stable and competent and professional by linux standards.

If I was developing a product for true long-term support, with the minimum possible engineering effort devoted to fighting churn, BSD would be at the top of the list.

Re:Dozens of malicious PyPI packages discovered targeting de... by CoolCold on Thursday November 03, 2022 @04:35AM (#33448432)
And with all that beauty, FreeBSD is not something I would [nowdays] look into as base OS for hosting my services and products. It means something, probably something about humans.
Re:Dozens of malicious PyPI packages discovered targeting de... by rollcat on Thursday November 03, 2022 @06:44AM (#33449202)
Netflix uses FreeBSD for their CDN/edge caches - it was consistently more performant both in benchmarks and with real-world workloads.
Re:Dozens of malicious PyPI packages discovered targeting de... by CoolCold on Friday November 04, 2022 @04:14AM (#33463433)
Yeah, that's quite interesting reading from them, some sort of specialized appliance really.

I'm and the average Joe around me, totally far from Netflix's task of packing bytes from disk to network. Simple 2vCPU VPS serving 4GBit without being saturated on system resource level is quite often much more than enough. Extra note - it's not even using kTLS.

Moreover, even for Netflix, noting they know FreeBSD in and out, do you think/have info on using FreeBSD as base OS beyond distribution level - running applications/services in particular?

I've quickly checked on their repos like https://github.com/Netflix/conductor and it smells like they use containers/Docker, which doesn't work on FreeBSD => I'm in very much doubts it's OS of choice for them.

Re:Dozens of malicious PyPI packages discovered targeting de... by washadjeffmad on Thursday November 03, 2022 @09:30AM (#33450660)
What attracted me to Linux so long ago is what ultimately drove me away. I now apply it only as needed because it's no longer simple ("stable" over the timescales I'm interested in) as a project, and it's not moving towards any type of consistency.

If you read "rolling stones gather no moss" to mean "keep moving or risk becoming obsolete", choose Linux. If you understand it as "change for change's sake prevents the achievement of mastery", go with a BSD.

Re:Dozens of malicious PyPI packages discovered targeting de... by dilawar on Wednesday November 02, 2022 @09:21PM (#33445467)
I think @jart has been porting it to Linux https://justine.lol/pledge/ .
Re:Dozens of malicious PyPI packages discovered targeting de... by jart on Thursday November 03, 2022 @04:12AM (#33448295)
Indeed! If your dependencies are able to be command line programs that are shell scripted together, then you can in fact have an access policy on a per-dependency basis, using the pledge.com program linked on my website. So shell scripters rejoice.

But it gets better. If you build Python in the Cosmopolitan Libc repository:

    git clone https://github.com/jart/cosmopolitan
    cd cosmopolitan
    build/bootstrap/make.com -j8 o//third_party/python/python.com
Then you can use cosmo.pledge() directly from Python.

    $ o//third_party/python/python.com
    Python 3.6.14+ (Actually Portable Python) [GCC 9.2.0] on cosmo
    Type "help", "copyright", "credits" or "license" for more information.
    >>: import cosmo, socket
    >>: cosmo.pledge('stdio rpath wpath tty', None)
    >>: print('hi')
    hi
    >>: socket.socket()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/zip/.python/socket.py", line 144, in __init__
        _socket.socket.__init__(self, family, type, proto, fileno)
    PermissionError: [Errno 1] EPERM/1/Operation not permitted
Since we didn't put "inet" in the pledge, you can now be certain your PyPi deps aren't spying on you or uploading your bitcoin wallet to the cloud. You can even use os.fork() to rapidly put each dependency in its own process, then call cosmo.pledge() afterwards to grant each component of your app its own maximally restrictive policy.

Cosmopolitan Python also ports OpenBSD's unveil() system call to Linux too. For example, to disallow all file system access, just call cosmo.unveil(None, None). You need a very recent version of Linux though. For instance, I use unveil() in production on GCE but I had to apt install linux-image-5.18.0-0.deb11.4-cloud-amd64 in order for Landlock LSM to be available to use unveil().

Re:Dozens of malicious PyPI packages discovered targeting de... by gjadi on Thursday November 03, 2022 @10:59AM (#33452040)
I thought the thread model of pledge/unveil was to restrict a program that you are writing, but that you couldn't wrap around other program in a safe way.

That is, you can protect your own program from doing network stuff because of incorrect input, but you can't use it to sandbox another program.

See this thread: https://marc.info/?t=162367803300003&r=1&w=2 and this mail about sandboxing: https://marc.info/?l=openbsd-tech&m=162367954705721&w=2

Re:Dozens of malicious PyPI packages discovered targeting de... by jart on Thursday November 03, 2022 @12:50PM (#33453813)
You can, if you use pledge() and unveil() on Linux. SECCOMP and Landlock use a monotonically decreasing permissions model. It's inherited across exec(). This is a good thing. OpenBSD devs don't need it because they built their own hermetic system. They're more afraid of having their servers compromised remotely than they are of programs they've installed locally. The tradeoff is you can't use pledge() and unveil() to build your own SSH server on Linux, since SSH needs to shed restrictions when launching a shell. But the benefit is you can safely leverage more code written by strangers on the Internet, which is what Linux is all about.
Re:Dozens of malicious PyPI packages discovered targeting de... by mrlemke on Thursday November 03, 2022 @09:17AM (#33450478)
I thought of OpenBSD too since it includes Perl modules for OpenBSD::Pledge and OpenBSD::Unveil. Now I'm wondering if I can get something to work where these are used before importing CPAN modules to reduce the damage of potentially hostile modules.
Re:Dozens of malicious PyPI packages discovered targeting de... by ransom1538 on Wednesday November 02, 2022 @06:41PM (#33443874)
It's only a matter of time, until, someone with some cash + a good connection to a package just does what is going to happen.
Re:Dozens of malicious PyPI packages discovered targeting de... by p1necone on Wednesday November 02, 2022 @06:44PM (#33443902)
You could remove the need to explicitly specify the permissions somewhat by enforcing semver for permission addition.

If you own a package at version 1.X.X and you want to add a permission requirement you have to bump the version to 2.0.0. If you also allow people to opt in to a less strict "auto allow all the currently required permissions for these dependencies" mode, they would at least know for sure nothing can touch anything new unless they explicitly bump the major version.

If you're extra concerned about security you can explicitly specify them so it's really obvious when a major version bump adds new ones, but it removes some of the friction.

Re:Dozens of malicious PyPI packages discovered targeting de... by e1g on Wednesday November 02, 2022 @07:20PM (#33444236)
Node.js is building something very similar: Permission Model https://github.com/nodejs/security-wg/issues/791
Re:Dozens of malicious PyPI packages discovered targeting de... by ciupicri on Wednesday November 02, 2022 @07:30PM (#33444320)
There were some attempts made for Python 10 - 15 years ago and the conclusions were that it's very hard to do it right. If I remember correctly Zope was using some sandboxing and because of it, it took a while time to catch up with newer versions of Python. You had to compile you own Python because the one that came with the Linux distribution was too new. Also If I'm not mistaking I think that PyPy has some sandboxing.

Anyway I'll leave this from 2013 here:

> After having work during 3 years on a pysandbox project to sandbox untrusted code, I now reached a point where I am convinced that pysandbox is broken by design. Different developers tried to convinced me before that pysandbox design is unsafe, but I had to experience it myself to be convineced.

> It would also be nice to help developers looking for a sandbox for their application. Please tell me if you know sandbox projects for Python so I can redirect users of pysandbox to a safer solution. I already know PyPy sandbox.

-- https://mail.python.org/pipermail/python-dev/2013-November/1...

Re:Dozens of malicious PyPI packages discovered targeting de... by 0xblinq on Wednesday November 02, 2022 @08:42PM (#33445087)
Wouldn't running your development environment inside docker provide the same safety levels?
Re:Dozens of malicious PyPI packages discovered targeting de... by louislang on Wednesday November 02, 2022 @09:13PM (#33445373)
Containers aren't great security boundaries. To get the safety you'd really need, you should absolutely use a VM.
Re:Dozens of malicious PyPI packages discovered targeting de... by ryukafalz on Wednesday November 02, 2022 @09:00PM (#33445240)
I broadly agree, but if I'm reading your suggestion correctly I think that "access" list is too coarse-grained still! It looks like you're suggesting a predefined list of permissions that can be granted to a dependency, but... why not go even further? If the list of things you're passing in are references rather than strings, then you could do...

    const apollo = require('apollo-client', {fetch});
    const stringutils = require('stringutils');
That way, you can pass in at a very fine-grained level any object you want to, including things like `fetch` and `fs`. But then, you could just as easily pass in a custom `loggedFetch` module like so, that wraps `fetch` and logs all network requests made:

    const apollo = require('apollo-client', {fetch: loggedFetch});
This is the object-capability security model, and as a sibling commenter pointed out, LavaMoat basically does this for JavaScript dependencies. (This is also basically just lexical scope, by the way, if your language is strict enough - though most unfortunately aren't.)
Re:Dozens of malicious PyPI packages discovered targeting de... by FractalHQ on Wednesday November 02, 2022 @09:34PM (#33445597)
I love this idea. But what about peer deps? And their dependencies? What if multiple deps share peer deps? Is there a simple way permissions could be resolved in the web of modules?

Also- tangential but I really wish people would stop using require and use ESM whenever possible. I cringe when I see `require` just as much as when I see `var` being used in 2022, but I’m not certain there’s never a good reason not to use ESM.

Re:Dozens of malicious PyPI packages discovered targeting de... by nirimda on Thursday November 03, 2022 @07:36AM (#33449548)
If you want to override the dependency of your dependency, then it's your dependency too - so if you were using the javascript approach up there you might have

    var bar = require("bar", {baz: loggingBaz})
    var foo = require("foo", {bar})
This is true even if you never otherwise use bar.

This is certainly how peer dependencies work in nix flakes, for instance, where you can say something like

   bar = //....
   bar.inputs.baz.follows = loggingBaz;
   foo = //....
   foo.inputs.bar.follows = bar;
Since nix flakes is a package/dependency manager, it generates a lockfile that you could inspect too see what all the dependencies are, and make sure you got it right (oh, I still have two bar's, I must have forgotten to override some other dep). I suppose any compiler that involves a linking stage would in principle be able to generate some comparable output at the language level.

(Apologies for using require and var, but I'm convinced the functional syntax is semantically clearer in this context.)

Re:Dozens of malicious PyPI packages discovered targeting de... by bernawil on Wednesday November 02, 2022 @09:36PM (#33445621)
A resource access model for dependencies doesn't make much sense to me, there's basically only 2 things you want to gate access for libraries: filesystem and network. And it's all-in. A library that needs network access may be legit today and after an update start exfiltrating data to a different url. It seems easier to grep for fs and network calls in the library code than any of that.
Re:Dozens of malicious PyPI packages discovered targeting de... by jononor on Friday November 04, 2022 @04:32PM (#33473366)
Restricting a process to only be able to access opt-in list of directories underneath the project directory would be useful. Assuming one uses a venv, and all the dependencies are contained there. Then one might want some data folder. And have at least prevented dels from scraping user-wide secrets.
Re:Dozens of malicious PyPI packages discovered targeting de... by bernawil on Saturday November 05, 2022 @12:13AM (#33477890)
You're describing a chroot jail. key there is "process". Dealing with processes permissions is the OS's job.

A if a language wants to deal in library's security it should strive to make static analysis possible. Eg: the language guarantees that network and filesystem calls can only be done with a single function, statically so I can audit that leftpad indeed doesn't make network calls .

Re:Dozens of malicious PyPI packages discovered targeting de... by mdavidn on Wednesday November 02, 2022 @10:42PM (#33446260)
In a post-Spectre and post-rowhammer world, I have my doubts that any sub-process security boundary will prove durable in the long run.
Re:Dozens of malicious PyPI packages discovered targeting de... by marmada on Wednesday November 02, 2022 @11:07PM (#33446490)
Wasmtime / WASI does this extremely well.
Re:Dozens of malicious PyPI packages discovered targeting de... by hayley-patton on Thursday November 03, 2022 @02:08AM (#33447614)
Re:Dozens of malicious PyPI packages discovered targeting de... by pjmlp on Thursday November 03, 2022 @03:06AM (#33447941)
Java and .NET had it, and in both cases they eventually dropped it, because many security exploits were cause by developers not really understanding how to use them.

In the end they became yet another attack vector, and now everyone should use OS security services instead.

Re:Dozens of malicious PyPI packages discovered targeting de... by lionkor on Thursday November 03, 2022 @03:17AM (#33447984)
Sort of like BSD's pledge() and similar APIs[1]

[1]: https://man.openbsd.org/pledge.2