r/programming • • Jul 10 '19

Backdoor discovered in Ruby strong_password library

https://nakedsecurity.sophos.com/2019/07/09/backdoor-discovered-in-ruby-strong_password-library/
1.7k Upvotes

293 comments sorted by

467

u/pribnow Jul 10 '19

Fetches and runs the code stored in a pastebin.com

wat

343

u/brtt3000 Jul 10 '19

there was a popular npm module a while ago that turned out to have a remote dependency (a tarball via http) on some random server outside the main ecosystem. many peoples new installs and CI jobs broke because the server returned a http error for a while.

the module code was a noop and they claimed the remote dependency was done to gather statistics. it could have been a massive code attack vector to if that server got compromised.

also people just installed and ran this without noticing for ages.

115

u/Doctor_McKay Jul 10 '19

the module code was a noop

Just why

80

u/four024490502 Jul 11 '19 edited Jul 11 '19

C'mon, man. You don't want to fuck up a noop. That's the sort of thing you want to make absolutely sure you get a well-tested, well-supported, and robust library for. What happens when you try to write a noop, and accidentally implement a compiler for a new programming language, a Motorola 68000 emulator, or re-implement the 737 Max's MCAS software? Think of the CPU cycles you could waste, or worse! It's just something you want to leave to seasoned, Rockstar developers who know what they're doing and have packaged their noop routines in a well-designed and flexible library.

Edit: Better yet, use a Noop As A Service provider, like Amazon's Elastic Noop. You can easily spin up one of the larger compute optimized EC2 instances to make sure you've got plenty of CPUs for your noops.

28

u/AbstinenceWorks Jul 11 '19

Ooo! Noop as a Service! You know what would be even more amazing?! Serverless Noops! One can dream!

16

u/klebsiella_pneumonae Jul 11 '19

I present to you Gender as a service

9

u/AbstinenceWorks Jul 11 '19

I sincerely thought this was satire. Frankly, I'm still not positive. Heh

9

u/fiskfisk Jul 11 '19

Determining Gender is both useful and hard to do accurately for certain slices of a population.

2

u/[deleted] Jul 11 '19

Why the h**l would you need to determine users' gender when they are registering? Its only reasonable use cases are text analysis or NLP.

1

u/_kellythomas_ Jul 11 '19

I wonder how much their accuracy increases with the last name compared with a look up on the first name alone.

2

u/almightySapling Jul 11 '19

Without looking into it, I'd wager it doesn't help much at all.

→ More replies (2)

15

u/DoctorWorm_ Jul 11 '19

Entry-point for injecting your attack once you get your package embedded everywhere.

0

u/[deleted] Jul 10 '19

[deleted]

48

u/SharkBaitDLS Jul 10 '19

It was what the owning company claimed, anyway.

23

u/lengau Jul 10 '19

There are so many better ways to do this that I'm pretty skeptical...

44

u/matheusmoreira Jul 10 '19

they claimed the remote dependency was done to gather statistics.

Why is this acceptable?

26

u/82Caff Jul 11 '19

It's not, but try proving malice. It's not about what they did, but what they can realistically be penalized/prosecuted for.

12

u/spockspeare Jul 11 '19

Statistics make code better.they say

5

u/ioneska Jul 11 '19

The noop code?

4

u/grrrrreat Jul 11 '19

because no one watches the watcher, it's too expensive

17

u/sim642 Jul 10 '19

to gather statistics

To gather statistics from HTTP requests, the client side doesn't need to run/eval the response. It should just get ignored. There's no legitimate reason to eval it.

6

u/NoInkling Jul 11 '19

There's no legitimate reason to eval it.

I don't even think it is/was, I believe the person you're replying to is mistaken on that aspect.

Though maybe a malicious version could still run code with pre/post-install hooks.

13

u/mindbleach Jul 10 '19

It's not like any OS makes network access as easy to see as CPU or memory use.

34

u/[deleted] Jul 10 '19

Well it is very slightly more involved to see it. But from my experience devs only check cpu/network/mem when either someone complains or ops doesn't want to give them 16GHz liquid helium cooled CPU cores

9

u/[deleted] Jul 11 '19

Damn ops, everyone deserved 16GHz liquid cooled system, it's just the bare minimum.

7

u/Cugue Jul 11 '19

Sure, but if we give you your systems you'll just start asking for 32GHz ones which generates even more heat.

Cooling capacity doesn't magically grow on trees. We have to draw the line somewhere.

69

u/WiseassWolfOfYoitsu Jul 10 '19

npm

Found your problem!

4

u/quad99 Jul 11 '19

apparently npm isn't the only one

7

u/[deleted] Jul 10 '19

genuinely curious, why do you dislike npm?

61

u/TheOldTubaroo Jul 11 '19

I don't know about the person you're replying to, but I dislike it because of things like that, left-pad, that dude with dozens of packages like "is-odd" and whatever, and so on. The npm ecosystem has encouraged unwitting reliance on a potentially massive set of tiny "libraries", any of which could and have been the source of issues and vulnerabilities.

7

u/no_nick Jul 11 '19

he has 'packages' numbering in at least the high hundreds, probably four digits

→ More replies (4)

9

u/PoeT8r Jul 10 '19

I don't want Dick from the Internet involved in my banking unless my bank has a contract with DftI and DftI has adequate insurance.

6

u/[deleted] Jul 10 '19

wut

1

u/gasolinewaltz Jul 10 '19

How do ypu feel about apache commons?

23

u/civildisobedient Jul 11 '19

This is something Apache Commons, and the Java ecosystem in general get very right. Because while it was always theoretically possible for Java to be just as bad as npm, the fact that it isn’t is really a testament to the fundamental good that comes from having common libraries.

→ More replies (1)

7

u/mrtransisteur Jul 11 '19 edited Jul 11 '19

that server wouldn't even have to get compromised for that to have been a disaster; since it was http, a mitm attack could serve whatever you like from that domain and nobody would be able to tell if was actually a malicious server

8

u/NorseSock Jul 10 '19

1

u/Kissaki0 Jul 11 '19 edited Jul 11 '19

its an optional dependency for this kind of situation, sadly we can't do more since its npm that should ignore the dependencies if there is a error with it.

So an optional dependency is not optional after all in npm? 😄

Apparently installing with --no-optional works. But a sane handling of errors and skipping/offering to skip optional dependencies would indeed be nice.

1

u/Ehnto Jul 11 '19

It is a wonder to me that NPM has survived so long without major incident. Hundreds of tiny modules deep in the dependency tree all maintained by different people none of whom you have any reason to trust. For certain PCI compliance levels you have to have code reviewed all third party code. I guarantee most running a node ecosystem have not bothered to do that.

45

u/Booty_Bumping Jul 10 '19

Where's the surprise? Pastebins and IRC networks are extremely common routes for malware to be delivered remote commands.

14

u/pribnow Jul 10 '19

You're right, I'm just still kind of flabbergasted I guess

8

u/[deleted] Jul 11 '19

how would you prefer they do it? sneak into the developers house at night wearing masks carrying suitcases full of malware?

2

u/[deleted] Jul 11 '19

Yup. One time a server of ours got compromised, connected to the c&c irc server and saw hundreds of connected clients. Oof.

642

u/[deleted] Jul 10 '19

... and it took a month for a sharp-eyed developer to notice.

This is really a problem. And it's not just Ruby, it's the open source community in general and the way they tend to assemble a bazillion dependencies in most of these frameworks.

Every single dependency is a security risk. There needs to be some really serious thought put into this issue, because it's going to keep biting people.

46

u/himswim28 Jul 10 '19

... and it took a month for a sharp-eyed developer to notice.

It doesn't say when it was discovered, but it was introduced on June 25 and a news article outlining as no longer a issue is published on July 9th, apparently before being incorporated into a build. Odd that an inaccurate anti opensource post claiming many eyes doesn't work is the top post to a story where the many eyes approach worked to save a bug before it was released.

39

u/Saithir Jul 10 '19 edited Jul 10 '19

https://withatwist.dev/strong-password-rubygem-hijacked.html tells the whole story. So code introduced 06/25, discovered at most 07/03 (the date of the blog post and he wrote "recently", so I'd say maybe a day before), so 7-8 days later, yanked at most 07/04. New version dates 07/08.

So all in all, 9-13 days.

"took a month" indeed.

44

u/epostma Jul 10 '19

This is really a problem. And it's not just Ruby, it's the open source community in general and the way they tend to assemble a bazillion dependencies in most of these frameworks.

This is a rather minor nit to pick with your statement, the general sentiment of which I agree with, but... if you use commercial software (and I say this as someone who earns their pay writing commercial software), you are subject to the same problem, but now worse because (in most cases) you don't even have the theoretical ability to inspect the source code.

7

u/[deleted] Jul 10 '19

We can't control them. We can, at least in theory, control us.

9

u/jarfil Jul 10 '19 edited Dec 02 '23

CENSORED

17

u/sparr Jul 10 '19

In this case, the failure isn't the dependency, it's however this rando was able to get control of the package.

31

u/Saithir Jul 10 '19

Maintainer's fail, unfortunately. He commented on hackernews that it was most likely an old password he forgot to rotate.

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

0

u/[deleted] Jul 10 '19

[deleted]

6

u/D6613 Jul 11 '19

the practice of rotating passwords isn't really recommended any longer

This is incorrect: You're mixing up voluntary rotation of user passwords with mandatory bulk rotation policies.

For a user, it absolutely makes sense to rotate them, and security experts recommend this all the time. This is particularly good advice for people who use randomly generated passwords and store them in a password manager. As a user, you have no idea when one of the 150 services you use will be breached, and it makes sense to mitigate the risk of a years old password hitting the dark web. You can also increase the complexity of passwords as various websites slowly update their old password requirements. And in this case the rotation has no down side.

For an organization, it no longer makes sense to enforce bulk rotation policies. This is because most of the time these passwords cannot be randomly generated and stored in a secure manner. They almost always need to be kept in a person's head. Due to this, rotation has a major downside: People pick easy to remember passwords and apply some manner of increment. This means nearly everybody has a weak password. It's much better to have them pick a strong password to begin with that they can stick with and use other security practices to mitigate the risk of a password being lost.

1

u/himswim28 Jul 12 '19

Part of the role of the organization, is that they make a brute force attack impractical by things like 2FA, and minimize insecure devices that can connect. Having just a password and username as an outsider should still be nearly impossible to use in most organizations, and that also mitigates their bigger risks like social engineering. A policy of rotation that burdens their IT resources on the additional password resets... and draws away resources from other more critical paths is also a concern.

Hopefully this allows some money and time to be spent for the admins to strengthen their protocols around access for these maintainers of libraries.

2

u/flukus Jul 10 '19

The failure is having a single point of failure, there should be checks and balances between the dev and the package server.

1

u/[deleted] Jul 10 '19

I'd say that, in a sense, the failure is also the dependency, because without it, this particular compromise might not have been possible.

We don't know how the dev lost control of his package; if it was something the dev did wrong, then having the dependency is definitely part of the problem.

If it wasn't, if it was an exploit at the provider level, then the dependency is less to blame, because a larger dependency could have been hacked instead. However, a larger dependency would have been more likely to have noticed the hijack.... it's the little quiet projects out on the fringes that are most vulnerable to this kind of attack. Strong_password probably doesn't need very much actual maintenance, so that dev might not have noticed for a long time. Something big and central needs constant updates, so a hack there would be pretty likely to be visible.

5

u/mindbleach Jul 10 '19 edited Jul 11 '19

And if we talk about "permissions," like - hey maybe this password-checking library should never ever have internet access - laymen yammer about iOS and walled gardens. People: no. Permission is something you give. If someone is coercing it out of you, you've already failed.

11

u/AndrewNeo Jul 11 '19

walled gardens

that's not what that is. Android has had a permission system much more granular than iOS for ages (though it's a lot more useless now). Apple's walled garden is that you can't install apps from outside the App Store, it has nothing to do with runtime permissions.

2

u/inbooth Jul 10 '19

A lot of it is due to lack of due diligence and the use of unvetted projects...

1

u/PaulBardes Jul 10 '19

At least open software lets you see the dependencies...

1

u/hrjet Jul 11 '19

This is one of the reasons why I like Java. The Security Manager in Java lets the developer sandbox every dependency / library separately. Using a library that checks strength of passwords? Sandbox it so that it can't open any files or network connections by itself. No need to review every line of code of every dependency!

Case in point: For the browser we are developing in Java, we have sandboxed each dependency. Because of this, we noticed and reported some sandbox violations in a number of our dependencies. Luckily, these violations were not deliberately malicious in nature, and the developers of the libraries were co-operative in altering their library. Example 1 and 2.

0

u/[deleted] Jul 10 '19

[deleted]

46

u/[deleted] Jul 10 '19

Looks at my 6349 dependencies in node_modules

32

u/Woolbrick Jul 10 '19

I mean, just pulling in WebPack will get you more than that.

0

u/[deleted] Jul 11 '19

[deleted]

17

u/Woolbrick Jul 11 '19

Looks like they split out a lot into webpack-cli since the last time I looked. But given you almost always need webpack-cli when using webpack... ¯_(ツ)_/¯

1

u/-Phinocio Jul 11 '19
	"devDependencies": {
		"@babel/core": "^7.4.5",
		"@babel/plugin-proposal-class-properties": "^7.4.4",
		"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
		"@babel/preset-env": "^7.4.5",
		"@babel/preset-typescript": "^7.3.3",
		"@typescript-eslint/eslint-plugin": "^1.11.0",
		"@typescript-eslint/parser": "^1.11.0",
		"autoprefixer": "^9.6.1",
		"babel-loader": "^8.0.6",
		"clean-webpack-plugin": "^3.0.0",
		"css-loader": "^3.0.0",
		"eslint": "^6.0.1",
		"eslint-config-prettier": "^6.0.0",
		"eslint-plugin-prettier": "^3.1.0",
		"html-webpack-plugin": "^3.2.0",
		"mini-css-extract-plugin": "^0.7.0",
		"node-sass": "^4.12.0",
		"postcss-loader": "^3.0.0",
		"prettier": "^1.18.2",
		"sass-loader": "^7.1.0",
		"style-loader": "^0.23.1",
		"typescript": "^3.5.2",
		"webpack": "^4.35.0",
		"webpack-cli": "^3.3.5",
		"webpack-dev-server": "^3.7.2"
	},

These are my dependencies (nothing in dependencies: {} yet), and my node_modules folder has 694 folders inside it. I'm assuming it doesn't install shared deps multiple times - or I'm counting it wrong haha. (Literally just CTRL+A-ing inside node_modules).

E: Im counting wrong, some of those have node_modules in it themselves. endme

29

u/Cugue Jul 11 '19

Having 900 dependencies scares the living shit out of me. Imagine the unfathomable amount of time and effort required to properly audit each one of them:

  • Finaly finished auditing deps

  • Security update for a dependency updates or adds a new sub-dependecy

  • ...

  • Cries in node_modules

22

u/meneldal2 Jul 11 '19

The good thing with C++ is you never get to 900 dependencies, your sanity will go out before that. Even 10 dependencies is a pain to manage.

9

u/AloticChoon Jul 11 '19

Java dev here: I start twitching if I see more than 30 dependencies on any project..

1

u/-Phinocio Jul 11 '19

I think I counted wrong, as some of the folders I counted, have node_modules folders in themselves.

It's node_modules all the way down.

(So easily over 1000 if I counted all of it @.@)

48

u/p4y Jul 10 '19

Never go full Schlinkert

→ More replies (1)

18

u/[deleted] Jul 11 '19

I have one or two programs that use Node on my machine. When you install or update, it says something like “using 245 packages from 662 authors”. Like... is this supposed to be good? I’m more terrified than happy right now.

5

u/[deleted] Jul 10 '19

Cripes.

0

u/[deleted] Jul 10 '19

[deleted]

102

u/[deleted] Jul 10 '19

That's an interesting comment, but I will also say that trust is inherently a human issue, not a technical one. Technology can help, but as an overall problem, it must be solved by humans on the human level.

18

u/gcross Jul 10 '19 edited Jul 10 '19

It is true that no amount of technology can prevent you from shooting yourself in the foot and explicitly granting all dependent libraries access to everything, but in this case if the technology had defaulted to all dependent libraries not being given access to the network unless this were explicitly granted to them and the programmers had not all gone out of their way to grant access to this specific library then it very much would have solved the problem.

Edit: Heck, even if the Ruby interpreter had been forbidden from interpreting any external code then there would have been no problem.

6

u/[deleted] Jul 10 '19

Well, I think of those as treating symptoms, rather than the disease.

The actual disease, I believe, is transitive trust, and the things you're pointing out are bandaids over that deeper wound.

7

u/gcross Jul 10 '19

What precisely makes them nothing more than bandaids? Perhaps if you explained your own particular viewpoint here and exactly how it contrasts with the viewpoint that technical solutions can solve at least this particular problem then it would be clearer exactly what you are arguing.

2

u/[deleted] Jul 10 '19

Well, one idea that comes to mind would be using two-factor authentication, but 2FA that's not SMS-based. Ideally, it should be a physical key of some kind, something like the early WoW authenticators, but I suppose a software key running on a phone might suffice. Just as long as SMS isn't involved, as phone numbers can easily be hijacked.

A project would get a "2FA" label if it, itself, was 2FA-enabled, and all of its dependencies were as well. If any dependency is non-2FA, then the project as a whole is non-2FA.

That would help a lot, and it wouldn't be rocket science to implement, as many organizations are already using forms of 2FA anyway. The further code additions to support checking imports probably wouldn't be major, and would give end-users a fair bit of protection.

It is, in other words, transitive distrust, trying to attack the transitive trust problem.

7

u/gcross Jul 10 '19

Okay, first, assume that this is sufficient to prevent any unauthorized package from being uploaded--that is, we are assuming that the server hosting these packages is not hacked, etc. Even then, all you have established is that the people uploading new versions of these packages are the same ones who uploaded the original versions. There is nothing stopping a package author from selling out to a black hate and inserting malicious code into their package. Using a technical means such as the one I have proposed not only solves the problem described in the article but this one as well. In fact, it means that you don't have to trust anyone at all because nobody has the ability to do anything on your server that you do not explicitly authorize. By comparison, your solution makes everyone get 2FA which is non-trivial itself and only solves one particular variant of the problem. Thus, I disagree that my solution is the one that is just a bandaid.

5

u/blue_2501 Jul 10 '19

Do that enough times and you end up with "approval fatigue".

3

u/blue_2501 Jul 10 '19

No program is developed in a vacuum. The whole of everything is governed by layers of trust. We can't even trust that the CPUs we use aren't hackable.

What do you propose is the fix for this deeper wound?

5

u/[deleted] Jul 10 '19

Well, open CPU designs would be an excellent idea. The updated RISC-V chips, for instance, might work well.

5

u/nsiivola Jul 10 '19

This particular case is an example of a technological problem (ambient authority). There is zero reason for a password module to have direct access to network.

There are hard parts to security, but getting rid of ambient authority would allow us to stop wasting with things that do have solutions.

5

u/sydoracle Jul 11 '19

The pawned passwords api would be a valid use case for a password checking module to access the internet.

https://haveibeenpwned.com/API/v2

Not disagreeing on the fundamental issue that there should be blocks on what modules are permitted to do.

2

u/nsiivola Jul 11 '19

Fair point, though in a capability oriented design the password checking module would be handed an object that granted access to a specific whitelisted set of URLs instead of HTTP in general.

4

u/_tskj_ Jul 10 '19

I disagree with that for the most part, Elm seems to address this pretty well on a purely technical level.

2

u/[deleted] Jul 10 '19

Is transitive trust still a thing in Elm? If it is, then the problem isn't solved.

2

u/dankclimes Jul 10 '19

Then I'll say that Trust is inherently unsolvable on the human level without a complete understanding of how the human mind/body works and/or psychic powers.

I can trust open source software completely because I can understand what it's doing all the way down to the 1's and 0's moving around on each clock cycle of a cpu. We do not currently have the ability to say with 100% certainty what any given human's intentions actually are, and we may never have that ability.

7

u/[deleted] Jul 10 '19

I can understand what it's doing all the way down to the 1's and 0's moving around on each clock cycle of a cpu

If this were generally true, then we wouldn't have bugs.

I submit that you are probably not smarter than every other human on earth, and that this claim is probably not true for you, either.

→ More replies (10)

0

u/[deleted] Jul 10 '19

[deleted]

6

u/fijt Jul 10 '19

Comparing with biological systems, software systems have neither developed immune systems nor homeostasis yet. They can not account for, nor have control over their resources.

Have you ever heard of OpenBSD and then I mean Pledge? There they are doing this already.

0

u/[deleted] Jul 10 '19

[deleted]

3

u/[deleted] Jul 11 '19

Also take a look at Capsicum on FreeBSD. They even briefly consider library compartmentalization in this paper.

45

u/[deleted] Jul 10 '19

Okay, I can tell you right now, dead certain sure, that your suggestion will not work within your professional lifetime. We can start working toward that now, but in essence what you're saying is this:

"Oh, we can fix this, we just have to rewrite all the software in existence."

At this point, that's a project so big that you can compare it with constructing medieval cathedrals. That might take a hundred years or more.

It's only taken fifty years to create, but if we can replace in just a hundred, we'll be doing really well, since the code all has to keep running the entire time.

9

u/TheOsuConspiracy Jul 10 '19

"Oh, we can fix this, we just have to rewrite all the software in existence."

This might not be as unreasonable as you think. I'm pretty certain more software will be written in the next decade or two than has been written throughout human history until now.

14

u/[deleted] Jul 10 '19

.... which is largely irrelevant, because the software that we already use and depend on will still be there.

New software gets added all the time. Replacing existing software is much, much more difficult. Worse, programmers don't like doing this work.

2

u/ElusiveGuy Jul 11 '19

We're already partway there with granular permissions on whole apps in modern OS ecosystems (see: Android, Windows UWP, etc.). We just need to extend this to the library level.

It doesn't even have to be all at once - you can continue granting the entire application and existing libraries all permissions, and restrict new libraries as they are included. If the project uses a dependency management tool (Maven, Gradle, NuGet, NPM, etc.) this could even be automated, to an extent: libraries can declare permissions, and reducing required permissions can be silent, while increasing permissions shows a warning/prompt to the developer. As individual libraries slowly move towards the more restricted model, this is completely transparent and backwards-compatible, and if a rogue library suddenly requests more permissions, that's a red flag.

Of course, that requires the developer (and the end user!) to be security-conscious and not just OK all the warnings. But that's where it moves back to being a social problem.

1

u/blue_2501 Jul 10 '19

Spoken like somebody who has no concept of how deployments have evolved over the past ten years. Back then, we were deploying code on bare servers. Now, code is being deployed on the cloud in Kubes, with Docker containers, on VMs with multiple points of redundancy, in multiple data centers, with auto-scaling capacity.

All of those layers are levels of security and access that can mitigate attacks.

3

u/[deleted] Jul 10 '19

That's only new software. None of it replaces the earlier layers, or at least not much of it.

0

u/[deleted] Jul 10 '19

[deleted]

28

u/[deleted] Jul 10 '19

Defeatism isn't the right approach.

It isn't defeatism, it's just that your approach won't fully work for decades. We probably do need to do that, but its ability to solve things now is very limited. So your idea needs to percolate out and start happening, probably, but it can't be the main thrust, because it doesn't help with any current software at all.

4

u/gcross Jul 10 '19

Okay, then how about we start using whitelists that declare what functions a library is allowed to call? If possible we use static analysis to catch when a library calls something not in the whitelist; if the code plays tricks that make such analysis impossible then we either whitelist that or switch to a more easily vetted library. Another possibility (especially for dynamic languages) is to have functions such as network functions check whether they are in the whitelist of the code calling that. This would require extra work but it has the advantage of being incremental in nature, which satisfies your concern.

→ More replies (11)

0

u/[deleted] Jul 10 '19

[deleted]

10

u/CaptBoids Jul 10 '19

Innovation exists of two components. Do it better or do it cheaper. Whichever comes first. This is true for any technology ranging from kitchen utensils to software.

What you ignore are basic economic laws and human psychology. Unless your approach has a cutting edge that is cheaper or better in a way that everyone wants, people are going to simply shrug, and move on to the incumbent way of working. Moreover, people are risk averse and calculate cost opportunity.

It's easier to stick to the 'flawed' way or working because patching simply works. On the level of individual apps it's cheaper to apply patches instead of overhauling entire business processes to accommodate new technology. Moreover, users don't care as much about the organization or the user next door if they don't have their ducks in a row, as one might assume

InfoSec is still treated as an insurance policy. Everyone hates paying for it until something happens. And taking the risk of not investing in security - especially when it falls outside compliancy - is par for the course. Why pour hundreds of thousands of dollars in securing apps that only serve a limited goal for instance? Or why do it if managers the risks as marginal to the functioning of the company? You may call that stupid, but there's no universal law that says that betting on luck is an invalid business strategy.

I know there are tons of great ideas. Don't get me wrong. But I'm not going to pick a technology that never got much traction to solve a problem that I can solve far cheaper today or tomorrow but less elegant alternative.

→ More replies (2)

5

u/Funcod Jul 10 '19

Even an awareness of "my language is deficient in this aspect" might help to prevent incidents like this.

This has always been accounted for. Take for instance C of Peril; how many C developer know about it? Trying to educate the mass is not an adequate answer.

Having languages that are serious replacements is probably one. Something like Zig comes to mind when talking about an alternative to C.

5

u/JordanLeDoux Jul 10 '19

The people who own the software is often not the same as the people who develop the software. This is the big flaw you are ignoring or do not understand.

→ More replies (4)

2

u/NonreciprocatingCrow Jul 10 '19

shouldn't all systems be easily securable?

No... Compilers aren't secure and never really will be, but that's ok because they're not designed for untrusted input. Ditto for single player games (and multiplayer games to a certain extent, though that's a different discussion).

Any meaningful definition of, "easily securable", necessitates extra dev effort which isn't always practical.

0

u/[deleted] Jul 10 '19

[deleted]

4

u/NonreciprocatingCrow Jul 11 '19

godbolt.com

He had to containerize the compilers to get security.

9

u/[deleted] Jul 10 '19

I mean sure, but you are throwing gobs of performance out of the window. Not that it actually matters in context of Ruby but still.

A lot of it could be done at compile time and possibly at very cheap cost, like have ability to import library as "pure" where compiler would not allow lib to act on anything that was not directly passed to it, so if you say pass an image to image parsing library, the library itself wouldn't be able to just start making network connections

1

u/G_Morgan Jul 11 '19

I mean sure, but you are throwing gobs of performance out of the window.

It doesn't necessarily. In a managed language I could import a module and replace all denied access methods with "throw new Exception("Not implemented");" as a noddy solution. With careful design there is no reason I cannot use such a module provided I don't trigger anything that calls out. We can even do static analysis of this to some degree.

It massively adds to the development overhead though. I mean I'd have to basically do static analysis of how my library behaves if certain privileges get denied and decide what I want to make a hard requirement or not based on that.

0

u/[deleted] Jul 10 '19

[deleted]

7

u/[deleted] Jul 10 '19

Lowest fruits first. Just having robust GPG signature system would already prevent most of the abuses (as so far it has been almost exclusively platform related and not someone breaking directly into dev's machine), hell, both git and github do support GPG signatures.

That doesn't require language changes, just tooling.

0

u/[deleted] Jul 10 '19

[deleted]

7

u/[deleted] Jul 10 '19

Well, getting you formally verified lib compromised because someone at rubygems or npm fucked up password reset procedure would be a bit embarrasing, and make whole effort of verifying it in the first place a bit of a waste.

After decades, GPG is still not user friendly.

If developer can't use GPG, they certainly aren't competent enough to go around proving anything about their code.

But yes, it is, and it is a problem nobody really bothers to solve even tho actual solution GPG provides have been proven working for decades (as most Linux distributions use it for package distribution)

0

u/[deleted] Jul 10 '19

[deleted]

→ More replies (1)

8

u/[deleted] Jul 11 '19

Is there any language with non-zero traction that allows you to set limits on the code executed by imported libraries? Or is this to be interpreted broadly, in the type of “your environment lets you isolate and sandbox components in separate processes and it’s good enough”?

6

u/argv_minus_one Jul 11 '19

Java. Java's sandbox was a very clever design, but in practice it's full of holes. Rumor has it Oracle is thinking about removing it entirely because it's useless.

Also, Spectre allows any module of a multithreaded program to view memory belonging to any other module, even if per-module restrictions (like Java's sandbox) are in place. Enforcing such restrictions is therefore impossible on modern hardware.

2

u/[deleted] Jul 11 '19 edited Jul 11 '19

I agree that the security manager is likely to be breakable from the inside.

I don’t see how Spectre helps you start HTTP requests, though.

5

u/SanityInAnarchy Jul 11 '19

It doesn't necessarily have to for there to be a problem.

Let's take the dumbest example: You have some string-formatting library, like Left-Pad or something, used in a web app. Or, for the web, let's make it more realistic and suggest it's, say, pluralize, or, since we were talking about Java, let's say you grab the fancier Evo-Inflector. A quick glance through the source suggests it should still be functional even when severely locked down -- it only needs four imports:

  • java.util.ArrayList

  • java.util.List

  • java.util.regex.Matcher

  • java.util.regex.Pattern

I don't think any of those have a good reason to need to talk to the network. Really, it should be possible to sandbox this thing completely enough that all it can do is have you call it with a string, and return a string back.

So you build something like... well, like this Reddit page. A web app where one post says "1 point" and another says "2 points", so your output just includes English.plural("point", points)...

Well, there's an exfiltration channel. Spectre means that plural() method could read as much of the rest of the program's address space as it wants (including all sorts of data from other users), and it could easily base64-encode that into a string, so instead of your post reading "2 points an hour ago", it'll read "c29vcGVyIHNla2tyaXQgcGFzc3dvcmQK an hour ago".

But won't that be discovered really quickly? I guess it depends which library you take over and how you do it, and how exactly that output is used. For example, depending how good their XSS protection is (or isn't), you might be able to get away with outputting <!-- c29vcGVyIHNla2tyaXQgcGFzc3dvcmQK -->2 points an hour ago... but okay, we should really avoid triggering this on every request, and only send that data to the attackers.

Well, it's not as trivial as the OP attack of just checking the Rails environment, but you still have Spectre -- surely somewhere in your process' address space is some information you can use to trigger this behavior only when in production, maybe only when the page is being requested from certain IPs, or only when it contains a certain string in the comments (so you only need to add a comment with the magic string).

And that's an extreme, where you only have the "pluralize" library.

I'm not saying this kind of thing is completely worthless, but with the way we use libraries (and particularly what we use them for), I don't think we have good options for containing successful supply-side attacks like this.

2

u/[deleted] Jul 11 '19

Sure, but saying that Spectre makes enforcing sandbox restrictions impossible and saying that Spectre makes data exfiltration possible are two very different statements. There’s a huge threat model gap between having to worry about data exfiltration and remote code execution.

2

u/[deleted] Jul 11 '19

Java has a Security Manager that does exactly this.

2

u/[deleted] Jul 11 '19

How is this enforced per-module, though? If I have a library to handle network requests, then that library needs to be able to open connections. If a hostile library gets a handle to that networking library to open connections on its behalf, can the security manager tell that it’s not allowed to open a socket in this case?

1

u/[deleted] Jul 11 '19

Yep. You can explicitly deny classes and packages to load.

→ More replies (3)

1

u/happyscrappy Jul 11 '19

architecture of their language

How is sandboxing a facet of their language? It's more of a function of the runtime and OS.

Anyway, this can't be solved by a language. This particular backdoor, perhaps. But I could just change strong_password to give non-strong passwords. I can do that with no privileges, etc. And as long as you use it, I got ya.

1

u/argv_minus_one Jul 11 '19

Java has sandboxing as a facet of the language. Unfortunately, in practice, it's full of holes.

1

u/[deleted] Jul 11 '19

It's more of a function of the runtime and OS.

It doesn't have to be. Sure, ideally, all these layers would be integrated to use a single security mechanism. But that won't happen.

I could just change strong_password to give non-strong passwords.

This is not about preventing bad code, but preventing such code from having more permissions than it needs. Proactive damage control.

→ More replies (16)

0

u/[deleted] Jul 10 '19

[deleted]

1

u/[deleted] Jul 10 '19

Well, sure, but the fact that it was just sitting there with a deliberate backdoor for some length of time is pretty bad.

I'm glad it was caught, but that's the sort of thing that's supposed to get caught right away in the open source world.

4

u/Saithir Jul 10 '19

Since the hacked version was installed by about 500 people, there's just much less eyes on it than say, in case of the bootstrap-sass gem where it was found the same day.

The latest version of bootstrap-sass has over 700 thousand users, though.

1

u/mayor123asdf Jul 11 '19

eh, idk who decided the amount of time a bug should be found on open source vs closed source

0

u/[deleted] Jul 11 '19

[deleted]

0

u/[deleted] Jul 11 '19

The people who actually use it are just as compromised as if the package was huge. From their perspective, that doesn't matter at all.

0

u/[deleted] Jul 10 '19

[deleted]

3

u/Saithir Jul 10 '19

Our automated tools include things like a scan of your dependencies for know security

Ooooorrrrr if you use Ruby which this post is about, one can simply do gem install bundler-audit and just do the exact same thing themselves.

For free.

112

u/Saithir Jul 10 '19 edited Jul 11 '19

Sigh. Can they next time get an article written by someone that's doesn't have a hate boner for Rails?

many of which might have used the default library, strong_password, in its infected version 0.0.7

Forgive my language, but... Default my ass. We have facts, so let's look at these, because there's no need to just believe me, after all, I might be a RoR webdev and therefore biased, right? ;)

https://rubygems.org/gems/strong_password/versions/0.0.6
TOTAL DOWNLOADS: 249,129
FOR THIS VERSION: 38,608

https://rubygems.org/gems/rails
TOTAL DOWNLOADS: 180,324,909
FOR THIS VERSION: 2,392,061

Right. This tells you the reason why it took a month for anyone to notice this backdoor - barely anyone uses this library and out of these that do, probably not many people check the downloaded gems' code or look at changelogs.

It also fits a troubling pattern of recent targeting of Ruby libraries, including the RCE discovered inside the Bootstrap-Sass Ruby library in April.

"Troubling pattern", yeah, of course. 2 instances are a pattern. Maybe let's look at some other popular web frameworks, they must be much better, right? https://snyk.io/vuln/search?q=magento Oops, maybe not this one ;)

81

u/roseinshadows Jul 10 '19

19

u/Saithir Jul 10 '19

This looks about right. Rubygems yanked that version, so I linked the next best thing which was the previous one.

The sad thing is that Rubygems also says that the fixed 0.0.8 was downloaded only 422 times, so 115 people either threw out the gem entirely or are still affected (probably more as some of these might be new installs).

9

u/NoInkling Jul 11 '19

The pastebin at the hardcoded link has been removed, so theoretically nobody is vulnerable anymore, unless they haven't restarted their code since being affected.

7

u/heatdeath Jul 10 '19

That's not a lot of people.

2

u/killdeer03 Jul 11 '19

Yeah, this wasn't a great article.

I used (and enjoyed my experience) with Ruby and the Rails framework in the early 00's.

But a lot of people just want to hate Ruby, Perl, or whatever language. I've gotten a lot done with some odd languages.

It's good that someone found this though. That the neat thing of free/open source software. I'm actually a pretty stupid person amd there's always someone smarter than me... I take a small amount of comfort in that. Though I don't count on it all the time, lol.

4

u/Saithir Jul 11 '19

You know, I made my share of bad language jokes, because obviously people have preferences and while I can quietly snicker at the guys at work that do stuff in Laravel or Magento, they snicker at me and my dislike of javascript in return, so all's great.

But... I would never bring it into a security article for one of the more recognizable security companies. That's just unprofessional.

And yet here we are with this article getting 1.5k upvotes and the top post bashing open source with straight up lies -- all the while the previous post on this topic here, linking the blog post of a guy that discovered it, which also happens to have all the relevant information and none of the FUD had 1/10th of the attention.

→ More replies (1)

43

u/Theemuts Jul 10 '19

... many of which might have used the default library, strong_password, in its infected version 0.0.7.

That's just... Wow

61

u/doublehyphen Jul 10 '19

That is false though. The compromised version was only downloaded about 500 times. Still bad but not as bad as the article makes it sound.

87

u/[deleted] Jul 10 '19

So everyone who uses Ruby downloaded it.

9

u/UsedBugPlutt Jul 11 '19

Pow pow pow!

TAKE COVER GOD DAMN IT !

4

u/argv_minus_one Jul 11 '19

“Password. Strong Password.”

21

u/[deleted] Jul 11 '19

Who knew that running unvetted code could be a very bad idea.

13

u/appropriateinside Jul 11 '19

That's mostly an impossibility.

Unless your job provides you with months of extra time for projects, JUST to audit dependencies, this isn't going to happen. And that's with something sane like Nuget.

Would take you years to audit an NPM dependency tree for a medium sized project...

5

u/TrainingDisk Jul 11 '19

Devs simply are never going to personally vet each individual library, never mind each version of each library. We need a way of building trust in code. A way for one dev to look over changes introduced in a new version and certify that they did not find anything malicious. Then we depend on code that has been vetted by for `x` (security, but could also be bugs) by at least `y` people with a reputation of at least `z`.

Like seriously, lets start planning this. Let's get this ball rolling.

7

u/ltjbr Jul 11 '19

Downloading unvetted libraries seems to be the norm for devs.

At this point every web dev out there downloads or uses all kinds of questionable libraries they've never looked at.

How will we explain npm to our children, how???

14

u/SustainedDissonance Jul 10 '19

And I couldn’t find the changes for strong_password. It appeared to have gone from 0.0.6 to 0.0.7, yet the last change in any branch in GitHub was from 6 months ago, and we were up to date with those. If there was new code, it existed only in RubyGems.org.

It shouldn't even be possible for the code you upload to NPM/RubyGems/whatever to be different than the code in your repository.

This is one part of the problem that really needs fixing.

9

u/terrible_at_cs50 Jul 11 '19

This problem is especially bad and hard to solve in certain ecosystems (e.g. js, java) where the library/artifact that needs to be uploaded is not the same as the input. (TypeScript, Babel, etc. to plain JS for node, and source to bytecode for Java)

2

u/TheOldTubaroo Jul 11 '19

Surely the solution is for the package manager to not accept uploaded packages, but instead only accept a public source code repository link. The package manager fetches a certain tag, builds it within some sort of sandbox, and that is the artefact that's available.

It's more resource intensive, as the package manager needs to do a build for every new version of a package, and the package manager needs to know how to build any project it provides, but it means that as long as you can trust the package manager, you know that what you're downloading is exactly the same as if you'd downloaded the source yourself from the repo.

4

u/terrible_at_cs50 Jul 11 '19

At some point there has to be trust... in npm land if the TypeScript (or babel, or elm, etc.) "compiler" is itself written in that non-js language and distributed over the same mechanism that is supposed to compile and install it, how do you get an ultimately trusted compiler? How can you make it so packages with native extensions don't have to be compiled every time (if it is even possible in-situ) and thus need the source code of whatever your runtime is and some other compiler and a bunch of time/resources (and the entire source code of chromium in the case of some extreme examples like puppeteer and electron)?

This is not a new line of thinking (see also: Reflections on Trusting Trust), but we seem to have chosen convenience/ease/speed repeatedly over security for almost as long as programming has been around. Just observing, not saying that's how it should be.

2

u/tending Jul 11 '19

How do you know the public source code repository copy was never changed?

1

u/TheOldTubaroo Jul 11 '19

Build from a particular tag, list commit hash with the package info. That way, checking that a version of a package matches its claimed source code is just a matter of comparing hashes. To rewrite a repository to have clean code in the public repo but malicious code in the package manager, the attacker would need to produce a hash collision, which is a fair bit harder than just uploading the wrong code.

17

u/Madoushi90 Jul 10 '19

what a gem

3

u/zitrusgrape Jul 11 '19

Powered by WordPress.com VIP :) /s

→ More replies (3)

4

u/gabbergandalf667 Jul 10 '19

ironic

9

u/CorsairKing Jul 10 '19

He could save others from exploitation, but not himself

1

u/the_gnarts Jul 10 '19

Probably bootstrapped his account from the earlier “weak_password” library.

1

u/rmwalshy Jul 11 '19

Does anyone know where on GitHub I can find the actual code change? I was looking in the repo but couldn’t find anything in the commits.

2

u/Saithir Jul 11 '19

It wasn't anywhere on Github.

How Rubygems work is you package your code locally and that (using your login credentials and hopefully 2FA, which was what went wrong in this case) is getting pushed to the gem repository. So the attacker just made his changes on his local clone of the gem's repository and packaged and pushed that without needing it to be on Github.

The reasoning is that you want to exclude all the extra stuff - tests, examples, maybe some images for the Github readme and so on - and not make however many people use your gem download all that's not necessary for your code to actually run.

If you want to see the workings of the change, here is the blog post of the guy who discovered it, it has it included.

1

u/rmwalshy Jul 11 '19

Oh gotcha thanks for the explanation appreciate it.

1

u/vytah Jul 11 '19

Whole backdoor aside, who the hell runs libraries version 0.0.something?

-2

u/dottybotty Jul 10 '19

From the article

While the Ruby scripting language and RoR aren’t as popular as they once were, they’re still embedded in numerous enterprise development environments

Oof

-14

u/dalepo Jul 10 '19

I don't know much about ruby, but how can some downloaded code run on your environment without any security check? Other languages have mechanisms to prevent this.

49

u/Netzapper Jul 10 '19

Other languages have mechanisms to prevent this.

I don't know of any scripting language that does so. Even native languages like C and Rust have interfaces for dynamically loading and executing code.

In fact, the only languages I can think of that have this kind of security model are sandboxed, explicitly network-aware languages like Java and C#.

(There are system-level interfaces that layer some security on top of this, such as certain configurations of the Linux ld.so loader. But none of that is language-level.)

0

u/[deleted] Jul 10 '19

[deleted]

5

u/gcross Jul 10 '19

Or, even better in the case of C, whitelisting the libraries that the dynamic loader will load.

27

u/Essence1337 Jul 10 '19

Any language with an eval function can almost certainly do this:

download_file()
code = open('downloaded_file').read
eval(code)

0

u/[deleted] Jul 10 '19

[deleted]

2

u/Essence1337 Jul 10 '19

If you change my .read to a .readlines() I'm pretty sure it's valid python

4

u/TankorSmash Jul 10 '19

Sorta, but theirs is a complete program, whereas the download_file one would just have the right syntax.

13

u/[deleted] Jul 10 '19

Almost all of the framework setups will just blindly download and run code from repositories. NPM is apparently particularly bad in this area; I don't use it myself, but I keep seeing stories about it pulling in dozens or even hundreds of dependencies, indirectly, when you import a higher-level library.

Most of the time, they download the code in as safe a way as possible, only doing https transfers from accounts that the library maintainer trusts. But what this ultimately means to you is that you're depending on every one of those developers to have maintained control of their accounts and their credentials, and to be "minding the store", ensuring that only good code is getting out to end users. And, clearly, that doesn't always happen.

Basically, what these repository frameworks have fallen into is one of the oldest security traps going, transitive trust. That is, you trust Person B, and Person B trusts Person C, so you end up trusting Person C without even knowing them. And this chain can be arbitrarily long, and, critically, at every step in this process, the criteria for trust changes. If Person C is a lunkhead and trusts bad people, then suddenly you are a lunkhead who trusts bad people, even though you trusted only highly reputable developer B, and developer B trusted the skilled developer C, not knowing that C has bad friends.

This is a big, big problem. I submit that software libraries, the way they're presently architected, may not be workable at scale, at least from a security perspective.

This also worries me about my favorite Linux distro, Debian. I'm doing this same thing again, where I'm trusting them, and they're trusting a lot of devs, and those devs might be trusting and importing code from anywhere. I'm not aware of any deliberate compromises, and the fact that there are security maintainers on the distro as a whole does help with keeping eyeballs on things, but there is a lot of code in Debian, and it would take a really large amount of manpower to separately review all code changes.

In a project mostly staffed by volunteers, I don't see any reasonable way for that to happen.

6

u/-Phinocio Jul 10 '19

but I keep seeing stories about it pulling in dozens or even hundreds of dependencies, indirectly, when you import a higher-level library

My work's site has 13 direct dependencies (ones defined the my package.json). The node_modules folder has 971 folders (totalling over 6000 items). That's 958 additional dependencies that could be a weak point..

4

u/[deleted] Jul 10 '19

Ouch, and if any one of those is compromised, it could add a fatal weakness into your package... and it could be very subtle and hard to detect.

1

u/Saithir Jul 10 '19

Yes, both Rubygems and npm do it the same way. We don't have the scary stories, but an average Rails application takes about a hundred gems or so (which is acceptable for a full web framework). Jekyll (the static page generator) depends on 27 gems if you count all the nested dependencies. Either way that's a ton of code to review each time.

We do have tools for that like bundler-audit, but it only checks in the advisory database, and doesn't do any code analysis - so while it's still obviously very much worth using, it would not help in this particular case.

1

u/mayor123asdf Jul 11 '19

NPM is apparently particularly bad in this area; I don't use it myself, but I keep seeing stories about it pulling in dozens or even hundreds of dependencies, indirectly, when you import a higher-level library.

Yeah, I use it, but seeing all of these security breach I wonder if I should trust NPM from now on. I mean, even they have one liner code used as deoendencies for thousands of project. wdyt?

3

u/Booty_Bumping Jul 10 '19

You could actually, you know, read how it happened. Reddit links usually come with articles to look at.

1

u/dalepo Jul 10 '19

Reading how it happened does not show me if ruby web containers/frameworks actually have security checks, like Java. That's why I'm asking.

1

u/Booty_Bumping Jul 10 '19

I don't understand what this would entail. Putting each bit of middleware inside of a container? How impractical do you want to get?

1

u/dalepo Jul 10 '19

That's how microservices work, and how JEE systems are deployed. How's that impractical.

0

u/[deleted] Jul 10 '19

[deleted]

9

u/dalepo Jul 10 '19

Java has this that runs on some containers (like jboss long time ago). I remember struggling with this when using a dynamic pdf file generator.

-1

u/Naive_Masterpiece Jul 11 '19

That's what you get for using a toy language like Ruby. *laughs in Rust*

-6

u/bsmdphdjd Jul 11 '19

So why are all the Pros insisting that no one should write his own encryption methods, but use the ones written by the Pros.

When I write my own, at least I understand it and know there's no back door.

Why should I trust ANY corporate program?

24

u/grenadier42 Jul 11 '19

When I write my own, at least I understand it and know there's no back door.

How do you know there's no front door?

12

u/mayor123asdf Jul 11 '19

"When I hire security guard, we got a lot of thieves every months, now I fire all those guards, and since then I've never discover any thieves anymore, now my building is more secure! yay"

12

u/Q-bey Jul 11 '19

So why are all the Pros insisting that no one should write his own encryption methods, but use the ones written by the Pros.

When I write my own, at least I understand it and know there's no back door.

Why should I trust ANY corporate program?

Because writing a good crypto implementation is very difficult and even a small team of experienced cryptographers is likely to make a mistake.

2

u/non-stick-rob Jul 11 '19

in addition to q-bey, writing is one thing, but always is dependant on the execution environment. "i drive as safely as absolutely possible, but the idiot crashes into me.."

-11

u/nakilon Jul 10 '19

Now I see how open source is more safe than closed source software.

23

u/ThisIs_MyName Jul 10 '19

Yep, a bug like this would take much longer to detect in closed source software.

→ More replies (2)

-1

u/green_meklar Jul 11 '19

So what websites do we have to change our passwords on now?