@posiwise/common-services 0.2.3 → 0.2.5
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,18 +1478,9 @@ 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
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
permission,
|
|
1485
|
-
expr: expr.trim(),
|
|
1486
|
-
result,
|
|
1487
|
-
selectedProduct: PermissionService?.selectedProduct,
|
|
1488
|
-
productKey,
|
|
1489
|
-
permission_key,
|
|
1490
|
-
productSlug
|
|
1491
|
-
});
|
|
1492
|
-
return result;
|
|
1481
|
+
const sop = this.evaluateBooleanExpression(expr);
|
|
1482
|
+
console.log("Usama", sop, eval(expr));
|
|
1483
|
+
return eval(expr); // NOSONAR
|
|
1493
1484
|
}
|
|
1494
1485
|
/** Safe boolean expression parser - replaces eval() for CSP compliance. */
|
|
1495
1486
|
evaluateBooleanExpression(expr) {
|
|
@@ -1526,34 +1517,24 @@ class PermissionService {
|
|
|
1526
1517
|
return (this.evaluateBooleanExpression(left) && this.evaluateBooleanExpression(right));
|
|
1527
1518
|
}
|
|
1528
1519
|
}
|
|
1529
|
-
// Strip matching outer parens - only when first ( and last ) are a pair
|
|
1530
1520
|
if (expr.startsWith('(') && expr.endsWith(')')) {
|
|
1531
|
-
let
|
|
1532
|
-
for (let j =
|
|
1521
|
+
let d = 0;
|
|
1522
|
+
for (let j = 1; j < expr.length - 1; j++) {
|
|
1533
1523
|
if (expr[j] === '(')
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
if (
|
|
1538
|
-
|
|
1539
|
-
return this.evaluateBooleanExpression(expr.substring(1, expr.length - 1));
|
|
1540
|
-
}
|
|
1541
|
-
break; // First ( doesn't wrap entire expr
|
|
1542
|
-
}
|
|
1543
|
-
if (depth < 0)
|
|
1544
|
-
break;
|
|
1524
|
+
d++;
|
|
1525
|
+
if (expr[j] === ')')
|
|
1526
|
+
d--;
|
|
1527
|
+
if (d < 0)
|
|
1528
|
+
return false;
|
|
1545
1529
|
}
|
|
1530
|
+
return this.evaluateBooleanExpression(expr.substring(1, expr.length - 1));
|
|
1546
1531
|
}
|
|
1547
|
-
// Unrecognized token - treat as false for safety
|
|
1548
|
-
console.warn('[PermissionService] evaluateBooleanExpression: unrecognized expr', { expr });
|
|
1549
1532
|
return false;
|
|
1550
1533
|
}
|
|
1551
1534
|
handleNonBooleanPermissions(permission, expr, productKey, permission_key, productSlug) {
|
|
1552
1535
|
if (typeof permission !== 'boolean') {
|
|
1553
1536
|
permission.split(' ').forEach(x => {
|
|
1554
1537
|
const raw = x.trim();
|
|
1555
|
-
if (!raw)
|
|
1556
|
-
return;
|
|
1557
1538
|
if (['||', '&&', '(', ')'].includes(raw)) {
|
|
1558
1539
|
expr += ` ${raw} `;
|
|
1559
1540
|
}
|