fix(security): enforce resource isolation across API and hubs
This commit is contained in:
1 parent
21f0530b6c
commit
1cd4e2b4b5
39 files changed
+1081
-497
No files matched your search
@@ -63,6 +63,14 @@ public class ApiKeyAuthenticationHandler : AuthenticationHandler<ApiKeyAuthentic
|
||||
if (!CryptographicOperations.FixedTimeEquals(incomingHash, storedHash))
|
||||
return AuthenticateResult.Fail("Invalid API key");
|
||||
|
||||
// A site key alone is not an agent identity. Resolve the registered binding
|
||||
// by the full verified hash, and reject ambiguous or stale bindings.
|
||||
var agents = await db.Agents.AsNoTracking()
|
||||
.Where(a => a.ApiKeyHash == apiKeyEntity.KeyHash && a.SiteId == apiKeyEntity.SiteId)
|
||||
.Select(a => a.Id).Take(2).ToListAsync(Context.RequestAborted);
|
||||
if (agents.Count != 1 || !apiKeyEntity.SiteId.HasValue)
|
||||
return AuthenticateResult.Fail("API key is not bound to one active agent");
|
||||
|
||||
apiKeyEntity.MarkUsed();
|
||||
// Persist LastUsedAt update
|
||||
await db.SaveChangesAsync();
|
||||
@@ -71,6 +79,7 @@ public class ApiKeyAuthenticationHandler : AuthenticationHandler<ApiKeyAuthentic
|
||||
{
|
||||
new Claim(ClaimTypes.NameIdentifier, apiKeyEntity.Id.ToString()),
|
||||
new Claim("auth_method", "api_key"),
|
||||
new Claim("agent_id", agents[0].ToString()),
|
||||
new Claim("api_key_prefix", prefix),
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user