65

Using Apache, it is quite simple to set up a page that uses basic access authentication to prompt a user for a name/password and use those credentials in some way to grant access to that user.

Is this secure, assuming the connection between the client and server is secure?

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361
  • 1
    **See Also**: [Is BASIC-Auth secure if done over HTTPS?](https://security.stackexchange.com/q/988/24374) – KyleMit Aug 03 '18 at 21:43

6 Answers6

77

The worry about basic auth is that the credentials are sent as cleartext and are vulnerable to packet sniffing, if that connection is secured using TLS/SSL then it is as secure as other methods that use encryption.

Chris Diver
  • 19,362
  • 4
  • 47
  • 58
  • 24
    Another difference: The password is sent repeatedly, for each request. (Larger attack window) See https://security.stackexchange.com/a/990/95555 – Nateowami Apr 28 '17 at 09:50
  • 2
    so it's secure or not? :-D – Bruno Dec 12 '18 at 14:15
  • 1
    @BGBruno my 2 cents: if you don't use SSL, it is not secure. If you use SSL, it will depend on your application. One-off REST requests are fine IMHO as long as there are other server-side security measures (to avoid DoS or brute force attacks, for instance). However, you're better off using something more elaborated for more complicated authentication scenarios. For example, you should most definitely not use it as your website login. – lotif Mar 13 '19 at 19:15
  • thx @lotif - I study this theme for long time and for now I use #jwt+xcsrf – Bruno Mar 15 '19 at 15:16
30

This is an old thread, and I do not believe the highest voted/chosen answer is correct.

As noted by @Nateowami, the security stack exchange thread outlines a number of issues with basic authentication.

I'd like to point out another one: if you are doing your password verification correctly, then basic authentication makes your server more vulnerable to denial of service. Why? In the old days, it was common belief that salted hash was sufficient for password verification. That is no longer the case. Nowadays, we say that you need to have slow functions to prevent brute forcing passwords in the event that the database becomes exposed (which happens all too often). If you are using basic auth, then you are forcing your server to do these slow computations on every API call, which adds a heavy burden to your server. You are making it more vulnerable to DoS simply by using this dated authentication mechanism.

More generally, passwords are higher value than sessions: compromise of a user password allows hijacking the user's account indefinitely, not to mention the possibility of hijacking other systems that the user accesses due to password reuse; whereas a a user session is time-limited and confined to a single system. Therefore, as a matter of defense in depth, high value data like passwords should not be used repeatedly if not necessary. Basic authentication is a dated technology and should be deprecated.

TheGreatContini
  • 6,429
  • 2
  • 27
  • 37
  • 6
    Doesn't this apply to moste of the auth mechanisms? For example token based authentication. The server has to check the signature of the token every single request, which usually is a mix of RSA and SHA2 or only SHA2 ... – Genfood May 08 '21 at 19:10
6

The reason why most sites prefer OAuth over Basic Auth is that Basic Auth requires users to enter their password in a 3rd party app. This 3rd party app has to store the password in cleartext. The only way to revoke access is for the user to change their password. This, however, would revoke access for all 3rd party apps. So you can see what's the problem here.

On the other hand, OAuth requires a web frame. A user enters their login information at the login page of this particular site itself. The site then generates an access token which the app can use to authenticate itself in the future. Pros:

  • an access token can be revoked
  • the 3rd-party app can not see the user's password
  • an access token can be granted particular permissions (whereas basic auth treats every consumer equally).
  • if a 3rd-party app turns out to be insecure, the service provider can decide to revoke all access tokens generated for that particular app.
cutsoy
  • 10,127
  • 4
  • 40
  • 57
  • 1
    I agree on all the points excpect for granting particular permission, nothing stops a 3rd app from seeing the user used in the basic auth, and by that extent granting particular permissions to that user/password combination. – vasilevich Feb 16 '18 at 12:08
  • Also you can usually "revoke" Basic Auth by sending a 401 response code back, and asking the user to re-authenticate... – Mikkel Løkke Jun 15 '21 at 12:03
2

Basic auth over http in an environment that can be sniffed is like no auth, because the password can be easily reversed and then re-used. In response to the snarky comment above about credit cards over ssl being "a bit" more secure, the problem is that basic authentication is used over and over again over the same channel. If you compromise the password once, you compromise the security of every transaction over that channel, not just a single data attribute.

If you knew that you would be passing the same credit card number over a web session over and over, i'd hope that you'd come up with some other control besides just relying on SSL, because chances are that a credit card number used that frequently will be compromised... eventually.

phydroxide
  • 29
  • 4
  • 8
    SSL is secure no matter how many times you use it. Repeatedly using it does not increase the chances that information will be compromised – MobileMon Jan 15 '18 at 19:50
  • The problem with all these comments is that basic auth holds no security properties in itself. Assume attacker is positioned behind SSL termination and the argument goes away. An expiring session token can be stolen, but is only good for x period of time. Basic Auth has a token that always works once known, and so has to be rotated manually on a basis as frequent as an expiring token to have the same security property. – phydroxide Oct 01 '18 at 06:19
1

If you are generating passwords with htpasswd consider switching to htdigest.

Digest authentication is secure even over unencrypted connections and its just as easy to set up. Sure, basic authentication is ok when you are going over ssl, but why take the chance when you could just as easily use digest authentication?

jwsample
  • 2,401
  • 19
  • 18
  • 5
    If it is encrypted then there is no reason to use digest over basic auth, there is no 'chance' being taken. If the connection is not encrypted then digest authentication will prevent revealing the password of the user and it will prevent replay attacks, but the data will be sent in plain text, I would hardly call that 'secure even over unencrypted connections'. – Chris Diver Jul 24 '10 at 00:44
  • 1
    The "chance" is more like a misconfigured server allowing someone to access the page unencrypted or a user doing so accidentally. This wasn't a question about whether information is better sent over ssl or in the clear. Basic authentication is at the lowest of the low in terms of password authentication security standards. There is a reason you don't see it much in the wild. – jwsample Jul 24 '10 at 01:09
  • I wonder what is better in general. Basic can be on the web server level, so pretty low and reducing the areas quite a lot compared to having for example Jenkins handle the authentication (which can open just so many URLs, posts, etc accesses and possible bugs). So what is better for such cases (outside of https only). – Wernight Jul 18 '13 at 16:11
  • 1
    "Digest authentication is secure even over unencrypted connections" -- False. One can simply do pass-the-hash to steal an identity without knowing the password. Furthermore, it is easy to reverse most password hashes via table lookup (can even be done using Google), rainbow tables, or low-cost GPU brute forcing. – TheGreatContini Sep 04 '17 at 23:13
-3

As the name itself implies, 'Basic Authentication' is just basic security mechanism. Don't rely on it to provide you with worry free security.

Using SSL on top of it does makes it bit more secure but there are better mechanisms.

SoftwareGeek
  • 15,234
  • 19
  • 61
  • 78
  • 31
    So sending credit card details over SSL is a 'bit more secure' than plain text? – Chris Diver Jul 24 '10 at 00:46
  • 1
    @Chris Diver - what do you mean? – SoftwareGeek Jul 24 '10 at 01:15
  • 5
    Basic Auth creds are "plaintext over SSL" just like sending your credit card number through HTTP POST is "plaintext over SSL". So by doing it over SSL (TLS these days) makes it secure during transport. – Kias Jan 30 '17 at 16:58