Class BoundedMetadataHttpMessageHandler
- Namespace
- MailFathom.Infrastructure.Security.OAuth
- Assembly
- MailFathom.Infrastructure.dll
Keeps the retrieval of an authorization server's metadata inside stated bounds.
public sealed class BoundedMetadataHttpMessageHandler : DelegatingHandler, IDisposable
- Inheritance
-
BoundedMetadataHttpMessageHandler
- Implements
- Inherited Members
Remarks
Discovery documents and key sets are the one thing this process fetches from a machine it does not own, and it fetches them on a schedule nobody watches. A server that has been replaced, misconfigured, or taken over is therefore in a position to answer a key refresh with something other than a few kilobytes of JSON, and the refresh happens inside a request's authentication path.
Two bounds are enforced here and two are set where the client is composed. This handler refuses a response larger
than the limit and a request that is not https; the client that owns it carries the timeout and follows no
redirect, so a server cannot answer slowly forever and cannot send the retrieval somewhere the configuration never
named.
A declared length over the limit is refused before the body is read at all, and a body without one is read through a buffer that stops at the same limit. Both fail as an ordinary retrieval failure, which the caller already treats as "the metadata could not be read" rather than as a reason to accept a token.
Constructors
- BoundedMetadataHttpMessageHandler(int)
Initializes a new bounded metadata handler.
Methods
- SendAsync(HttpRequestMessage, CancellationToken)
Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.