@posiwise/common-services 0.2.5 → 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,9 +1478,7 @@ 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
|
-
|
|
1482
|
-
console.log("Usama", sop, eval(expr));
|
|
1483
|
-
return eval(expr); // NOSONAR
|
|
1481
|
+
return this.evaluateBooleanExpression(expr);
|
|
1484
1482
|
}
|
|
1485
1483
|
/** Safe boolean expression parser - replaces eval() for CSP compliance. */
|
|
1486
1484
|
evaluateBooleanExpression(expr) {
|
|
@@ -1517,17 +1515,23 @@ class PermissionService {
|
|
|
1517
1515
|
return (this.evaluateBooleanExpression(left) && this.evaluateBooleanExpression(right));
|
|
1518
1516
|
}
|
|
1519
1517
|
}
|
|
1518
|
+
// Strip matching outer parens - only when first ( and last ) are a pair
|
|
1520
1519
|
if (expr.startsWith('(') && expr.endsWith(')')) {
|
|
1521
1520
|
let d = 0;
|
|
1522
|
-
for (let j =
|
|
1521
|
+
for (let j = 0; j < expr.length; j++) {
|
|
1523
1522
|
if (expr[j] === '(')
|
|
1524
1523
|
d++;
|
|
1525
|
-
if (expr[j] === ')')
|
|
1524
|
+
else if (expr[j] === ')')
|
|
1526
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
|
+
}
|
|
1527
1532
|
if (d < 0)
|
|
1528
|
-
|
|
1533
|
+
break;
|
|
1529
1534
|
}
|
|
1530
|
-
return this.evaluateBooleanExpression(expr.substring(1, expr.length - 1));
|
|
1531
1535
|
}
|
|
1532
1536
|
return false;
|
|
1533
1537
|
}
|
|
@@ -1535,6 +1539,8 @@ class PermissionService {
|
|
|
1535
1539
|
if (typeof permission !== 'boolean') {
|
|
1536
1540
|
permission.split(' ').forEach(x => {
|
|
1537
1541
|
const raw = x.trim();
|
|
1542
|
+
if (!raw)
|
|
1543
|
+
return;
|
|
1538
1544
|
if (['||', '&&', '(', ')'].includes(raw)) {
|
|
1539
1545
|
expr += ` ${raw} `;
|
|
1540
1546
|
}
|