Require registered Bifrost identity for bridge mouths
This commit is contained in:
parent
23c02be2a6
commit
80a5392935
2 changed files with 104 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using Bifrost.Web.Data;
|
||||
using Bifrost.Web.Domain;
|
||||
using Bifrost.Web.Features.Membership;
|
||||
using Bifrost.Web.Features.Shared;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
|
@ -212,6 +213,12 @@ public sealed class BridgeActionService(
|
|||
return BridgePolicyDecision.Reject("Persona and agent Discord/Reddit bridge actions must carry a Bifrost identity.");
|
||||
}
|
||||
|
||||
var identityDecision = await EvaluateRegisteredBifrostIdentityAsync(request.BifrostIdentity, cancellationToken);
|
||||
if (identityDecision is not null)
|
||||
{
|
||||
return identityDecision;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(request.HeimdallCapabilityReference))
|
||||
{
|
||||
return BridgePolicyDecision.Reject("Persona and agent Discord/Reddit bridge actions must carry a Heimdall-backed capability or account reference.");
|
||||
|
|
@ -257,6 +264,31 @@ public sealed class BridgeActionService(
|
|||
: "Authorized for an active Bifrost member through Bifrost policy.");
|
||||
}
|
||||
|
||||
private async Task<BridgePolicyDecision?> EvaluateRegisteredBifrostIdentityAsync(
|
||||
string bifrostIdentity,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
string normalizedIdentity;
|
||||
try
|
||||
{
|
||||
normalizedIdentity = BifrostIdentityService.NormalizeIdentity(bifrostIdentity);
|
||||
}
|
||||
catch (BifrostIdentityException exception)
|
||||
{
|
||||
return BridgePolicyDecision.Reject(exception.Message);
|
||||
}
|
||||
|
||||
var exists = await dbContext.UserAccounts.AnyAsync(
|
||||
x => x.NormalizedBifrostIdentity == normalizedIdentity,
|
||||
cancellationToken);
|
||||
if (!exists)
|
||||
{
|
||||
return BridgePolicyDecision.Reject("Persona and agent Discord/Reddit bridge actions must carry a registered Bifrost identity.");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task<BridgePolicyDecision?> EvaluateBifrostOwnedProvenanceAsync(
|
||||
BridgeActionRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
|
|
|
|||
Loading…
Reference in a new issue