@posiwise/common-services 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1478,22 +1478,6 @@ class PermissionService {
|
|
|
1478
1478
|
expr = this.handleNonBooleanPermissions(permission, expr, productKey, permission_key, productSlug);
|
|
1479
1479
|
// Now expr is made of true/false values with &&, ||, ()
|
|
1480
1480
|
// Safe parser: no eval() - CSP 'unsafe-eval' not required
|
|
1481
|
-
const ourResult = this.evaluateBooleanExpression(expr);
|
|
1482
|
-
let evalResult;
|
|
1483
|
-
try {
|
|
1484
|
-
evalResult = eval(expr.trim());
|
|
1485
|
-
}
|
|
1486
|
-
catch {
|
|
1487
|
-
evalResult = undefined;
|
|
1488
|
-
}
|
|
1489
|
-
if (ourResult !== evalResult) {
|
|
1490
|
-
console.warn('[PermissionService] MISMATCH - parser vs eval', {
|
|
1491
|
-
permission,
|
|
1492
|
-
expr: expr.trim(),
|
|
1493
|
-
ourResult,
|
|
1494
|
-
evalResult
|
|
1495
|
-
});
|
|
1496
|
-
}
|
|
1497
1481
|
return this.evaluateBooleanExpression(expr);
|
|
1498
1482
|
}
|
|
1499
1483
|
/** Safe boolean expression parser - replaces eval() for CSP compliance. */
|
|
@@ -1531,17 +1515,23 @@ class PermissionService {
|
|
|
1531
1515
|
return (this.evaluateBooleanExpression(left) && this.evaluateBooleanExpression(right));
|
|
1532
1516
|
}
|
|
1533
1517
|
}
|
|
1518
|
+
// Strip matching outer parens - only when first ( and last ) are a pair
|
|
1534
1519
|
if (expr.startsWith('(') && expr.endsWith(')')) {
|
|
1535
1520
|
let d = 0;
|
|
1536
|
-
for (let j =
|
|
1521
|
+
for (let j = 0; j < expr.length; j++) {
|
|
1537
1522
|
if (expr[j] === '(')
|
|
1538
1523
|
d++;
|
|
1539
|
-
if (expr[j] === ')')
|
|
1524
|
+
else if (expr[j] === ')')
|
|
1540
1525
|
d--;
|
|
1526
|
+
if (d === 0) {
|
|
1527
|
+
if (j === expr.length - 1) {
|
|
1528
|
+
return this.evaluateBooleanExpression(expr.substring(1, expr.length - 1));
|
|
1529
|
+
}
|
|
1530
|
+
break;
|
|
1531
|
+
}
|
|
1541
1532
|
if (d < 0)
|
|
1542
|
-
|
|
1533
|
+
break;
|
|
1543
1534
|
}
|
|
1544
|
-
return this.evaluateBooleanExpression(expr.substring(1, expr.length - 1));
|
|
1545
1535
|
}
|
|
1546
1536
|
return false;
|
|
1547
1537
|
}
|
|
@@ -1549,6 +1539,8 @@ class PermissionService {
|
|
|
1549
1539
|
if (typeof permission !== 'boolean') {
|
|
1550
1540
|
permission.split(' ').forEach(x => {
|
|
1551
1541
|
const raw = x.trim();
|
|
1542
|
+
if (!raw)
|
|
1543
|
+
return;
|
|
1552
1544
|
if (['||', '&&', '(', ')'].includes(raw)) {
|
|
1553
1545
|
expr += ` ${raw} `;
|
|
1554
1546
|
}
|