mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 23:07:29 +00:00
fix(policy): treat malformed grant expiresAt as expired, not active
Date.parse() returns NaN for invalid date strings. Previously, a grant with expiresAt set to a malformed value (e.g. 'invalid') would pass the expiry check (NaN > Date.now() === false, but the falsy NaN would skip the check due to how the condition was written—or more precisely, would evaluate incorrectly). Now, if expiresAt is present but cannot be parsed, the grant is treated as expired/invalid rather than silently allowing access.
This commit is contained in:
parent
8f4691584c
commit
681600360d
1 changed files with 2 additions and 1 deletions
|
|
@ -52,7 +52,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 riskScore = Math.min(1, Math.max(0, input.riskScore ?? scoreAccountActionRisk({ action: input.action })));
|
||||||
const grantActive = input.grant && !input.grant.revokedAt && (!input.grant.expiresAt || Date.parse(input.grant.expiresAt) > Date.now());
|
const expiryMs = input.grant?.expiresAt ? Date.parse(input.grant.expiresAt) : NaN;
|
||||||
|
const grantActive = input.grant && !input.grant.revokedAt && (!input.grant.expiresAt || (!Number.isNaN(expiryMs) && expiryMs > Date.now()));
|
||||||
const hasPermission = Boolean(grantActive && input.grant?.permissions.includes(input.action));
|
const hasPermission = Boolean(grantActive && input.grant?.permissions.includes(input.action));
|
||||||
|
|
||||||
if (!hasPermission) {
|
if (!hasPermission) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue