mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-15 07:17:30 +00:00
Handle non-finite policy risk scores
This commit is contained in:
parent
8a86d14ffd
commit
21f764f06d
2 changed files with 37 additions and 1 deletions
|
|
@ -14,6 +14,9 @@ const WRITE_ACTIONS = new Set([
|
|||
]);
|
||||
|
||||
export function riskBandForScore(score: number): LogicSrcRiskBand {
|
||||
if (!Number.isFinite(score)) {
|
||||
return "critical";
|
||||
}
|
||||
if (score >= 0.75) {
|
||||
return "critical";
|
||||
}
|
||||
|
|
@ -50,8 +53,16 @@ export function scoreAccountActionRisk(input: {
|
|||
return Math.min(1, Number(score.toFixed(2)));
|
||||
}
|
||||
|
||||
function normalizeRiskScore(score: number): number {
|
||||
if (!Number.isFinite(score)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return Math.min(1, Math.max(0, score));
|
||||
}
|
||||
|
||||
export function evaluateAccountPolicy(input: LogicSrcPolicyEvaluationInput): LogicSrcPolicyEvaluationResult {
|
||||
const riskScore = Math.min(1, Math.max(0, input.riskScore ?? scoreAccountActionRisk({ action: input.action })));
|
||||
const riskScore = normalizeRiskScore(input.riskScore ?? scoreAccountActionRisk({ action: input.action }));
|
||||
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