-
Notifications
You must be signed in to change notification settings - Fork 9
fix(agent-script): prevent Object globals from mutating host prototypes #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,13 +37,7 @@ export function createObjectArrayGlobals(options: { budget: Budget }): ObjectArr | |||||||||||||||||||||||
| name: "fromEntries" | ||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||
| freeze: createSandboxClosure({ | ||||||||||||||||||||||||
| call: ([value]) => { | ||||||||||||||||||||||||
| if (typeof value === "object" && value !== null) { | ||||||||||||||||||||||||
| Object.freeze(value); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return value; | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| call: ([value]) => freezeSandboxValue(value), | ||||||||||||||||||||||||
| name: "freeze" | ||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||
| assign: createSandboxClosure({ | ||||||||||||||||||||||||
|
|
@@ -80,6 +74,15 @@ export function createObjectArrayGlobals(options: { budget: Budget }): ObjectArr | |||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function freezeSandboxValue(value: SandboxValue): SandboxValue { | ||||||||||||||||||||||||
| if (!isAssignableSandboxTarget(value)) { | ||||||||||||||||||||||||
| return value; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Object.freeze(value); | ||||||||||||||||||||||||
| return value; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function assignSandboxValues(target: SandboxValue, sources: readonly SandboxValue[]): SandboxValue { | ||||||||||||||||||||||||
| if (target === null || target === undefined) { | ||||||||||||||||||||||||
| throw new TypeError("Object.assign(target, ...sources) requires a non-null target."); | ||||||||||||||||||||||||
|
|
@@ -105,7 +108,15 @@ function assignSandboxValues(target: SandboxValue, sources: readonly SandboxValu | |||||||||||||||||||||||
| function isAssignableSandboxTarget( | ||||||||||||||||||||||||
| value: SandboxValue | ||||||||||||||||||||||||
| ): value is SandboxObject & Record<string, SandboxValue> | SandboxValue[] & Record<string, SandboxValue> { | ||||||||||||||||||||||||
| return typeof value === "object" && value !== null && !isSandboxClosure(value) && !isSandboxPromise(value); | ||||||||||||||||||||||||
| if (typeof value !== "object" || value === null || isSandboxClosure(value) || isSandboxPromise(value)) { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (Array.isArray(value)) { | ||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return Object.getPrototypeOf(value) === Object.prototype; | ||||||||||||||||||||||||
|
Comment on lines
+115
to
+119
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Object literals are created with
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| async function arrayFromSandboxValues(args: readonly SandboxValue[], budget: Budget): Promise<SandboxValue> { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add coverage for the sandbox object-literal/null-prototype path here too. The current test covers
Object.prototype, but not{}from the interpreter, which is the regression path forObject.assign({}, source)andObject.freeze({}).