News for hackers. Stuff that matters.
Re:Malicious PyPI packages stealing credit cards and injecti... by yardstick on Tuesday August 03, 2021 @09:18AM (#28048763)
This is why our build systems don’t use public repositories directly, and why we always pin to an exact version. Any third party dependencies (js/python/java/c/you-name-it) are manually uploaded to our Artifactory server- which itself has no internet access. All third party libraries are periodically checked for new versions, any security announcements etc, and only if we are happy do we update the internal repo.

It has been a bit of a challenge, especially with js & node and quite literally thousands of dependencies for a single library we want to use. In such cases we try avoid the library or look for a static/prepackaged version, but even then I don’t feel particularly comfortable.

I should really start specifying checksums too.

Re:Malicious PyPI packages stealing credit cards and injecti... by pornel on Tuesday August 03, 2021 @11:47AM (#28050631)
Own hosting, pinning, and checksum checks are defenses against network-based attacks and compromise of the package repository.

They do nothing against trojans like these. You will be running your own pinned checksummed version of the malicious code.

If you want to stop malware published by the legitimate package author, you need to review the code you're pulling in and/or tightly sandbox it (and effective sandboxing is usually impossible for dependencies running in your own process).

Re:Malicious PyPI packages stealing credit cards and injecti... by tremon on Tuesday August 03, 2021 @12:07PM (#28050908)
Well, it does induce a timed delay between upstream release of a compromised package and when it enters the own codebase. As long as the exploit is found and published before someone manually uploads it to the local store, you're safe.

But yes, a better option would be to run your own acceptance tests on each new upstream release, and that includes profiling disk/network/cpu usage across different releases.

Re:Malicious PyPI packages stealing credit cards and injecti... by jameshart on Tuesday August 03, 2021 @12:46PM (#28051336)
Also introduces that same time delay for getting security patches released by package maintainers into your build pipeline.
Re:Malicious PyPI packages stealing credit cards and injecti... by tracker1 on Tuesday August 03, 2021 @03:57PM (#28053389)
This... worked in an org, where it literally took nearly 3 months to get package updates and additions approved... and that was for licensing review, not even proper security audits.

It may be safer to just accept that you live in the wild west and have systems boundaries in place to limit exposure/impact.

I've been pushing for closed-box logging targets, for example, where all logging goes to at least two systems (local and remote) so that the logging target is generally only available to submit log lines entries to. Not perfect, but where my head has been at.

Another thing is to PULL backups, not push them out.

Re:Malicious PyPI packages stealing credit cards and injecti... by jacquesm on Tuesday August 03, 2021 @04:10PM (#28053551)
> Another thing is to PULL backups, not push them out.

That's an absolute must. A push backup may not be a backup at all when you need it, or it may be compromised. It also requires the system you push into to be accessible for inbound connections, which in itself may be problematic.

Re:Malicious PyPI packages stealing credit cards and injecti... by andrewchambers on Tuesday August 03, 2021 @08:12PM (#28055845)
Really once the secure channel between two processes running on each host is setup, there is no difference between the two methods. A pull backup can be tricked just as easily by presenting a false filesystem or backdooring the 'pull process' running on the compromised machine.

You want append only backups with secure timestamps and do forensics to find the last good snapshot. It is easier to set that up with pull backups, but not so hard with the right tools for push backups.

Re:Malicious PyPI packages stealing credit cards and injecti... by zomgwat on Tuesday August 03, 2021 @09:34PM (#28056291)
Another option is to use a cloud storage service that supports fine grained access control (e.g. write-only vs read-only) and retention polices.
Re:Malicious PyPI packages stealing credit cards and injecti... by actually_a_dog on Tuesday August 03, 2021 @07:38PM (#28055601)
Re: backups

Yes, yes, yes!

Not only that, but test your backups! And follow the 3-2-1 rule for any data of any importance: 3 copies in at least 2 different formats and 1 copy located off-site and in a different physical location from the other 2. Be sure to check the integrity of your backups, as well. It doesn't do much good to restore from a corrupted backup.

That all sounds like a lot of work, and an excess of paranoia, but you won't be thinking that when it comes time to restore from those backups. Let's see: pay millions of dollars in ransom anonymously in BTC to hackers who've held your data (and your company!) hostage, or, spend anywhere from a couple of hours to a few days restoring from backups.

It's your call, but, I know which one I would choose if I were the one who gets paged for things like that.

Re:Malicious PyPI packages stealing credit cards and injecti... by beefjerkins on Tuesday August 03, 2021 @06:11PM (#28054849)
I'm trying to wrap my head around the concept of 'pulling' backups, rather than pushing them. In my mind, once you make a backup, you should then transfer it to a separate system for archival.

Where am I going wrong?

Re:Malicious PyPI packages stealing credit cards and injecti... by jjnoakes on Tuesday August 03, 2021 @06:17PM (#28054898)
To pull backups, the backup system connects to the production system and grabs the data, storing it locally on the backup system. To push backups would be for the production system to connect to the backup system and send the data.

The main benefit of pull-based backups is that the production machine doesn't need credentials to write to the backup server; this means if production is compromised, it can't corrupt your backups.

Re:Malicious PyPI packages stealing credit cards and injecti... by teddyh on Tuesday August 03, 2021 @07:37PM (#28055593)
If you can’t trust the production machine to initiate regular backups by itself, why do you trust the production machine to allow the backup server to access the production machine and make backups? In both cases you need an alert system to detect if a production system has not been backed up for too long.

Therefore, a push system is no different than a pull system, provided, of course, that the production system can only make new backups, not write indiscriminately to the backup server (e.g. delete old backups).

Re:Malicious PyPI packages stealing credit cards and injecti... by jjnoakes on Tuesday August 03, 2021 @07:51PM (#28055693)
> If you can’t trust the production machine to initiate regular backups by itself, why do you trust the production machine to allow access by the backup server?

If production is compromised, you can't trust either.

> Therefore, a push system is no different than a pull system

Not entirely - a push system can DOS the backups much easier than a pull system (filling the disks, say), and a push system requires append-only backups in order to protect against backup corruption. A pull system just requires read-only access into production, which is much more simple to configure, audit, enforce, and maintain (IMO).

Re:Malicious PyPI packages stealing credit cards and injecti... by yardstick on Tuesday August 03, 2021 @03:42PM (#28053237)
Not true. We assess each update in case of high priority issues that need a quick update.

Also we are cautious of using dependencies that don’t provide long term support/back fixes - where possible I pick stable, responsibly-managed dependencies. Postgres is a great example, security fixes are applied across multiple major versions, not just the latest.

Re:Malicious PyPI packages stealing credit cards and injecti... by rexelhoff on Tuesday August 03, 2021 @03:57PM (#28053394)
Sounds exactly like what we do for medical device software.

Version pinning, self-managed forks and code reviews of the dependency on upgrade.

Re:Malicious PyPI packages stealing credit cards and injecti... by geofft on Tuesday August 03, 2021 @06:46PM (#28055189)
How do you get informed about whether a high-priority issue exists?

In particular, who is auditing the old version of the code that you happen to be running to make sure it doesn't have vulnerabilities that are now gone after a non-security-motivated change like a refactoring or a feature removal? Probably not the upstream maintainers, who generally only maintain HEAD.

Re:Malicious PyPI packages stealing credit cards and injecti... by zomgwat on Tuesday August 03, 2021 @09:51PM (#28056372)
Security mailing lists. GitHub has security alerts. Good old fashioned RSS. For example, rubygems.org supports RSS for releases. GitHub Release pages also support RSS. An easy way to create a shared RSS feeds is to create a #news channel in Slack that has all the feeds.

It can be a pain but that pain might be motivation to not pull in dependencies with little thought.

Re:Malicious PyPI packages stealing credit cards and injecti... by geofft on Wednesday August 04, 2021 @09:19AM (#28060681)
Again, how does any of that tell you whether a high-priority issue exists in the old version of the code that you're running, as opposed to in the latest release?
Re:Malicious PyPI packages stealing credit cards and injecti... by zomgwat on Wednesday August 04, 2021 @11:34AM (#28062223)
I understand your point. I'd expect the old version to have been reviewed when it was introduced into the system just as the new version should be. Of course, that doesn't guarantee something won't slip in.

Running private package infrastructure with audited dependencies isn't a panacea to stopping supply chain attacks. I do believe it's an effective defense-in-depth tactic for the reasons others have discussed.

An additional supporting tactic that should be done is to tightly control egress traffic. Like ingress traffic, all egress traffic should be denied by default. From there, traffic should be whitelisted. That makes it more difficult to exfiltrate data or communicate with command and control infrastructure. Tight control on egress traffic also makes it easier to alert on unexpected connection attempts. That all said, locking down egress traffic can be a pain. It also isn't a panacea. Where there’s a will there’s a way.

Re:Malicious PyPI packages stealing credit cards and injecti... by neves on Tuesday August 03, 2021 @04:43PM (#28053923)
And you should run an antivirus in the repository machine. It will be really slow, but will eventually catch these malicious libs.
Re:Malicious PyPI packages stealing credit cards and injecti... by stjohnswarts on Tuesday August 03, 2021 @01:38PM (#28051932)
You will never eliminate the threat entirely, pinning and not using obscure projects does however cut down on the probability and you can't deny that.
Re:Malicious PyPI packages stealing credit cards and injecti... by actually_a_dog on Tuesday August 03, 2021 @02:09PM (#28052224)
Depending what you mean by "review," then I agree with you.

If you mean having humans inspect every line of code of every package, well... good luck with that. But, if you're talking about automated analysis and acceptance testing, then, I think you've got something.

Like unit testing, automated testing and analysis is never going to catch 100% of all issues, but it can definitely help your SRE team sleep at night.

Re:Malicious PyPI packages stealing credit cards and injecti... by dec0dedab0de on Tuesday August 03, 2021 @01:31PM (#28051855)
it does stop against type-o'd dependencies. So if there was an evil package called requestss then you wouldn't be able to install it by accident.
Re:Malicious PyPI packages stealing credit cards and injecti... by specialist on Tuesday August 03, 2021 @09:52AM (#28049169)
I did a bunch of nodejs stuff at my last gig. These teams had the of practice keeping packages up to date. Drove me frikkin nuts. So much churn, chaos.

Is this a JavaScript thing? Carried over from frontend development?

Exasperated, I finally stopped advocating for locking everything down. Everyone treated me like I was crazy. (Reproducible builds?? Pfft!!)

Happens with enterprisey Java, Sprint, Maven projects too. (I can't even comment on Python projects; I was just happy when I could get them to run.)

What's going on? FOMO?

Lock ~~Look~~ down dependencies. Only upgrade when absolutely necessary. Keep things simple to facilitate catching regression bugs and such.

Oh well. I moved on. I don't miss it one bit.

Re:Malicious PyPI packages stealing credit cards and injecti... by wereHamster on Tuesday August 03, 2021 @10:14AM (#28049436)
Everyone I know uses some form of lock file, and most of the modern programming languages support it.

As for upgrading only when absolutely necessary, let's be honest, nothing is absolutely necessary. If the software is old, or slow, or buggy, well dear users you'll just have to deal with it.

In my experience however, it's easier to keep dependencies relatively up to date all the time, and do the occasional change that goes along with each upgrade, than waiting five years until it's absolutely necessary, at which point upgrading will be a nightmare.

I much rather spend each week 10 minutes reading through the short changelog of 5 dependencies to check that yes, that changes are simple enough that they can be merged without fear, and with the confidence that it's compatible with all the other up-to-date dependencies.

Re:Malicious PyPI packages stealing credit cards and injecti... by mathattack on Tuesday August 03, 2021 @10:48AM (#28049845)
Both extremes are bad. If you never change anything, you are left behind on a lot of security updates and bug fixes. The longer you wait the harder it is to move.

The “stay current” model comes with risks too. It’s just a matter of figuring out which manner has the better value to risk trade off, and how to mitigate the risks.

Re:Malicious PyPI packages stealing credit cards and injecti... by actually_a_dog on Tuesday August 03, 2021 @02:23PM (#28052380)
One company I worked for had a bot that would periodically go and try to upgrade each individual app dependency, then see if everything built and passed tests.

If it got a green build, it would make a PR with the upgrades, which you could then either choose to merge, or tell the bot to STFU about that dependency (or optionally, STFU until $SOME_NEWER_VERSION or higher is available, or there's a security issue with the current version).

If not, it would send a complain-y email to the dev team about it, which we could either silence or address by manually doing the upgrade.

This worked out rather well for us. I think the net effect of having the bot was to make sure we devs actually paid attention to what versions of our dependencies we were using.

Re:Malicious PyPI packages stealing credit cards and injecti... by snapetom on Tuesday August 03, 2021 @11:42AM (#28050542)
The solution was, and always been, to have someone review every commit to the libraries that your app uses, and raise red flags for security vulnerabilities and breaking changes to your application.

Oh, boy, I would love to work for a company that has someone like that. Know of any? At the least, I would love for a company to just give me time to review library changes with any sort of detail.

Re:Malicious PyPI packages stealing credit cards and injecti... by goodpoint on Tuesday August 03, 2021 @11:21AM (#28050247)
> It’s just a matter of figuring out which manner has the better value to risk trade off

This is also bad.

If you want to have both stability/reliability and also receive security updates you need somebody to track security issues and selectively backport patches.

This is what some Linux distribution do. Mainly Debian, Ubuntu, paid versions of SuSE and Red Had and so on

Re:Malicious PyPI packages stealing credit cards and injecti... by ASalazarMX on Thursday August 05, 2021 @11:43AM (#28075308)
The sweet spot would be using a lock file for reproducible builds, and programmed dependency upgrades. Before the dependency upgrade you can check if the new version breaks something and plan for it.

I've used this in Python, where I try to keep dependencies to a minimum. I don't know if that would work in JavaScript, the dependency tree is huge there.

Re:Malicious PyPI packages stealing credit cards and injecti... by specialist on Tuesday August 03, 2021 @10:46AM (#28049822)
How do you deal with regressions?

For example, we once upgraded the redis client. One brief revision of the parser submodule had an apparent resource leak. (I can't imagine how...) Causing all of our services to ABEND after a few hours.

Because everything is updated aggressively, and there's so many dependencies, we couldn't easily back out changes.

--

FWIW, Gilt's "Test Into Production" strategy is the first and only sane regime I've heard for "Agile". Potentially reasonable successor to the era when teams did actual QA & Test.

Sorry, I don't have a handy cite. I advocated for Test Into Prod. Alas, we didn't get very far before our ant farm got another good shake.

Re:Malicious PyPI packages stealing credit cards and injecti... by wereHamster on Tuesday August 03, 2021 @12:07PM (#28050902)
When I see a regression, I look at what was recently updated (in the past hours, days), and it's usually one of those packages. Because frequent updates tend to be independent, it's usually not difficult to revert that change (eg. if I update react and lodash at the same time, chances are really good that I can revert one of those changes independently without any issues)
Re:Malicious PyPI packages stealing credit cards and injecti... by actually_a_dog on Tuesday August 03, 2021 @02:30PM (#28052462)
This is the way.

Also, you should try to update as few things as possible at once, and let your changes "soak" into production for a while before going in all "upgrade ALL the things!"

Why? Well, sometimes things that fail take a while to actually start showing you symptoms. Sometimes, the failure itself takes a while to propagate, simply due to the number of servers you have.

And, one of these days, cosmic rays, or some other random memory/disk error is going to flip a critical bit in some crucial file in that neato library you depend on. And, oh, the fouled up build is only going to go out to a subset of your machines.

You'll be glad you didn't "upgrade ALL the things!" when any of these things ends up happening to you.

Re:Malicious PyPI packages stealing credit cards and injecti... by specialist on Tuesday August 03, 2021 @05:30PM (#28054484)
Totally agree. That's why I'm asking if compulsively updating modules is a JavaScript, nodejs, whatever pathos.

This team pushed multiple changes to prod per day. And the load balancer with autoscaling is bouncing instances on its own. And, and, and...

So resource leaks were being masked. It was only noticed during a lull in work.

And then because so many releases had passed, delta debugging was a lot tougher. And then because nodejs & npm has a culture of one module per line of source (joking!), figuring out which module to blame took even more time.

I think continuous deploys are kinda cool. But not without a safety net of some sort.

Re:Malicious PyPI packages stealing credit cards and injecti... by actually_a_dog on Tuesday August 03, 2021 @07:46PM (#28055659)
I'm gonna toss this grenade out here, just because I don't see a better place to do it lol...

One of the companies I worked at had an incident a couple years before I started, where there were multiple malicious Python libraries being used in the code. For 3 months.

Luckily, the libraries didn't do anything significant except to ping an IP address in China, actually did perform their advertised functionality, didn't exfiltrate any data other than the source IP address on the ping packets, and they were easy to replace once the situation was found out. But, for months, they had servers pinging or attempting to ping somewhere in China.

Oh, and those libraries made it into our internal repos we were using to pin versions with, too.

Beyond being a speecy spicy meatball of a story, the moral here is that you have to constantly be on your guard and verifying every single line of code that goes into your application somehow.

Re:Malicious PyPI packages stealing credit cards and injecti... by x0x0 on Tuesday August 03, 2021 @08:22PM (#28055894)
Also, you really ought to not allow egress from your servers except to your load balancer.

Just attempting should create alarms.

Re:Malicious PyPI packages stealing credit cards and injecti... by actually_a_dog on Tuesday August 03, 2021 @09:18PM (#28056216)
Correct. That's probably actually why it took so long to detect the malicious packages: when the got installed on machines running internal services, nothing much unexpected happened. Come to think of it, I actually don't remember how the packages were detected and identified to begin with.
Re:Malicious PyPI packages stealing credit cards and injecti... by polynomial on Tuesday August 03, 2021 @12:26PM (#28051093)
In my experience although lock files are widely used in Node development, utilizing the lock files as part of a reproducible build system is far less prevalent in the wild. In fact, the majority of Node development I've seen eschews reproducible builds on the basis that things are moving too fast for that anyway, as if it were somehow a DRY violation, but for CICD. Would love to hear from Node shops that have established well followed reproducible CICD.
Re:Malicious PyPI packages stealing credit cards and injecti... by cube00 on Tuesday August 03, 2021 @10:13AM (#28049429)
Good luck when your security department starts running XRay and demands all your dependencies are at the latest versions all the time because every second release of a package is reported as vulnerable.
Re:Malicious PyPI packages stealing credit cards and injecti... by specialist on Tuesday August 03, 2021 @10:55AM (#28049947)
Ya. That's a tough one. Philosophically, I totally support vetting. I don't know we'd make it useful.

Pondering...

One past team had a weekly formal "log bash" ritual. I LOVED it.

That ops team kept track of everything. Any unexplained log entry had to be explained or eliminated. They kept track of explained entries on their end, so we wouldn't waste time rehashing stuff. I imagine their monitoring tools supported filters for squelching noisy explained log entries.

Maybe the security team which owns XRay could do something similar.

Re:Malicious PyPI packages stealing credit cards and injecti... by cyberpunk on Tuesday August 03, 2021 @10:54AM (#28049934)
But.... We're right though? I mean there is some wiggle room, if some lib has a security hole in some functionality that's not actually being used, but it's all about risk. We gate deploys to prod over something like XRay or LifeCycle and the frustration it causes our devs is much cheaper than deploying something we know is insecure to prod and would cause us to fail an audit or something (let alone get pwned).
Re:Malicious PyPI packages stealing credit cards and injecti... by TechBro8615 on Tuesday August 03, 2021 @11:34AM (#28050431)
There was a recent discussion on HN about `npm audit` and its overwhelming number of false positive vulnerabilities [0]. I can see a policy like this being frustrating in the case of `npm dependencies`. Is this something you deal with?

[0] https://news.ycombinator.com/item?id=27761334

Re:Malicious PyPI packages stealing credit cards and injecti... by rtpg on Tuesday August 03, 2021 @10:07AM (#28049340)
I mean you can have reproducible builds while being on the upgrade train. `package-lock.json` eixsts for a reason. And the tiny pains of upgrading packages over time mean that then you don't have to deal with gargantuan leaps when that one package has the thing you want and it requires updating 10 other packages because of dependencies.

Node is a special horror because of absolute garbage like babel splitting itself into 100s of plugins and slowly killing the earth through useless HTTP requests instead of just packaging a single thing (also Jon Schlinkert wanting to up his package download counts by making a billion useless micropackages). But hey, you're choosing to use those packages.

I think if you're using them, good to stay up to date. But you can always roll your own thing or just stay pinned. Just that stuff is still evolving in the JS world (since people still aren't super satisfied with the tooling). But more mature stuff is probably fine to stick to forever.

Re:Malicious PyPI packages stealing credit cards and injecti... by Merad on Tuesday August 03, 2021 @02:11PM (#28052246)
> Only upgrade when absolutely necessary.

Gotta disagree with this part. If you're making a web app package updates really need to be done on a regular cadence, ideally every quarter, but twice a year at minimum IMO. In the .Net world at least it feels like most responsible open source maintainers make it relatively painless to upgrade between incremental major versions (e.g. v4 -> v5). If you put off upgrades until someone holds a gun to your head so that your dependencies are years out of date, you're much more likely to experience painful upgrades that require a lot of work.

Re:Malicious PyPI packages stealing credit cards and injecti... by Macha on Tuesday August 03, 2021 @11:41AM (#28050540)
Backwards compatibility in the javascript world isn't great. If you stop updating for a couple of years, half your libraries have incompatible API changes. Then something like a node or UI framework update comes along and makes you update them all at once to work on the new version, and you're rewriting half your application just to move to a non-vulnerable version of your core dependency.
Re:Malicious PyPI packages stealing credit cards and injecti... by oblio on Tuesday August 03, 2021 @10:00AM (#28049269)
Java/Spring/Maven should have locked down dependencies by default. They have to go out of their way to not do that. Not that some people don't, anyway.

Typos:

> I stopped advocating for locking everything down.

started?

> Look down dependencies.

lock?

Re:Malicious PyPI packages stealing credit cards and injecti... by nvrspyx on Tuesday August 03, 2021 @10:09AM (#28049368)
I think the first typo is actually correct. They're saying that they stopped advocating for it because everyone treated them like they were crazy for doing so.
Re:Malicious PyPI packages stealing credit cards and injecti... by watermelon0 on Tuesday August 03, 2021 @01:16PM (#28051715)
AFAIK Maven and Gradle don't have any built-in way of locking down dependencies (direct or transient), unless I missed something.
Re:Malicious PyPI packages stealing credit cards and injecti... by cesarb on Tuesday August 03, 2021 @03:50PM (#28053314)
In my experience, Maven always uses the exact version specified in your pom.xml (and the pom.xml of your dependencies, transitively), it never uses a newer version automatically. That is, the built-in way in Maven is locked down dependencies.
Re:Malicious PyPI packages stealing credit cards and injecti... by specialist on Tuesday August 03, 2021 @10:47AM (#28049837)
Edited. Thanks for proofreading my rant. :)
Re:Malicious PyPI packages stealing credit cards and injecti... by OJFord on Tuesday August 03, 2021 @05:40PM (#28054574)
I tend to assume OSS contributors/maintainers are working generally to make things better, features I'm not using/don't need aside, they're fixing bugs (that I might not know I'm hitting/about to hit), patching security holes, etc. - so that's one for the 'pro-upgrading' column.

Against that, sure, there might be something bad in the new release (maliciousness aside even, there might be a new bug!). But.. there might be in the old one I've pinned to as well? Assuming I'm not vetting everything (because how many places are, honestly) I have no reason to distrust the new version any more than my current one.

Reproducible builds are an orthogonal issue? You can still keep your dependencies' versions updated with fully reproducible builds. Ours aren't, but we do pin to specific versions (requirements.txt & yarn.lock), and keep the former up to date with pyup (creates and tests a branch with the latest version) and up to date within semver minor versions just with yarn update (committed automatically since in theory it should be safe, had to revert only occasionally).

Re:Malicious PyPI packages stealing credit cards and injecti... by Nursie on Tuesday August 03, 2021 @11:11AM (#28050137)
> keeping packages up to date.

It’s good security practice, especially for anything internet facing.

Sure, you don’t have to do it obsessively, but if you let it stagnate you can have trouble updating things when critical vulnerabilities are found, and you have a huge job because multiple APIs have changed along the way.

Re:Malicious PyPI packages stealing credit cards and injecti... by dheera on Tuesday August 03, 2021 @11:17AM (#28050216)
I get notifications every other week about my NodeJS packages having security vulnerabilities, and so I upgrade.

I'm not sure why NodeJS devs are so bad at security compared to say C++ devs. It's not like I'm getting asked to upgrade libstdc++ and eigen all the time ...

Re:Malicious PyPI packages stealing credit cards and injecti... by ComputerGuru on Tuesday August 03, 2021 @04:38PM (#28053866)
I’m not going to get into barriers for entry and what kind of developer chooses which language, but C/C++ has always eschewed having unnecessary dependencies (originally because dependency management is hard, but that’s no longer the real reason - it’s just become baked into the culture). Even if you copy and paste hundreds of lines of code (or individual source files) the way you think about and treat them is very different from when they are external to your code base. You own (your copy of) them now, and at the very least, you familiarize yourself with their internals (and you wouldn’t copy and paste something that had its own dependencies). Actual (dynamically linked) dependencies don’t export objects with super brittle interfaces so much as they do expose very stable, carefully designed, and as minimal as possible boundaries for interfacing with their internals. Anything crossing API boundaries is considered leaving/entering the trusted domain, and lifespans of pointers and references in a non-garbage collected language guide/force you to eschew incorporating external libraries into your code globally and isolate the interaction (and therefore, the attack surface area) between your code and external code.

Then there’s the type system. Despite having some of the weakest type systems of strongly types languages, C (to some extent) and C++ (especially modern C++) are still light years ahead of what even Typescript buys you because they don’t offer the same escape hatches or “fingers crossed this TS interface matches the JS object that we are binding it to, but two lines from here, no one will remember that this isn’t actually a native TS class and that this non-nullable field might actually be null because the compile-time type checking system can’t verify this even at runtime without manual user validation because the MS TS team refuses to transpile type validation because they insist on zero overhead even though JS is not a low level or systems language.”

More than anything else however, developers of statically typed languages tend to fundamentally disagree with the idea of “move fast and break often” and will put off changes for years if they’re not at least 90% sure it’s the correct solution (and even when they end up wrong, it’s still far better than someone that says “who cares if it’s the or even just an actually correct solution, it’s still a solution and we can always revisit this later”).

Re:Malicious PyPI packages stealing credit cards and injecti... by wiremine on Tuesday August 03, 2021 @11:01AM (#28050011)
Feels like this is a business opportunity for someone.

Use case:

1. Upload a pre-reviewed package.json file. 2. The service monitors changes, and recommends updates. Recommendations might include security, bug, features, etc. It would check downstream dependencies, too. For production systems, the team might only care about security features. 3. Developer team can review recommendations, and download the new package.json.

(There are lots of opportunities to improve this: direct integration with git, etc.)

Anybody know if this sort of service exists? I know npm has _some_ of this. Maybe I'm just ignorant of how much of a solved problem this is?

Re:Malicious PyPI packages stealing credit cards and injecti... by rank0 on Tuesday August 03, 2021 @11:05AM (#28050075)
What you’re looking for is called SCA (software composition analysis).

Best tool I’ve used so far in this domain is snyk.

Re:Malicious PyPI packages stealing credit cards and injecti... by goodpoint on Tuesday August 03, 2021 @11:23AM (#28050263)
> Feels like this is a business opportunity for someone.

This is what some Linux distributions do. Quality review, legal review, security backports.

Re:Malicious PyPI packages stealing credit cards and injecti... by cilefen on Tuesday August 03, 2021 @06:42PM (#28055143)
We use Renovate for this.
Re:Malicious PyPI packages stealing credit cards and injecti... by dec0dedab0de on Tuesday August 03, 2021 @01:34PM (#28051897)
node locks down dependencies for you, not only the version, but it saves a hash too. The problem is that npm install will install the newest version allowed in your config, and re lock it. However if you run npm ci, it will only install what is locked, and fail if the hashes don't match.

in python pipenv works the same way, pipenv sync will only install what is locked, and will check your hashes. I'm not sure about poetry.

Re:Malicious PyPI packages stealing credit cards and injecti... by paulddraper on Tuesday August 03, 2021 @04:00PM (#28053428)
For quite a while now, the JS ecosystem has used lock files -- npm, yarn, pnpm. You have to got out of your way not to pin JS dependencies.
Re:Malicious PyPI packages stealing credit cards and injecti... by _pmf_ on Tuesday August 03, 2021 @11:14AM (#28050176)
They have no concept of ever needing to reproduce a build. And they are probably right if you do continuous development of some SaaS stuff.
Re:Malicious PyPI packages stealing credit cards and injecti... by aranchelk on Tuesday August 03, 2021 @01:26PM (#28051805)
I’ve heard the argument that it’s not worth spending the time to get all aspects of your build environment into version control for 100% reproducible builds, but the saying “I shouldn’t be bothered to know what my upstream deps are” that’s pretty sad (hopefully rare).

Even with the continuous deploy stuff, I think you’re giving too much benefit of the doubt. If an upstream non-pinned change brings down something critical (e.g. payments), you’ll revert the change in source, rebuild, release, the site is still broken. If you keep old artifacts you can push one of those, now you’re not really doing continuous deployment, and you won’t be again until you finish root cause analysis, and since you’ll never see the relevant change in your source code, it could take a while.

Re:Malicious PyPI packages stealing credit cards and injecti... by actually_a_dog on Tuesday August 03, 2021 @02:17PM (#28052303)
I agree. Locking things down is the way to go, when it comes to safety.

The downside, however, is that, by design, you end up with packages that don't get upgraded regularly. That can cause problems down the road when you decide you do want to upgrade those packages.

For instance, there might be breaking changes, because you're jumping major versions. Of course, breaking changes are always a problem, but, if you're not regularly upgrading stuff, your team will tend to build on/build around the functionality of the old version.

That leads to some real fun come upgrade time. If, you're, say, 3 major versions behind the latest version, or whatever version you want to upgrade to that contains some Cool New Feature(tm) you really, really need, you might end up having to do this silly dance of upgrading major versions one at a time, in order to keep the complexity of the upgrade process as a whole under control.

Oh, and, sometimes things get deprecated. That's always fun to deal with.

So, TL;DR: Yes, pin versions! It's safer that way! Just be aware that, like most engineering decisions, there's a tradeoff here that saves you some pain now in exchange for some amount of a different kind of pain in the future.

Re:Malicious PyPI packages stealing credit cards and injecti... by fnord77 on Tuesday August 03, 2021 @11:25AM (#28050302)
on the other hand, if you don't keep your packages up to date, you can get so behind that it is nearly impossible to upgrade.

especially bad if the older version you are on turns out to have vulns.

Josh Bloch says to update your packages frequently and I agree.

Re:Malicious PyPI packages stealing credit cards and injecti... by yjftsjthsd-h on Tuesday August 03, 2021 @11:24AM (#28050293)
Sorry, I don't quite see how this would protect against supply chain attacks. If an upstream dependency is back-doored, they just have to silently add their code in an otherwise reasonable sounding release, and now you will happily download that version, add it to your internal mirrors, and pin its version forever. Unless you actually read the diff on every update, which I think is impractical (although you're welcome to correct me), I don't see how this is buying you much.
Re:Malicious PyPI packages stealing credit cards and injecti... by ozzythecat on Tuesday August 03, 2021 @11:36AM (#28050463)
It’s not 100% bullet proof, but it’s safer than pulling any random repos directly from the internet.

It’s also good that your business doesn’t have to rely on a third party every time you need to pull down your dependencies and build your software.

Re:Malicious PyPI packages stealing credit cards and injecti... by DSingularity on Tuesday August 03, 2021 @12:04PM (#28050848)
Protects you against a dependency being hijacked and retroactively embedding malware in prior versions . Check summing would protect against that without the trouble of manually hosting the dependency.
Re:Malicious PyPI packages stealing credit cards and injecti... by cortesoft on Tuesday August 03, 2021 @01:08PM (#28051620)
I think part of the idea is that if you only use versions that have been released for a little while, you are hoping SOMEONE notices the malicious code before you finally update.

There are a number of issues with this approach, although the practice still might be a net benefit.

One, you are going to be behind on security patches. You have to figure out, are you more at risk from running unpatched code for longer, or from someone compromising an upstream package?

Two, if too many people use this approach, there won't be anyone who is actually looking at the code. Everyone assumes someone else would have looked, so no one looks.

Re:Malicious PyPI packages stealing credit cards and injecti... by polynomial on Tuesday August 03, 2021 @12:22PM (#28051054)
My read was GP is implying they do read the diff every time, and only change the pinned version after a manual review- "only after we are happy."

This does seem impractical at even a modest scale.

Re:Malicious PyPI packages stealing credit cards and injecti... by zerkten on Tuesday August 03, 2021 @12:53PM (#28051434)
What does "modest scale" mean? Some people have to have all dependency updates reviewed and have some level of independent security team monitoring dependency changes. Not everyone has this, but the context is key as some domains have this consistently.

Some of this is cultural in addition to being paranoid about security, or having strict compliance requirements. For your average startup, they may not have any time to dedicate to this and other fires, but that's not a universal situation.

Re:Malicious PyPI packages stealing credit cards and injecti... by staticassertion on Tuesday August 03, 2021 @01:12PM (#28051667)
> What does "modest scale" mean? Some people have to have all dependency updates reviewed and have some level of independent security team monitoring dependency changes.

Who? Seems totally intractable to me.

Re:Malicious PyPI packages stealing credit cards and injecti... by yardstick on Tuesday August 03, 2021 @03:44PM (#28053254)
We periodically review all dependencies change logs, security advisories etc and update based on risk review. We also keep an eye out for critical vulnerabilities that need immediate patching. There are tools to help with this, plus communities like HN are relevant for breaking news.
Re:Malicious PyPI packages stealing credit cards and injecti... by grincho on Tuesday August 03, 2021 @09:50AM (#28049143)
Yes, this is why I implemented hash-checking in pip (https://pip.pypa.io/en/stable/topics/repeatable-installs/#ha...). Running your own server is certainly another way to solve the problem (and lets you work offline), but keeping the pinning info in version control gives you a built-in audit trail, code reviews, and one fewer server to maintain.
Re:Malicious PyPI packages stealing credit cards and injecti... by stavros on Tuesday August 03, 2021 @01:09PM (#28051624)
Doesn't Poetry do this by default in its lockfile too?
Re:Malicious PyPI packages stealing credit cards and injecti... by c618b9b695c4 on Tuesday August 03, 2021 @01:54PM (#28052075)
There is an active PEP[0] for defining lockfiles.

0: https://www.python.org/dev/peps/pep-0665/

Re:Malicious PyPI packages stealing credit cards and injecti... by Nursie on Tuesday August 03, 2021 @11:08AM (#28050110)
This is how it always used to be, back in the before[1] times. Libraries would be selected carefully and dependencies would be kept locally so that you could always reproduce a build.

The world is different now, and just being able to select a package and integrate it like that is a massive effectiveness multiplier, but I think the industry at large lost something in the transition.

([1] before internet package management, and before even stuff like apt and yum)

Re:Malicious PyPI packages stealing credit cards and injecti... by _tom_ on Tuesday August 03, 2021 @11:17AM (#28050207)
The problem is that it also is a vulnerability multiplier.

People used to understand every package the installed. Now, they install dependencies of dependencies of dependencies, to the point that they have not even SEEN the name of most of their dependencies.

Install anything with maven and count the number of packages installed. It is appalling.

Re:Malicious PyPI packages stealing credit cards and injecti... by goodpoint on Tuesday August 03, 2021 @11:15AM (#28050185)
> I think the industry at large lost something in the transition.

Lost a lot of trust and security with the advent of language-specific installers that pull libraries and their dependencies from random URLs without any 3rd party vetting.

Re:Malicious PyPI packages stealing credit cards and injecti... by mikepurvis on Tuesday August 03, 2021 @12:02PM (#28050834)
I agree, though I think there are a couple pieces to the puzzle. Like, quite apart from the enormous convenience of new releases being available right away, and even being able to drop in a git URL and run your dependency off a branch while you wait for your upstream PR to merge, pip provides isolation between workspaces that apt has never been able to do natively because it's too generic— the closest thing is lightweight unshares, but those were years after virtualenv, require more ceremony to get going with, and may be isolated from the outside system in ways that impede productivity (there's also never really been a consistent tooling story for it, with having to cobble together debootstrap + whatever the chroot flavor of the week is).

But the biggest issue is when npm, cargo, etc showed how to include a dependency multiple times at different versions. Operating system package managers (other than Nix & friends) have no concept for how this could or would work. Pip has no story for it, and the various pip-to-apt bridges like py2deb and stdeb if anything just exacerbate the problem, by mixing your project's dependencies with those on your system.

Anyway, yes. Things were lost, 100%. But I don't think the system you want (isolation, version freedom, but with safe/vetted packages) is going to be something that's possible to evolve out of any of the current systems. It's got to be something that goes back to first principles.

Re:Malicious PyPI packages stealing credit cards and injecti... by goodpoint on Tuesday August 03, 2021 @12:57PM (#28051474)
> pip provides isolation between workspaces that apt has never been able to do natively because it's too generic

This is hardly a concern on production systems. It's been common practice for decades to deploy each service on a dedicated host, or at least a VM in order to have a degree of security isolation. [or a container if you don't care]

> npm, cargo, etc showed how to include a dependency multiple times at different versions

And this is why they cannot provide stable releases and security backports.

If you want security updates you can use Debian or pay $$ for SuSE or Red Hat or $$$$ for custom support from some tech companies, but they will mostly support one version per package.

The combinatorics explosion of packages times versions on archives like npm or pypi makes it prohibitively expensive to reliably patch and test every combination of packages and versions.

Debian has been pioneering reproducible builds and automated installation CI/QA and it still took a lot of effort to get there.

> I don't think the system you want (isolation, version freedom, but with safe/vetted packages) is going to be something that's possible to evolve out of any of the current systems.

I don't want version freedom: it's not attainable. It's not a software problem, it's a math problem.

> It's got to be something that goes back to first principles.

Any idea?

Re:Malicious PyPI packages stealing credit cards and injecti... by mikepurvis on Tuesday August 03, 2021 @01:30PM (#28051851)
If you don't want or need version freedom, what is it about the existing deb/rpm ecosystems that don't work for you, either on their own or in conjunction with the various tools that bridge other ecosystems into them? (I'm a fan of dh_virtualenv, myself)

Or is your lament that the world as a whole is worse off because others have eaten of the fruit of systems like npm and pip?

Re:Malicious PyPI packages stealing credit cards and injecti... by goodpoint on Tuesday August 03, 2021 @02:04PM (#28052175)
The latter, albeit it's not "the world as a whole", but some tech bubble. Various large companies prohibit pip/npm/docker.

(and here I'm even getting downvoted for going against the hivemind)

I can only hope that after enough software supply chain attacks the industry will realize that distros were right all along.

Re:Malicious PyPI packages stealing credit cards and injecti... by helsinki on Tuesday August 03, 2021 @09:46AM (#28049071)
FYI - You can overwrite an existing package’s release/version via pip (at least when using Artifactory’s PyPi). Not safe to assume pinning the version ‘freezes’ anything.
Re:Malicious PyPI packages stealing credit cards and injecti... by nerdponx on Tuesday August 03, 2021 @09:56AM (#28049215)
Make a "lockfile" with the pip-compile tool [0] that includes hashes. Unless you happen to fetch the hash after the package has been compromised, this should keep you safe from an overwritten version.

[0]: https://pypi.org/project/pip-tools/

Re:Malicious PyPI packages stealing credit cards and injecti... by oefrha on Tuesday August 03, 2021 @10:03AM (#28049299)
No, you cannot overwrite a file on PyPI once uploaded, even if you delete the release first. This policy has been in place for many years.
Re:Malicious PyPI packages stealing credit cards and injecti... by globular-toast on Tuesday August 03, 2021 @10:07AM (#28049341)
Pip also supports packages hashes so you can be sure you're getting the exact same package that you got last time.
Re:Malicious PyPI packages stealing credit cards and injecti... by actually_a_dog on Tuesday August 03, 2021 @02:06PM (#28052200)
Yep. You should also be hosting and deploying from wheels[0], even for stuff you create internally. If you're doing it right, you'll end up hosting your own internal PyPi server[1], which, luckily, isn't hard[2].

We did this at one of my previous companies, and, of all the things that ever went wrong with our deploy processes, our internal PyPi server was literally never the culprit.

---

[0]: https://pythonwheels.com/

[1]: https://github.com/testdrivenio/private-pypi

[2]: https://testdriven.io/blog/private-pypi/

Re:Malicious PyPI packages stealing credit cards and injecti... by pjmlp on Tuesday August 03, 2021 @10:15AM (#28049452)
I have been doing internal repositories and vendoring since 2000, only for personal projects do I do otherwise as they are mostly throw away stuff.

Teaching good security practices and application lifecycle management seems to always be an uphill battle.

Re:Malicious PyPI packages stealing credit cards and injecti... by ericpauley on Tuesday August 03, 2021 @09:26AM (#28048859)
Out of curiosity, is it really necessary to have the separate artifact server? Pinning dependencies by hash ought to be sufficient.
Re:Malicious PyPI packages stealing credit cards and injecti... by yardstick on Tuesday August 03, 2021 @09:32AM (#28048932)
Seems reasonable enough depending on your use case.

In our situation we store our own (private, commercial) artifacts as well as third party ones, so we already need to have a server, and we know our server is configured, maintained & monitored in a secure fashion whereas I have no guarantees with public servers.

Plus our build servers don’t have access out to the internet either, for security. Supply chain attacks like SolarWinds and Kaseya are too common these days.

Edit: Also, our local servers are faster at serving requests, allowing for faster builds, and ensures no issues with broken builds if a public repo went offline or was under attack.

Re:Malicious PyPI packages stealing credit cards and injecti... by jrockway on Tuesday August 03, 2021 @09:52AM (#28049170)
Security and availability don't have to be mutually exclusive. I remember in the early day of Go modules our Docker builds (that did "go mod download") would be rate-limited by Github, so a local cache was necessary to get builds to succeed 100% of the time. (Yes, you can plumb through some authentication material to avoid this, but Github is slow even when they're not rate limiting you!) Honestly, that thing was faster than the official Go Module Proxy so I kept it around longer than necessary and the results were good.

Even if you cache modules on your own infrastructure, you should still validate the checksums to prevent insiders from tampering with the cached modules.

I'll also mention that any speed increases really depend on your CI provider. I self-hosted Jenkins on a Rather Large AWS machine, and had the proxy nearby, so it was fast. But if you use a CI provider, they tend to be severely network-limited at the node level and so even if you have a cache nearby, you are still going to download at dialup speeds. (I use CircleCI now and at one point cached our node_modules. It was as slow as just getting them from NPM. And like, really slow... often 2 minutes to download, whereas on my consumer Internet connection it's on the order of 10 seconds. Shared resources... always a disaster.)

Re:Malicious PyPI packages stealing credit cards and injecti... by helsinki on Tuesday August 03, 2021 @09:56AM (#28049212)
Tangential non-sequitor:

> self-hosted on AWS

People forgot what self-hosting actually means.

Re:Malicious PyPI packages stealing credit cards and injecti... by jrockway on Tuesday August 03, 2021 @10:04AM (#28049314)
I disagree with that analysis. That basically means running some binary yourself, with the alternative being buying a SaaS product that is hosted by the developer. You may think that "self-hosting" means having your own physical server, but I have never heard anyone else use the expression like that.
Re:Malicious PyPI packages stealing credit cards and injecti... by paulryanrogers on Tuesday August 03, 2021 @10:06AM (#28049329)
Meanings can evolve over time. I tend to think of self hosted as installing from code and managing myself, whether on local hardware or remote.
Re:Malicious PyPI packages stealing credit cards and injecti... by jijji on Tuesday August 03, 2021 @10:29AM (#28049625)
The OP wrote "self-hosted Jenkins", which has a different meaning
Re:Malicious PyPI packages stealing credit cards and injecti... by zerkten on Tuesday August 03, 2021 @09:40AM (#28049012)
It's going to depend on your circumstances. You don't share any context about your app or any of your development. Rather than looking at this from the perspective of needing an artifact server, you just look at it as a case of supply chain protection.

If pinning dependencies counters all the threats in your threat model, then fine. If not, you need to be doing something to counter them. An artifact server, or vendoring your dependencies, provides provides a lot of additional control where chokepoints or additional audits can be inserted.

If there was no management cost or hassle then you'd just have an artifact server to give you a free abstraction, but it's a trade-off for many people. It's also not a solution in itself, you need to be able to do audits and use the artifact server to your advantage.

The problem is really with the threat models and whether someone really knows what they need to defend against. I find that many engineers are naïve to the threats since they've never personally had exposure to an environment where these are made visible and countered. At other times, engineers are aware, but it's a problem of influencing management.

Re:Malicious PyPI packages stealing credit cards and injecti... by fortran77 on Tuesday August 03, 2021 @09:31AM (#28048912)
It's nice to have a build machine that can complete a build when it's disconnected from the Internet
Re:Malicious PyPI packages stealing credit cards and injecti... by kawsper on Tuesday August 03, 2021 @09:32AM (#28048929)
How often does that happen?
Re:Malicious PyPI packages stealing credit cards and injecti... by oauea on Tuesday August 03, 2021 @09:42AM (#28049043)
Re:Malicious PyPI packages stealing credit cards and injecti... by jrockway on Tuesday August 03, 2021 @09:56AM (#28049214)
Docker Hub also has rate limits and outages, so yet another thing you want to cache if you promise customers "we'll install our software in your Kubernetes cluster in 15 minutes 99.95% of the time".
Re:Malicious PyPI packages stealing credit cards and injecti... by kawsper on Wednesday August 04, 2021 @07:52AM (#28059891)
I don't see how any of those are build machines that are offline.
Re:Malicious PyPI packages stealing credit cards and injecti... by oauea on Wednesday August 04, 2021 @09:50AM (#28060972)
Build machines generally want to be 'online' so they can connect to the internet. They want to connect to the internet so they can access services hosted on the internet. Many of those services use Cloudflare, Akamari or Github. If any of those are down, those services are down. Now it's great that your build machine is online, but the packages it's trying to fetch won't be available because their CDN is offline.

Now if only you had a local caching proxy.

Re:Malicious PyPI packages stealing credit cards and injecti... by 83457 on Tuesday August 03, 2021 @09:40AM (#28049016)
Sometimes I use an air gapped test lab. Setup of certain software and projects is a real pain. Sounds like this approach could help.
Re:Malicious PyPI packages stealing credit cards and injecti... by ex_amazon_sde on Tuesday August 03, 2021 @11:24AM (#28050278)
It's standard practice in many large companies.
Re:Malicious PyPI packages stealing credit cards and injecti... by tikkabhuna on Tuesday August 03, 2021 @09:54AM (#28049196)
We use an artifact server and our build servers are completely airgapped. We know exactly what dependencies are used across the organisation. We can take centralised action against malicious dependencies.

I wouldn't bother having one if you're small (<25) people. If you start having a centralised Infosec group, then it starts to become necessary.

Re:Malicious PyPI packages stealing credit cards and injecti... by njharman on Tuesday August 03, 2021 @10:40AM (#28049770)
Airgaped? Really? Everytime a build happens someone physically moves a Thu drive or some other media too from the build server?

Airgap means not networked, even internally. Not just "blocked" from internet.

Re:Malicious PyPI packages stealing credit cards and injecti... by tikkabhuna on Tuesday August 03, 2021 @11:59AM (#28050804)
Wikipedia[1] offers a slightly relaxed definition, although I agree, I (and my colleagues) abuse the term.

The artifact repository server connects to the internet via a proxy. Build servers have no access to the internet.

[1] https://en.wikipedia.org/wiki/Air_gap_(networking)

Re:Malicious PyPI packages stealing credit cards and injecti... by formerly_proven on Tuesday August 03, 2021 @11:11AM (#28050138)
Depending on what you're using for package management, an "artifact server" can be as simple as a directory in git or a dumb HTTP server. File names are non-colliding and you don't really need an audit log on that server, because all references are through lock-files in git with hashes (right? RIGHT?), so it basically doesn't matter what's on there.
Re:Malicious PyPI packages stealing credit cards and injecti... by ageofwant on Tuesday August 03, 2021 @10:11AM (#28049406)
You should mention this in your interviews. Keeping up to date with the state of the art is implicit for me. If I need to spend months retraining or up training because of company policy I expect to be compensated for that while employed.
Re:Malicious PyPI packages stealing credit cards and injecti... by yardstick on Tuesday August 03, 2021 @11:25AM (#28050311)
We are upfront about it in interviews. We definitely don’t want unhappy developers, but we also don’t want insecure code. We do upgrade libraries but we do so only after analysing risk and impact. None of our developers have spent months training to develop our code.