Basics: Basic Auth header

Auth headers basics - cheat sheet

Intro - Basic Auth

Auth headers are not something overly complex, but we all come across them while dealing with APIs. Different tools handle them a bit differently. It’s not that annoying that learned it by heart but then I lost dev time every time I had to look it up. So. Here we go. Also… there might be madly intersting happenings in the AI world where new models beat each other in benchmarking every other week (at the time of writing according to livebench.ai o3-mini is the best one for coding and o1 the best reasoning model). The only logical step to take is to write about something which is 25y+ old. - hereby I prodly present my take on Basic Auth.

What are auth headers?

Auth headers are a way to authenticate a request to an API. They are a set of key-value pairs that are sent with the request. The most common auth header is the Authorization header.

Basic Auth

What is it?

Basic Auth is one of the simplest authentication methods where credentials are sent in the HTTP header. The header is constructed by combining username and password with a colon (username:password), encoding it in Base64, and prefixing it with “Basic ”. Read as “Basic username:password”.

Why are the Basic Auth credentials encoded?

The Base64 encoding requirement comes from RFC 7617, which defines the Basic Authentication scheme. The encoding serves two purposes:

  1. It allows the transmission of non-ASCII characters in usernames and passwords
  2. It avoids the use of forbidden characters in HTTP headers like colons, which are used as delimiters

The encoding process works as follows:

  1. The username and password are combined with a colon (:)
  2. The resulting string is encoded into octets using UTF-8
  3. The octets are encoded using Base64 to create the credentials
  4. The word “Basic” and a space are prepended to the credentials

Note that Base64 encoding is not a security measure - it’s merely an encoding scheme to ensure safe transmission of the credentials as part of the HTTP Authorization header.

How to use Basic Auth?

Here’s how to use Basic Auth in different tools and languages:

Security notes:

Additional thought, desribed in the RFC 7617 directly: If you authenticate yourself somewhere using Basic Auth, keep in mind that you are in no control of what the server does with your credentials. It’s basically the same as if you would send your password in plain text. So if the server stores your requests / credentials / both, you basically handed over your password to the system on a silver platter. Should the server be compromised, your credentials are free for take. Should the server be malicious, your credentials are free for take. Etc. So never use the same password twice across different systems as it could grant access to multiple accounts of yours in case of a data breach or maliciuos activity.

Why is it still used?

When should you use Basic Auth?

Conclusion

I still think that there are valid use cases for Basic Auth even with its securuty vulnerabilities, even after 25 years+ of its existence, but it’s important to understand the security implications and use it accordingly.