@posiwise/common-services 0.1.94 → 0.1.98

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.
@@ -36,6 +36,16 @@ class ScriptLoaderService {
36
36
  this.document = document;
37
37
  this._scripts = {};
38
38
  }
39
+ getCspNonce() {
40
+ // Prefer explicit global set by server-side renderer
41
+ const w = globalThis;
42
+ if (w?.__cspNonce)
43
+ return w.__cspNonce;
44
+ // Fallback: try to read nonce from any existing script tag
45
+ const anyScript = this.document.querySelector('script[nonce]');
46
+ const n = anyScript?.nonce || anyScript?.getAttribute('nonce') || undefined;
47
+ return n || undefined;
48
+ }
39
49
  load(tag, ...scripts) {
40
50
  scripts.forEach((src) => {
41
51
  if (!this._scripts[src]) {
@@ -73,6 +83,9 @@ class ScriptLoaderService {
73
83
  const scriptTag = document.createElement('script');
74
84
  scriptTag.type = 'text/javascript';
75
85
  scriptTag.src = this._scripts[src].src;
86
+ const nonce = this.getCspNonce();
87
+ if (nonce)
88
+ scriptTag.nonce = nonce;
76
89
  scriptTag.onload = () => {
77
90
  this._scripts[src].loaded = true;
78
91
  resolve({ src, loaded: true });
@@ -1464,13 +1477,64 @@ class PermissionService {
1464
1477
  }
1465
1478
  expr = this.handleNonBooleanPermissions(permission, expr, productKey, permission_key, productSlug);
1466
1479
  // Now expr is made of true/false values with &&, ||, ()
1467
- // eslint-disable-next-line no-eval
1468
- return eval(expr); // NOSONAR
1480
+ // Safe parser: no eval() - CSP 'unsafe-eval' not required
1481
+ return this.evaluateBooleanExpression(expr);
1482
+ }
1483
+ /** Safe boolean expression parser - replaces eval() for CSP compliance. */
1484
+ evaluateBooleanExpression(expr) {
1485
+ expr = expr.replace(/\s+/g, ' ').trim();
1486
+ if (!expr)
1487
+ return false;
1488
+ if (expr === 'true')
1489
+ return true;
1490
+ if (expr === 'false')
1491
+ return false;
1492
+ let depth = 0;
1493
+ for (let i = 0; i < expr.length - 1; i++) {
1494
+ const c = expr[i];
1495
+ if (c === '(')
1496
+ depth++;
1497
+ else if (c === ')')
1498
+ depth--;
1499
+ else if (depth === 0 && expr.substring(i, i + 2) === '||') {
1500
+ const left = expr.substring(0, i).trim();
1501
+ const right = expr.substring(i + 2).trim();
1502
+ return (this.evaluateBooleanExpression(left) || this.evaluateBooleanExpression(right));
1503
+ }
1504
+ }
1505
+ depth = 0;
1506
+ for (let i = 0; i < expr.length - 1; i++) {
1507
+ const c = expr[i];
1508
+ if (c === '(')
1509
+ depth++;
1510
+ else if (c === ')')
1511
+ depth--;
1512
+ else if (depth === 0 && expr.substring(i, i + 2) === '&&') {
1513
+ const left = expr.substring(0, i).trim();
1514
+ const right = expr.substring(i + 2).trim();
1515
+ return (this.evaluateBooleanExpression(left) && this.evaluateBooleanExpression(right));
1516
+ }
1517
+ }
1518
+ if (expr.startsWith('(') && expr.endsWith(')')) {
1519
+ let d = 0;
1520
+ for (let j = 1; j < expr.length - 1; j++) {
1521
+ if (expr[j] === '(')
1522
+ d++;
1523
+ if (expr[j] === ')')
1524
+ d--;
1525
+ if (d < 0)
1526
+ return false;
1527
+ }
1528
+ return this.evaluateBooleanExpression(expr.substring(1, expr.length - 1));
1529
+ }
1530
+ return false;
1469
1531
  }
1470
1532
  handleNonBooleanPermissions(permission, expr, productKey, permission_key, productSlug) {
1471
1533
  if (typeof permission !== 'boolean') {
1472
1534
  permission.split(' ').forEach(x => {
1473
1535
  const raw = x.trim();
1536
+ if (!raw)
1537
+ return; // Skip empty tokens (e.g. from double spaces) - avoids malformed expr
1474
1538
  if (['||', '&&', '(', ')'].includes(raw)) {
1475
1539
  expr += ` ${raw} `;
1476
1540
  }
@@ -2838,6 +2902,9 @@ class SentryErrorHandler {
2838
2902
  : 'production';
2839
2903
  const config = {
2840
2904
  dsn: null,
2905
+ // Disable Session Replay (uses eval internally) for CSP 'unsafe-eval' compliance
2906
+ replaysSessionSampleRate: 0,
2907
+ replaysOnErrorSampleRate: 0,
2841
2908
  // NOTE: We intentionally do not enable Performance Tracing here.
2842
2909
  // The previous integration (`BrowserTracing` + `routingInstrumentation`) was part of
2843
2910
  // the legacy `@sentry/angular-ivy` API and isn't available in `@sentry/angular` v10.