Live data from Hacker News

Why does your API still use HTTP Basic Auth?

swaggadocio.com

121–130 of 136 posts

Re: Why does your API still use HTTP Basic Auth?

#121
post #118

Earlier quoted context omitted.

You're only using SSL which protects you vs relay attacks (it's doing its own MAC). Authentication is being done through the HTTP request Authorization header and the attached pre shared key. Use SSL only, tune ciphers and you're good. You're wasting time trying to overthink the problem by adding another layer on top.

The problem is that it is very common for SSL client libraries to neglect to validate the peer certificate...

If you use a broken library then you're in trouble no matter what MAC wizardry you layer on top of it. You've got a core issue that is a better place to spend time solving that coming up with some sort of MAC layer to add on top.

Re: Why does your API still use HTTP Basic Auth?

#122
post #119
post #116

Earlier quoted context omitted.

Yes, I agree that the length of the key and the real randomness are the most important points and that when those are fulfilled the recipe has sense. Neither explicit length minimality nor real randomness of the key were mentioned but the SHA advice was explicit to the 256 bits. EDIT: To make it clearer: "Long" is not explicit. 256 bits is. The difference between real randomness and for example output of RND in your…

From the comment you initially replied to: "Only use the users password to obtain a long random key " (emphasis mine). So it was part of the initial recipe.

Someone can do the math but I expect a 64 character long random string is more than sufficient.

Re: Why does your API still use HTTP Basic Auth?

#123
post #99
post #93

Earlier quoted context omitted.

Storing SHA in the database or anything not produced by PBKDF2, bcrypt or scrypt is wrong and doesn't help you much "minimizing damage." Advising SHA doesn't seem to come from a real professional.

Storing the SHA-2 hash of a 256-bit random key obfuscates the API-key, so an attacker with access to the DB can't use it, but is fast to check so will remain performant. It doesn't matter how many machines you have or how fast you can compute the SHA. An attacker will not find the API key (work out the math).

Sorry I was a little inexact, when I said SHA-2 256 I meant specifically the SHA-2 256 bit (SHA-256) hashing algorithm as opposed to SHA-1 which is considered weak. Not the key length. Though I suspect a 64 character long random string has sufficient entropy.

Re: Why does your API still use HTTP Basic Auth?

#124

Earlier quoted context omitted.

In common usage the user will take an server generated API key and embed it within their application that makes API requests. Take a very typical example of a merchant selling snowboards and using Stripe to process the payments as an example. Since this API key is embedded within their app it'll require a programmer to change (and customers often may be non technical with sites built on contract). These are things yo…

If you lose the database containing either your API keys or hashes of your API keys, you need to revoke the keys. Not doing so is negligent. The correct next step after discovering that you may have lost custody of API key information is to ensure that the keys are worthless, not to scramble to try to protect the keys. This is another reason you want to be clear about the difference between a "key" and a "password",…

If you lose your DB you're in trouble regardless. We're talking about the level of trouble here. I'd rather be faced with a 30 day key rollover of all my users than a forced immediate change.

I dont see any reason to continue the argument. It's clear to me that you should hash your API keys in your DB.

Re: Why does your API still use HTTP Basic Auth?

#125
post #56

What's always needed is simply properly used TLS (https). Even wording in the article is misleading. It's not about "closing port 80" but about "using only TLS." Once you use TLS is the "HTTP basic" often the optimal solution. After reading the whole article, I still don't understand why would anybody try to make HTTP "secure" instead of simply using TLS. So my question to the author, paraphrasing the article title:…

Isn't he saying that even if the API provider requires SSL/TLS/https, an accidental http sends the username/key in plain text over the wire?

Re: Why does your API still use HTTP Basic Auth?

#126
The problem it seems to me with Stripe and others is that they stuff the API key in as the Basic Auth username. Wouldn't is be safer to use, say, a merchant ID as the username and then the API key as the password (since the password is not transmitted on the errant HTTP)?

Re: Why does your API still use HTTP Basic Auth?

#127
post #88

Earlier quoted context omitted.

Users should use "a long random key" But you should store "the key as SHA2-256 hash in your DB" why hash it?

Because if someone gets access to your database somehow you're not exposing all of the keys for all of your users. While you're likely in serious trouble if someone gets your DB this helps minimize damage. Besides to authenticate a request you dont need the plaintext of the key, a hash is fine.

Ah, that's fair

I guess the trade-off is here that the api key cannot then be retrieved from a GUI either (because the server doesn't actually know the original key!) .. from a UX perspective, most companies show your active keys in a GUI with ability to selectively remove or replace.

Though I can't think of a mainstream API that hasn't let me retrieve api key from GUI

Re: Why does your API still use HTTP Basic Auth?

#128
(I work at Stripe.)

We've thought about closing HTTP access in the past. As with a lot of security, it's a usability trade-off.

We work hard to make sure that people only ever access Stripe over HTTPS. Most people use the Stripe API through an existing library. Since the API doesn't work over HTTP, any such library is guaranteed to use HTTPS. Stripe itself is on Chrome's built-in HSTS list, sets HSTS headers, etc.

The scenario Stevie describes is unlikely to be an issue unless the user is implementing his or her own library. In that case, though, they're almost certainly going to be using test API credentials. Stripe's API will never return a successful response when you access it over HTTP, so you'll figure out that you can't do this on the very first request.

More broadly, what exactly is being defended against isn't particularly clear. There are much easier ways for someone implementing their own library to screw up (skipping cert verification is extremely common and leaves you perpetually vulnerable to HTTPS MITM), and there are many other plausible vectors for an attacker.

Even if we did change this, we'd only have solved one small class of accidental key leaks. You could accidentally specify "stripe.com" instead of "api.stripe.com", for example, and stripe.com will of course always accept HTTP. Or you could typo the domain and send your key to someone else entirely.

If we ever did want to solve this, we'd probably do something like:

- Monitor HTTP Authorization headers sent to api.stripe.com.

- Notify the user if they ever accidentally send a secret key in the clear.

- In addition to notifying the user, we could potentially roll the key automatically (though this runs the risk of breaking production code).

But I don't think disabling HTTP helps much. (I do think it'd be good if we started monitoring the frequency with which this happens -- if it's common, we should certainly do something like the above; if it ~never happens, it presumably doesn't matter.)

Separately, I think that the HMAC-based signature scheme that Stevie proposes is something we might want to do at some stage. A very early version of Stripe actually had something very similar. The issue with all protocols in this vein is that they involve considerably more complexity on the user's end and are harder to debug. But they definitely have some nice security properties.

Re: Why does your API still use HTTP Basic Auth?

#129
post #73

Earlier quoted context omitted.

I think the idea is that if the real port 80 never answers, real customers are highly unlikely to set up their apps in the vulnerable state in the first place. That said, having port 80 open, but returning an appropriate error code to all attempts to use the API, would probably have the same effect (while still answering on port 80, for anyone who just wants to ping it to see "are they up" --- one of the excuses the…

No, that's exactly the problem the post is complaining about. It still results in credentials being sent in plaintext in the original request.

Right, but the problem will be caught when the app is still in development. Then the devs will fix the app and by the time it gets to end-users, it won't do that anymore.

Re: Why does your API still use HTTP Basic Auth?

#130

Earlier quoted context omitted.

Would you mind enlightening us? If you're using API keys over TLS+HTTP Basic Auth, storing the plain API key in your database means that anyone with readonly access to the API key table can now use those accounts. (Ignoring IP filtering or something.) What am I missing?

If an attacker gets access to the key table, you are boned. Revoke all your keys. Make the keys worthless; don't take half-measures to try to protect them.

... I agree if you know an attacker has access then you should revoke. Just like if you know an employee has been compromised. But why wouldn't you store them hashed, anyways? So that if an employee has to debug something and selects more than they should, your system is not compromised?

Also, I'd say that a SHA256 hash of a 256-bit key is hardly a "half-measure". Nothing short of compromising your RNG or SHA2 will make those hashes useful to authenticate.

Post reply on HN