Skip to content
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

fix: Avoid elements created through the create element ns api from escaping the sandbox #645

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/browser-vm/src/dynamicNode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export function makeElInjector(sandboxConfig: SandboxOptions) {

if (typeof window.Element === 'function') {
// iframe can read html container this can't point to proxyDocument has Illegal invocation error
if (sandboxConfig.fixBaseUrl) safeWrapper(() => handleOwnerDocument());
if (sandboxConfig.fixBaseUrl || sandboxConfig.fixOwnerDocument)
safeWrapper(() => handleOwnerDocument());
const rewrite = (
methods: Array<string>,
builder: typeof injector | typeof injectorRemoveChild,
Expand Down
4 changes: 3 additions & 1 deletion packages/browser-vm/src/pluginify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ function createOptions(Garfish: interfaces.Garfish) {
fixStaticResourceBaseUrl: Boolean(
appInfo.sandbox?.fixStaticResourceBaseUrl,
),
fixOwnerDocument: Boolean(appInfo.sandbox?.fixOwnerDocument),
disableWith: Boolean(appInfo.sandbox?.disableWith),
disableElementtiming: Boolean(appInfo.sandbox?.disableElementtiming),
strictIsolation: Boolean(appInfo.sandbox?.strictIsolation),
// 缓存模式,不收集副作用
disableCollect: appInfo.cache === undefined ? true : Boolean(appInfo.cache),
disableCollect:
appInfo.cache === undefined ? true : Boolean(appInfo.cache),
el: () => appInstance.htmlNode,
styleScopeId: () => appInstance.appContainer.id,
protectVariable: () => appInfo.protectVariable || [],
Expand Down
6 changes: 6 additions & 0 deletions packages/browser-vm/src/proxyInterceptor/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export function createGetter(sandbox: Sandbox) {
const el = value.call(document, tagName, options);
return setSandboxRef(el);
};
}
if (p === 'createElementNS') {
return function (...args) {
const el = value.call(document, ...args);
return setSandboxRef(el);
};
} else if (p === 'createTextNode') {
return function (data) {
const el = value.call(document, data);
Expand Down
1 change: 1 addition & 0 deletions packages/browser-vm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface SandboxOptions {
namespace: string;
baseUrl?: string;
fixBaseUrl?: boolean;
fixOwnerDocument?: boolean;
fixStaticResourceBaseUrl?: boolean;
disableWith?: boolean;
strictIsolation?: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const createDefaultOptions = () => {
disableWith: false,
strictIsolation: false,
disableElementtiming: false,
fixOwnerDocument: false,
},
// global hooks
beforeLoad: () => {},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export namespace interfaces {
disableWith?: boolean;
strictIsolation?: boolean;
disableElementtiming?: boolean;
fixOwnerDocument?: boolean;
}

export interface Config {
Expand Down
Loading