fix(view): shadow dangerous globals in with-scoped evaluator - #188
Merged
Conversation
The evaluate/evaluateRaw proxies compiled new Function('$ctx',
'with($ctx){ return (expr); }'). The has trap returned 'prop in target',
so inherited Object.prototype members resolved from the context and
constructor.constructor('...')() reached the Function constructor (RCE
where bq-* attributes carry untrusted content).
Hardening the has trap to own-keys-only is necessary but not sufficient:
once the proxy declines 'constructor', with resolution falls through to
the global scope, where the global object inherits 'constructor' from
Object.prototype and exposes Function/eval/globalThis. So the evaluator
now *shadows* a denylist (constructor, __proto__, prototype, Function,
eval, globalThis, global, window, self, top, parent): has reports them
present and get resolves them to undefined unless the context owns that
property. Member access on undefined then throws and yields undefined.
Both the lazy (evaluate) and raw (evaluateRaw) contexts are covered.
Fixes #168
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
…heck evaluate<T=unknown> resolves to any in the test type-check context, which selected bun's Matchers<undefined> expect overload and broke .toBe(value). Explicit type args make the matcher type unambiguous. Co-Authored-By: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #168 (Medium hardening).
evaluate/evaluateRawrunnew Function('$ctx', 'with($ctx){ return (expr); }'). The proxyhastrap returnedprop in target, so inheritedObject.prototypemembers resolved from the context andconstructor.constructor('…')()reached theFunctionconstructor — arbitrary code execution whereverbq-*attributes carry untrusted content.Fix
The issue's suggested own-keys-only
hastrap is necessary but not sufficient: once the proxy declinesconstructor,withresolution falls through to the enclosing global scope, where the global object inheritsconstructorfromObject.prototypeand exposesFunction/eval/globalThis. A bareFunction('…')()escapes the same way.So the evaluator now shadows a denylist (
constructor,__proto__,prototype,Function,eval,globalThis,global,window,self,top,parent):hasreports them present (so they never fall through to the global scope) andgetresolves them toundefinedunless the context legitimately owns that property. Member access on the resultingundefinedthrows →undefined. Both the lazy (evaluate) and raw (evaluateRaw) paths are covered.Legitimate templates are unaffected: own context props (including ones shadowing a dangerous name), arithmetic, and method calls on context values (e.g.
name.toUpperCase()) all still work.Verification
constructor.constructor(…)()on bothevaluateandevaluateRaw, bareFunction(…)()andeval(…), plus positive cases (own props, method calls, own-prop shadowing a global name). The exploit tests fail on the pre-fix code.tsc --noEmit+ eslint clean.🤖 Generated with Claude Code