New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@locker/sandbox

Package Overview
Dependencies
Maintainers
7
Versions
259
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@locker/sandbox - npm Package Compare versions

Comparing version 0.13.5 to 0.13.6

96

dist/index.cjs.js

@@ -9,4 +9,6 @@ /**

var distortion = require('@locker/distortion');
var instrumentation = require('@locker/instrumentation');
var shared = require('@locker/shared');
var createVirtualEnvironment = require('@locker/near-membrane-dom');
var sharedDom = require('@locker/shared-dom');

@@ -83,3 +85,27 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

const loadingPromises = new shared.WeakMapCtor();
function createSandbox(key, distortionMap, endowments) {
function addWindowDistortion(record, w) {
const { distortionFactory, distortions } = record;
const entries = distortionFactory(w);
for (let i = 0, len = entries.length; i < len; i += 1) {
const [key, value] = entries[i];
shared.WeakMapSet(distortions, key, value);
}
}
function createDistortionCallback(record) {
return (redValueOrWindow) => {
const { distortions } = record;
const distortedValue = shared.WeakMapGet(distortions, redValueOrWindow);
if (distortedValue) {
return distortedValue;
}
if (sharedDom.isWindowLike(redValueOrWindow) && sharedDom.isWindow(redValueOrWindow)) {
addWindowDistortion(record, redValueOrWindow);
// this is to trick createDistortionCallback in case this window is seeing again
// just return immediately
shared.WeakMapSet(distortions, redValueOrWindow, redValueOrWindow);
}
return redValueOrWindow;
};
}
function createSandbox(key, distortionFactory, endowments) {
// Normalize the descriptors of the optional provided endowments object,

@@ -93,7 +119,10 @@ // and the default endowments so they can be accessible from inside the

const record = shared.ObjectCreate(null);
const distortionCallback = createDistortionCallback(record);
record.distortionFactory = distortionFactory;
record.distortions = new shared.WeakMapCtor(distortionFactory(window));
record.evaluator = createVirtualEnvironment__default['default']({
distortionMap,
distortionCallback,
endowments: normalizedEndowments,
// Flag whether the iframe should remain connected to DOM.
keepAlive: false,
keepAlive: "production" !== 'production',
});

@@ -119,4 +148,5 @@ record.helpers = shared.ObjectCreate(null);

const { createElement: DocumentProtoCreateElement } = Document.prototype;
const { addEventListener: ElementProtoAddEventListener, querySelector: ElementProtoQuerySelector, setAttribute: ElementProtoSetAttribute, } = Element.prototype;
const { querySelector: ElementProtoQuerySelector, setAttribute: ElementProtoSetAttribute, } = Element.prototype;
const { stopPropagation: EventProtoStopPropagation } = Event.prototype;
const { addEventListener: EventTargetProtoAddEventListener } = EventTarget.prototype;
const { appendChild: NodeProtoAppendChild } = Node.prototype;

@@ -130,5 +160,2 @@ const { get: WeakMapProtoGet, set: WeakMapProtoSet } = WeakMap.prototype;

}
function ElementAddEventListener(el, type, listener) {
return ReflectApply(ElementProtoAddEventListener, el, [type, listener]);
}
function ElementQuerySelector(el, selectors) {

@@ -143,5 +170,9 @@ return ReflectApply(ElementProtoQuerySelector, el, [selectors]);

}
function EventTargetAddEventListener(target, ...args) {
return ReflectApply(EventTargetProtoAddEventListener, target, args);
}
function NodeAppendChild(node, childNode) {
return ReflectApply(NodeProtoAppendChild, node, [childNode]);
}
// eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow
function WeakMapGet(weakMap,

@@ -152,2 +183,3 @@ // eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow

}
// eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow
function WeakMapSet(weakMap,

@@ -211,6 +243,6 @@ // eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow

const promise = new PromiseCtor((resolve, reject) => {
ElementAddEventListener(element, 'load', () => {
EventTargetAddEventListener(element, 'load', () => {
resolve(undefined);
});
ElementAddEventListener(element, 'error', (evt) => {
EventTargetAddEventListener(element, 'error', (evt) => {
EventStopPropagation(evt);

@@ -262,3 +294,6 @@ reject(loadingError(url));

function evaluateInSandbox(key, sourceText, context, endowments) {
// @TODO: [Issue #373] Abstract common code in sandbox and distortion packages
function evaluateInSandbox(key, sourceText, context, endowments, instrumentationService) {
const instrumentation$1 = instrumentationService || instrumentation.defaultInstrumentation;
const { errorBeacon, activityBeacon } = instrumentation$1;
if (typeof sourceText !== 'string') {

@@ -269,7 +304,19 @@ sourceText = toModuleSource(sourceText);

if (!record) {
const activityCreateDistortionEntries = activityBeacon(key, 'createExternalDistortionEntries');
const activityCreateSandbox = activityBeacon(key, 'createSandbox');
if (!shared.isObjectLike(endowments)) {
endowments = undefined;
}
const distortionMap = distortion.makeExternalDistortionMap(window, key, evaluateInSandbox);
record = createSandbox(key, distortionMap, endowments);
const config = shared.ObjectCreate(null, {
instrumentation: { value: instrumentation$1 },
});
const distortionFactory = (win) => {
activityCreateDistortionEntries.start();
const distortionEntries = distortion.createExternalDistortionEntries(win, key, evaluateInSandbox, config);
activityCreateDistortionEntries.stop();
return distortionEntries;
};
activityCreateSandbox.start();
record = createSandbox(key, distortionFactory, endowments);
activityCreateSandbox.stop();
}

@@ -294,2 +341,3 @@ // Provisioning the context before evaluating the sourceText

if (error !== undefined) {
errorBeacon(key, error);
// eslint-disable-next-line no-unsafe-finally

@@ -302,3 +350,6 @@ throw error;

const CORE_SANDBOX = '@@CORE';
function evaluateInCoreSandbox(_key, sourceText, context, endowments) {
// @TODO: [Issue #373] Abstract common code in sandbox and distortion packages
function evaluateInCoreSandbox(_key, sourceText, context, endowments, instrumentationService) {
const instrumentation$1 = instrumentationService || instrumentation.defaultInstrumentation;
const { errorBeacon, activityBeacon } = instrumentation$1;
if (typeof sourceText !== 'string') {

@@ -309,7 +360,19 @@ sourceText = toModuleSource(sourceText);

if (!record) {
const activityCreateDistortionEntries = activityBeacon(CORE_SANDBOX, 'createInternalDistortionEntries');
const activityCreateSandbox = activityBeacon(CORE_SANDBOX, 'createSandbox');
if (!shared.isObjectLike(endowments)) {
endowments = undefined;
}
const distortionMap = distortion.makeInternalDistortionMap(window, CORE_SANDBOX, evaluateInCoreSandbox);
record = createSandbox(CORE_SANDBOX, distortionMap, endowments);
const config = shared.ObjectCreate(null, {
instrumentation: { value: instrumentation$1 },
});
const distortionFactory = (win) => {
activityCreateDistortionEntries.start();
const distortionEntries = distortion.createInternalDistortionEntries(win, CORE_SANDBOX, evaluateInCoreSandbox, config);
activityCreateDistortionEntries.stop();
return distortionEntries;
};
activityCreateSandbox.start();
record = createSandbox(CORE_SANDBOX, distortionFactory, endowments);
activityCreateSandbox.stop();
}

@@ -334,2 +397,3 @@ // Provisioning the context before evaluating the sourceText

if (error !== undefined) {
errorBeacon(CORE_SANDBOX, error);
// eslint-disable-next-line no-unsafe-finally

@@ -343,2 +407,2 @@ throw error;

exports.evaluateInSandbox = evaluateInSandbox;
/** version: 0.13.5 */
/** version: 0.13.6 */
/**
* Copyright (C) 2019 salesforce.com, inc.
*/
import { makeExternalDistortionMap, makeInternalDistortionMap } from '@locker/distortion';
import { toSafeDescriptorMap, ObjectCreate, WeakMapCtor, toString, StringMatch, StringReplace, ObjectDefineProperties, ObjectGetOwnPropertyDescriptors, ObjectAssign, isObjectLike } from '@locker/shared';
import { createExternalDistortionEntries, createInternalDistortionEntries } from '@locker/distortion';
import { defaultInstrumentation } from '@locker/instrumentation';
import { toSafeDescriptorMap, ObjectCreate, WeakMapCtor, toString, StringMatch, StringReplace, ObjectDefineProperties, ObjectGetOwnPropertyDescriptors, WeakMapGet, WeakMapSet, ObjectAssign, isObjectLike } from '@locker/shared';
import createVirtualEnvironment from '@locker/near-membrane-dom';
import { isWindowLike, isWindow } from '@locker/shared-dom';

@@ -74,3 +76,27 @@ let lockerEvalContextValue;

const loadingPromises = new WeakMapCtor();
function createSandbox(key, distortionMap, endowments) {
function addWindowDistortion(record, w) {
const { distortionFactory, distortions } = record;
const entries = distortionFactory(w);
for (let i = 0, len = entries.length; i < len; i += 1) {
const [key, value] = entries[i];
WeakMapSet(distortions, key, value);
}
}
function createDistortionCallback(record) {
return (redValueOrWindow) => {
const { distortions } = record;
const distortedValue = WeakMapGet(distortions, redValueOrWindow);
if (distortedValue) {
return distortedValue;
}
if (isWindowLike(redValueOrWindow) && isWindow(redValueOrWindow)) {
addWindowDistortion(record, redValueOrWindow);
// this is to trick createDistortionCallback in case this window is seeing again
// just return immediately
WeakMapSet(distortions, redValueOrWindow, redValueOrWindow);
}
return redValueOrWindow;
};
}
function createSandbox(key, distortionFactory, endowments) {
// Normalize the descriptors of the optional provided endowments object,

@@ -84,7 +110,10 @@ // and the default endowments so they can be accessible from inside the

const record = ObjectCreate(null);
const distortionCallback = createDistortionCallback(record);
record.distortionFactory = distortionFactory;
record.distortions = new WeakMapCtor(distortionFactory(window));
record.evaluator = createVirtualEnvironment({
distortionMap,
distortionCallback,
endowments: normalizedEndowments,
// Flag whether the iframe should remain connected to DOM.
keepAlive: false,
keepAlive: "production" !== 'production',
});

@@ -110,4 +139,5 @@ record.helpers = ObjectCreate(null);

const { createElement: DocumentProtoCreateElement } = Document.prototype;
const { addEventListener: ElementProtoAddEventListener, querySelector: ElementProtoQuerySelector, setAttribute: ElementProtoSetAttribute, } = Element.prototype;
const { querySelector: ElementProtoQuerySelector, setAttribute: ElementProtoSetAttribute, } = Element.prototype;
const { stopPropagation: EventProtoStopPropagation } = Event.prototype;
const { addEventListener: EventTargetProtoAddEventListener } = EventTarget.prototype;
const { appendChild: NodeProtoAppendChild } = Node.prototype;

@@ -121,5 +151,2 @@ const { get: WeakMapProtoGet, set: WeakMapProtoSet } = WeakMap.prototype;

}
function ElementAddEventListener(el, type, listener) {
return ReflectApply(ElementProtoAddEventListener, el, [type, listener]);
}
function ElementQuerySelector(el, selectors) {

@@ -134,5 +161,9 @@ return ReflectApply(ElementProtoQuerySelector, el, [selectors]);

}
function EventTargetAddEventListener(target, ...args) {
return ReflectApply(EventTargetProtoAddEventListener, target, args);
}
function NodeAppendChild(node, childNode) {
return ReflectApply(NodeProtoAppendChild, node, [childNode]);
}
// eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow
function WeakMapGet(weakMap,

@@ -143,2 +174,3 @@ // eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow

}
// eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow
function WeakMapSet(weakMap,

@@ -202,6 +234,6 @@ // eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow

const promise = new PromiseCtor((resolve, reject) => {
ElementAddEventListener(element, 'load', () => {
EventTargetAddEventListener(element, 'load', () => {
resolve(undefined);
});
ElementAddEventListener(element, 'error', (evt) => {
EventTargetAddEventListener(element, 'error', (evt) => {
EventStopPropagation(evt);

@@ -253,3 +285,6 @@ reject(loadingError(url));

function evaluateInSandbox(key, sourceText, context, endowments) {
// @TODO: [Issue #373] Abstract common code in sandbox and distortion packages
function evaluateInSandbox(key, sourceText, context, endowments, instrumentationService) {
const instrumentation = instrumentationService || defaultInstrumentation;
const { errorBeacon, activityBeacon } = instrumentation;
if (typeof sourceText !== 'string') {

@@ -260,7 +295,19 @@ sourceText = toModuleSource(sourceText);

if (!record) {
const activityCreateDistortionEntries = activityBeacon(key, 'createExternalDistortionEntries');
const activityCreateSandbox = activityBeacon(key, 'createSandbox');
if (!isObjectLike(endowments)) {
endowments = undefined;
}
const distortionMap = makeExternalDistortionMap(window, key, evaluateInSandbox);
record = createSandbox(key, distortionMap, endowments);
const config = ObjectCreate(null, {
instrumentation: { value: instrumentation },
});
const distortionFactory = (win) => {
activityCreateDistortionEntries.start();
const distortionEntries = createExternalDistortionEntries(win, key, evaluateInSandbox, config);
activityCreateDistortionEntries.stop();
return distortionEntries;
};
activityCreateSandbox.start();
record = createSandbox(key, distortionFactory, endowments);
activityCreateSandbox.stop();
}

@@ -285,2 +332,3 @@ // Provisioning the context before evaluating the sourceText

if (error !== undefined) {
errorBeacon(key, error);
// eslint-disable-next-line no-unsafe-finally

@@ -293,3 +341,6 @@ throw error;

const CORE_SANDBOX = '@@CORE';
function evaluateInCoreSandbox(_key, sourceText, context, endowments) {
// @TODO: [Issue #373] Abstract common code in sandbox and distortion packages
function evaluateInCoreSandbox(_key, sourceText, context, endowments, instrumentationService) {
const instrumentation = instrumentationService || defaultInstrumentation;
const { errorBeacon, activityBeacon } = instrumentation;
if (typeof sourceText !== 'string') {

@@ -300,7 +351,19 @@ sourceText = toModuleSource(sourceText);

if (!record) {
const activityCreateDistortionEntries = activityBeacon(CORE_SANDBOX, 'createInternalDistortionEntries');
const activityCreateSandbox = activityBeacon(CORE_SANDBOX, 'createSandbox');
if (!isObjectLike(endowments)) {
endowments = undefined;
}
const distortionMap = makeInternalDistortionMap(window, CORE_SANDBOX, evaluateInCoreSandbox);
record = createSandbox(CORE_SANDBOX, distortionMap, endowments);
const config = ObjectCreate(null, {
instrumentation: { value: instrumentation },
});
const distortionFactory = (win) => {
activityCreateDistortionEntries.start();
const distortionEntries = createInternalDistortionEntries(win, CORE_SANDBOX, evaluateInCoreSandbox, config);
activityCreateDistortionEntries.stop();
return distortionEntries;
};
activityCreateSandbox.start();
record = createSandbox(CORE_SANDBOX, distortionFactory, endowments);
activityCreateSandbox.stop();
}

@@ -325,2 +388,3 @@ // Provisioning the context before evaluating the sourceText

if (error !== undefined) {
errorBeacon(CORE_SANDBOX, error);
// eslint-disable-next-line no-unsafe-finally

@@ -333,2 +397,2 @@ throw error;

export { evaluateInCoreSandbox, evaluateInSandbox };
/** version: 0.13.5 */
/** version: 0.13.6 */

23

package.json
{
"name": "@locker/sandbox",
"version": "0.13.5",
"version": "0.13.6",
"license": "Salesforce Developer Agreement",

@@ -10,6 +10,17 @@ "author": "Salesforce UI Security Team",

"typings": "types/index.d.ts",
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc --project tsconfig.types.json && rollup --config .rolluprc.cjs",
"build:dev": "cross-env NODE_ENV=development yarn build",
"clean": "locker-trash dist/ types/"
},
"dependencies": {
"@locker/distortion": "0.13.6",
"@locker/instrumentation": "0.13.6",
"@locker/near-membrane-dom": "0.6.0",
"@locker/shared": "0.13.6",
"@locker/shared-dom": "0.13.6"
},
"files": [

@@ -19,11 +30,3 @@ "dist/",

],
"publishConfig": {
"access": "public"
},
"dependencies": {
"@locker/distortion": "0.13.5",
"@locker/near-membrane-dom": "0.5.1",
"@locker/shared": "0.13.5"
},
"gitHead": "213b7ea798dd4a01891a5b5ead2cff46f6db5600"
"gitHead": "c323e27d3a3d5767725b338c81f9e24cb59cbc6f"
}

@@ -1,2 +0,3 @@

import { DistortionMap, SandboxKey } from '@locker/distortion';
import { DistortionMap, DistortionMapEntries, SandboxKey } from '@locker/distortion';
import { GlobalObject } from '@locker/shared-dom/types';
interface EvalHelpers {

@@ -10,4 +11,6 @@ asyncToGen: Function;

interface SandboxRecord {
evaluator: Function;
evaluator: (sourceText: string) => void;
helpers: EvalHelpers;
distortions: DistortionMap;
distortionFactory: (window: GlobalObject) => DistortionMapEntries;
}

@@ -20,4 +23,4 @@ export declare function clearEvalContext(): any;

export declare function getSandbox(key: SandboxKey): SandboxRecord;
export declare function createSandbox(key: SandboxKey, distortionMap: DistortionMap, endowments: object | undefined): SandboxRecord;
export declare function createSandbox(key: SandboxKey, distortionFactory: (window: GlobalObject) => DistortionMapEntries, endowments: object | undefined): SandboxRecord;
export {};
//# sourceMappingURL=common.d.ts.map
import { SandboxKey } from '@locker/distortion';
export declare function evaluateInSandbox(key: SandboxKey, sourceText: Function | string, context?: any, endowments?: object): void;
import { LockerInstrumentation } from '@locker/instrumentation/types';
export declare function evaluateInSandbox(key: SandboxKey, sourceText: Function | string, context?: any, endowments?: object, instrumentationService?: LockerInstrumentation): void;
//# sourceMappingURL=external.d.ts.map
import { SandboxKey } from '@locker/distortion';
export declare function evaluateInCoreSandbox(_key: SandboxKey, sourceText: Function | string, context?: any, endowments?: object): void;
import { LockerInstrumentation } from '@locker/instrumentation/types';
export declare function evaluateInCoreSandbox(_key: SandboxKey, sourceText: Function | string, context?: any, endowments?: object, instrumentationService?: LockerInstrumentation): void;
//# sourceMappingURL=internal.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc