-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use full URl as HMAC cache key #265
Conversation
Codecov Report
@@ Coverage Diff @@
## main #265 +/- ##
===================================
Coverage 85% 85%
===================================
Files 75 75
Lines 2036 2036
Branches 298 298
===================================
Hits 1741 1741
Misses 211 211
Partials 84 84
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
One major downside compared to PR #256 (removing the HMAC cache), is that you can't skip the token validation based on request specific conditions (e.g. by returning You could then use this to skip validation when a user is logged in: options.OnComputeHMACAsync = (context, secret) =>
{
if (context.Context.User.Identity.IsAuthenticated)
{
return Task.FromResult<string>(null);
}
string uri = CaseHandlingUriBuilder.BuildRelative(
CaseHandlingUriBuilder.CaseHandling.LowerInvariant,
context.Context.Request.PathBase,
context.Context.Request.Path,
QueryString.Create(context.Commands));
return Task.FromResult(HMACUtilities.ComputeHMACSHA256(uri, secret));
}; |
HMAC validation for requests should always be separate from general user authorization. They really do two different things. |
What about providing a way to skip validation for existing commands/values that you've used? When you currently configure the HMAC secret, all existing image URLs will return 400 error codes... And will this also work when you've added/removed a command in |
Which is absolutely the right thing to do. The HMAC system is all or nothing by design and always should be..
Yes. The token is calculated and compared before |
Prerequisites
Description
As previously identified using only the token as a cache key opens the potential for abuse of the caching mechanism. PR #256 was opened to remove that cache.
I would consider removing the cache with current target frameworks to be too expensive given the large overhead of HMAC generation so have replaced that PR with an implementation that uses the full encoded URL as the key.
The cache key generation method causes low allocations due to the underlying usage of
string.Create
so I would consider it acceptable for now. For .NET 6 we can likely remove the cache in it's entirety due to the much improved reusable hashing methods available to that framework.