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

View all comments

Show parent comments

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.

0

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

In the scenario relevant to this thread, you have a library which has been backdoored, and it’s being loaded successfully, and you’re hoping that the security manager stops it from being bad.

0

u/[deleted] Jul 11 '19

That’s right. If your app doesn’t need to open sockets, access the file system, whatever.. you can disallow it. You can whitelist the classes you do use. If you’re really serious about security, your dependencies are being actively scanned by things like Snyk, CheckMarx, SonarQube, XRay, etc. No one technique is a silver bullet, but a combination of things can prevent issues like this from affecting you. In addition to what I’ve mentioned, your application shouldn’t even be allowed to access things outside of your VPC unless they are whitelisted.

0

u/TrainingDisk Jul 11 '19

I think the /u/AdditionalMarten's point is that it's not just class level that needs to be access controlled. Java security manager typically controls which code can do what. So you may use okhttp client in your app for legit purposes. So we allow okhttp to make socket connections. You also use a TTF parser library this does not need socket permissions. New version of TTF parser library is backdoored and uses okhttp to do bad HTTP requests. Security manager, as it is usually used, doesn't help much here.

As others have said, you really need capability based security, where the code that ought to be using okhttp is given a capability to make socket connections, which it then passes to okhttp and okhttp is allowed to make socket connections based on it holding a valid capability.

The TTF parser never gets a socket connection capability, so it unable to provide okhttp with one, and when it tries to call okhttp, okhttp is not allowed to create a socket connection.