GeezerVison is showing github.com — fix(ssr): route DOM-backed evaluator through the CSP-safe parser by JosunLP · Pull Request #187 · bQuery/bQuery
Conversation
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:
- 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.
- 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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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
Bot
commented
Jul 6, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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:
✨ 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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
ssr
Changes to the ssr module
tests
Chenges to the tests
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.