mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-15 07:17:30 +00:00
Clamp non-finite account risk scores
This commit is contained in:
parent
8f4691584c
commit
d43019714d
2 changed files with 19 additions and 1 deletions
|
|
@ -41,6 +41,23 @@ describe("account-core", () => {
|
|||
expect(result.decision).toBe("approval_required");
|
||||
});
|
||||
|
||||
it("treats non-finite risk scores as critical", () => {
|
||||
const result = evaluateAccountPolicy({
|
||||
action: "social:profile:read",
|
||||
riskScore: Number.NaN,
|
||||
grant: {
|
||||
id: "grant_1",
|
||||
accountId: "account_1",
|
||||
principal: { type: "agent", id: "marketing-agent" },
|
||||
permissions: ["social:profile:read"],
|
||||
policy: [],
|
||||
createdAt: new Date(0).toISOString()
|
||||
}
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({ decision: "deny", riskScore: 1 });
|
||||
});
|
||||
|
||||
it("redacts secret-like audit previews", () => {
|
||||
const event = createAccountAuditEvent({
|
||||
provider: "gmail",
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ export function scoreAccountActionRisk(input: {
|
|||
}
|
||||
|
||||
export function evaluateAccountPolicy(input: LogicSrcPolicyEvaluationInput): LogicSrcPolicyEvaluationResult {
|
||||
const riskScore = Math.min(1, Math.max(0, input.riskScore ?? scoreAccountActionRisk({ action: input.action })));
|
||||
const rawRiskScore = input.riskScore ?? scoreAccountActionRisk({ action: input.action });
|
||||
const riskScore = Number.isFinite(rawRiskScore) ? Math.min(1, Math.max(0, rawRiskScore)) : 1;
|
||||
const grantActive = input.grant && !input.grant.revokedAt && (!input.grant.expiresAt || Date.parse(input.grant.expiresAt) > Date.now());
|
||||
const hasPermission = Boolean(grantActive && input.grant?.permissions.includes(input.action));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue