Skip to content

fix(ssr): route DOM-backed evaluator through the CSP-safe parser - #187

Merged
JosunLP merged 2 commits into
devfrom
fix/167-ssr-eval-fallback
Jul 6, 2026
Merged

fix(ssr): route DOM-backed evaluator through the CSP-safe parser#187
JosunLP merged 2 commits into
devfrom
fix/167-ssr-eval-fallback

Conversation

@JosunLP

@JosunLP JosunLP commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #167 (Medium; High where templates can carry untrusted content).

The DOM-backed evaluateSSR (active whenever a global/configured DOMParser exists) had two problems:

  1. It fell back to new Function(...keys, return (${expr});) for any non-trivial expression — unsafe-eval on a path whose sibling expression.ts was written specifically to avoid it.
  2. Its dot-notation fast-lane didn't call isPrototypePollutionKey, so constructor.constructor walked the prototype chain and returned the Function constructor.

Fix

evaluateSSR now delegates to the shared, CSP-safe evaluateExpression (Pratt parser in expression.ts) already used by the pure renderer. This removes the new Function fallback and the proto-lookup gap in one step, and unifies evaluator behaviour across both backends. The dead unwrap/isSignal/isComputed imports are dropped (unwrapping lives in the shared evaluator).

Verification

  • New test: constructor.constructor on the DOM backend yields no Function (fails on the old code, passes now).
  • New test: complex arithmetic (a + b) still evaluates via the safe parser.
  • Grep confirms no new Function remains in src/ssr.
  • Full suite: 2988 pass / 0 fail. tsc --noEmit + eslint clean.

🤖 Generated with Claude Code

evaluateSSR fell back to new Function() for any non-trivial expression on
the DOM-backed renderer, re-introducing unsafe-eval on a path documented
as CSP-safe, and its dot-path fast-lane skipped isPrototypePollutionKey
so evaluateSSR('constructor.constructor', ctx) reached the Function
constructor.

evaluateSSR now delegates to evaluateExpression from expression.ts (the
same evaluator the pure renderer uses): no eval/Function fallback, and
member access is proto-guarded. Evaluator behaviour is now unified across
both SSR backends.

Fixes #167

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 451d1426-0a74-4575-917a-73d82981a4be

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/167-ssr-eval-fallback

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added tests Chenges to the tests ssr Changes to the ssr module labels Jul 6, 2026
@JosunLP
JosunLP merged commit 27caa67 into dev Jul 6, 2026
5 checks passed
@JosunLP
JosunLP deleted the fix/167-ssr-eval-fallback branch July 6, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ssr Changes to the ssr module tests Chenges to the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant