Class BasicCredentialHeader
- Namespace
- MailFathom.Infrastructure.Security.Passwords
- Assembly
- MailFathom.Infrastructure.dll
Reads the user-id and password out of an HTTP Authorization: Basic header.
public static class BasicCredentialHeader
- Inheritance
-
BasicCredentialHeader
- Inherited Members
Remarks
RFC 7617 carries both halves of the credential in one Base64 field, separated by the first colon, so reading one is a decode and a split rather than a parse — and every one of the ways it can go wrong has to be refused before any password verification is attempted. Verification is deliberately expensive, so a header that could never have been a credential must cost the sender the price of a string comparison rather than the price of a key derivation.
Everything is bounded before it is decoded. A header longer than MaximumEncodedLength is refused without allocating, which is what stops an unauthenticated caller from making this process decode a megabyte per request; the limit is set from the longest credential this deployment can actually hold, so nothing an operator can legitimately provision comes near it.
The decoding is UTF-8 and is strict. RFC 7617 leaves the encoding of the credential unstated for historical reasons
and adds a charset parameter naming UTF-8 as the one a modern server should ask for, which is what the
challenge this deployment writes does. Decoding strictly means a sequence that is not UTF-8 is refused rather than
silently turned into replacement characters, so two different byte sequences can never fold into one password.
The decoded octets and the decoded characters both live in pinned buffers this reader owns and are cleared before it returns, and the credential it hands back owns the one buffer that survives. The header value itself arrives as a string the request pipeline already materialized and which cannot be erased, which is a property of HTTP rather than something this can improve — what it controls is every copy after that one.
Fields
- HttpAuthenticationScheme
The HTTP authentication scheme this reader accepts, and the one a challenge names.
- MaximumEncodedLength
The longest header value this reader will decode, in characters.
Methods
- TryRead(string?, out PresentedBasicCredential?)
Reads the credential an
Authorizationheader value carried.