mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 23:07:29 +00:00
Fail closed on non-finite risk scores
This commit is contained in:
parent
8f4691584c
commit
a50fc8714e
2 changed files with 27 additions and 1 deletions
|
|
@ -41,6 +41,31 @@ describe("account-core", () => {
|
||||||
expect(result.decision).toBe("approval_required");
|
expect(result.decision).toBe("approval_required");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each([Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY])(
|
||||||
|
"fails closed for a non-finite risk score of %s",
|
||||||
|
(riskScore) => {
|
||||||
|
const result = evaluateAccountPolicy({
|
||||||
|
action: "social:profile:read",
|
||||||
|
riskScore,
|
||||||
|
principal: { type: "agent", id: "profile-agent" },
|
||||||
|
grant: {
|
||||||
|
id: "grant_non_finite",
|
||||||
|
accountId: "account_1",
|
||||||
|
principal: { type: "agent", id: "profile-agent" },
|
||||||
|
permissions: ["social:profile:read"],
|
||||||
|
policy: [],
|
||||||
|
createdAt: new Date(0).toISOString()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toMatchObject({
|
||||||
|
decision: "deny",
|
||||||
|
riskScore: 1,
|
||||||
|
reason: "critical risk requires admin override"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
it("redacts secret-like audit previews", () => {
|
it("redacts secret-like audit previews", () => {
|
||||||
const event = createAccountAuditEvent({
|
const event = createAccountAuditEvent({
|
||||||
provider: "gmail",
|
provider: "gmail",
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,8 @@ export function scoreAccountActionRisk(input: {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function evaluateAccountPolicy(input: LogicSrcPolicyEvaluationInput): LogicSrcPolicyEvaluationResult {
|
export function evaluateAccountPolicy(input: LogicSrcPolicyEvaluationInput): LogicSrcPolicyEvaluationResult {
|
||||||
const riskScore = Math.min(1, Math.max(0, input.riskScore ?? scoreAccountActionRisk({ action: input.action })));
|
const requestedRiskScore = input.riskScore ?? scoreAccountActionRisk({ action: input.action });
|
||||||
|
const riskScore = Number.isFinite(requestedRiskScore) ? Math.min(1, Math.max(0, requestedRiskScore)) : 1;
|
||||||
const grantActive = input.grant && !input.grant.revokedAt && (!input.grant.expiresAt || Date.parse(input.grant.expiresAt) > Date.now());
|
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));
|
const hasPermission = Boolean(grantActive && input.grant?.permissions.includes(input.action));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue