TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Secure Your REST API

115 pointsby chunsakerabout 12 years ago

10 comments

tptacekabout 12 years ago
You should probably disregard this advice. Instead:<p>[Late addition:<p>* Do not use passwords as API authentication. The user of an API is a computer program, not a human. Issue single-purpose random credentials for API access.]<p>* Make sure that your API is accessible only over HTTPS; test the API endpoint to ensure requests aren't honored over unencrypted HTTP.<p>* Use the simplest API authentication mechanism that (a) works and (b) you understand. You should probably degrade the capabilities of your API before you try to adopt an authentication system that you don't completely, fully, absolutely grok.<p>This means, if you don't need delegation right away (for instance, if you don't have 3rd party applications making calls to your API on behalf of your users), don't bother with anything like OAuth.<p>Contrary to the implications in this article, HTTP Basic Auth is not less secure than OAuth if your endpoints all require HTTPS. If you allow HTTP calls to an API, you have bigger problems than your auth token scheme.<p>Semantic mismatches between API endpoints and web UI endpoints (ie, semantic differences between API auth and cookie-based authentication) are a classic, pervasive, hard- to- eradicate source of serious security flaws. Don't make things any more complicated than they need to be.<p><i>[Late edit: I didn't think I needed to make the first point, but I clearly did need to. Sorry.]</i>
评论 #5567941 未加载
评论 #5566267 未加载
评论 #5566226 未加载
评论 #5567108 未加载
评论 #5566934 未加载
评论 #5568777 未加载
评论 #5566471 未加载
评论 #5566407 未加载
评论 #5567720 未加载
评论 #5566837 未加载
wereHamsterabout 12 years ago
Please stop using the term UUID when you mean 'random alphanumeric string'. Because UUIDs have a standardized format (it's not just a random string): <a href="http://en.wikipedia.org/wiki/Universally_unique_identifier" rel="nofollow">http://en.wikipedia.org/wiki/Universally_unique_identifier</a>
评论 #5566066 未加载
评论 #5566563 未加载
jrochkind1about 12 years ago
&#62; Best practices say to encrypt your passwords in the database to limit a potential data breach. This increases overhead for each request when authenticating a user. Unique API keys authentication skips the hashing step and therefore speeds up your calls.<p>Wait, why can you can skip the hashing step and still be secure? Because hashing is only neccesary if you call it a 'password', but not if you use it in the same way but call it an 'api key' instead?<p>I guess it depends on the purpose for hashing. If it's just about 'data breaches', then maybe it doesn't matter if your api keys get out... because they at least won't grant access to any _other_ systems, since they weren't manually entered by users and re-used accross systems. Is that what you're thinking?<p>But don't you still want to avoid a data breach like this for your _own_ service?<p>And, I think, isn't the other reason hashed passwords are used, to make it harder to do a brute force attack? Ie, it's quite intentional and deliberate that it increases request overhead. And doesn't this still apply to an api key, possibly even MORE so when you have a single api key instead of a username/pass combo?
评论 #5566218 未加载
评论 #5566889 未加载
knkellaabout 12 years ago
What are your thoughts on Amazon like security scheme? As far as there are no third party apps involved, I think OAuth is an overkill.<p>What I mean by Amazon like securtiy is described in this article <a href="http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/" rel="nofollow">http://www.thebuzzmedia.com/designing-a-secure-rest-api-with...</a>
评论 #5566622 未加载
评论 #5567362 未加载
alinajafabout 12 years ago
Does anyone know of a good reason not to use TLS with client-side certificates (and you as the CA) for API authentication?
评论 #5566596 未加载
评论 #5566107 未加载
pplanteabout 12 years ago
In my humble opinion, security through obscurity via UUIDS rather than sequential integers is not great advice. It merely masks the real problem.
评论 #5566255 未加载
评论 #5566371 未加载
nicwolffabout 12 years ago
Shoots down Basic auth without SSL, without mentioning Digest auth, weird.
评论 #5566359 未加载
评论 #5566135 未加载
评论 #5566599 未加载
cicloidabout 12 years ago
Didn't oAuth2 support signed requests via MAC token on request?
mcavageabout 12 years ago
I expected something very different from this article based on the headline. Specifically, I completely disagree with the "leave it to industry standards" approach, as that doesn't help people understand what they should do, and more importantly, why.<p>Request/response protocols (well, many things) really break down into 5 top-level categories (some sources will say the 6th is Audit):<p>- Authentication<p>- Authorization<p>- Integrity<p>- Confidentiality<p>- Non-repudiation<p>It's a far more interesting exercise to walk through what you would get from each solution. Basic-Auth over TLS, actually gets you quite a ways towards that goal (specifically, C-I-A (authentication)). Where that, and notably HMAC, fall over is non-repudiation because they're based on a shared-secret model; admittedly HMAC keys are better than passwords because you're not sending the secret on every request, but asymmetric crypto is preferred. Authorization that the server system does is really out of scope in all of these protocols, so Basic-Auth over TLS doesn't really impact that one. It can be as simple as "caller = owner," or as full-featured as a security policy language [1] (full disclosure: I am the original author of [1]).<p>OAuth really doesn't differ that much besides specifically solving the delegated access and website SSO problem(s); but IMO it does so with an overly baroque protocol that has too many parts. The "long pole" of setting up such a system (that is, allowing 3rd party sites to act on behalf of my site's users) isn't the specifics of what my REST api looks like, but really it's all the "governance" of user decisions, and more-over, key management (in all these cases, key management is generally the hardest or almost hardest problem).<p>While it can be debated whether it was right or wrong, we (Joyent) released an open-source spec to solve straight up authentication of REST requests using SSH keys [2]. At the end of the day, the user signs the Date header of requests with their private key (which by definition the server has never seen), and all requests must be over TLS. Disregarding Authorization, this scheme gives you Confidentiality (TLS), Integrity (TLS), Authentication (Signature), Non-Repudiation (asymmetric signature), and adds a "poor man's nonce," assuming you disallow requests where the clock skew of the date header is too large. And lastly, SSH solves a lot of key management problems for humans. Note: I didn't drop that reference to advocate for our specification here, but rather the security process you should think about when evaluating whether a protocol is secure.<p>[1] <a href="http://docs.aws.amazon.com/IAM/latest/UserGuide/policy-reference.html" rel="nofollow">http://docs.aws.amazon.com/IAM/latest/UserGuide/policy-refer...</a><p>[2] <a href="https://github.com/joyent/node-http-signature/blob/master/http_signing.md" rel="nofollow">https://github.com/joyent/node-http-signature/blob/master/ht...</a><p>PS<p>Mutual-Auth SSL/TLS is a royal PITA, and is basically guaranteed to cause you grief. The client compatibility matrix might as well be considered an NP hard problem to assure yourself coverage, and failure modes of the different browsers/SDKs all differ. As a REST API should have maximum accessibility to clients (i.e., don't wed yourself to any one language/sdk), this is pretty much a non-starter.<p>* edited: copy/paste formatting
评论 #5567723 未加载
dantiberianabout 12 years ago
How does using bare api keys over TLS compare to these suggestions? It's less secure but is it still a recommended option?
评论 #5566341 未加载