ses 0.18.7 → 0.18.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NEWS.md +26 -1
- package/README.md +4 -4
- package/dist/lockdown.cjs +3435 -3228
- package/dist/lockdown.mjs +3435 -3228
- package/dist/lockdown.umd.js +3435 -3228
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +3435 -3228
- package/dist/ses.mjs +3435 -3228
- package/dist/ses.umd.js +3435 -3228
- package/dist/ses.umd.min.js +1 -1
- package/index.js +3 -31
- package/package.json +6 -6
- package/src/assert-shim.js +4 -0
- package/src/assert-sloppy-mode.js +11 -0
- package/src/compartment-shim.js +11 -288
- package/src/compartment.js +292 -0
- package/src/error/note-log-args.js +2 -3
- package/src/get-anonymous-intrinsics.js +1 -1
- package/src/lockdown-shim.js +19 -379
- package/src/lockdown.js +392 -0
- package/src/make-safe-evaluator.js +2 -2
- package/src/permits.js +12 -5
- package/src/tame-date-constructor.js +37 -21
- package/src/tame-math-object.js +20 -1
- package/src/transforms.js +89 -6
- package/types.d.ts +25 -8
package/src/transforms.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
FERAL_REG_EXP,
|
|
5
5
|
SyntaxError,
|
|
6
|
+
regexpExec,
|
|
6
7
|
stringReplace,
|
|
7
8
|
stringSearch,
|
|
8
9
|
stringSlice,
|
|
@@ -106,10 +107,78 @@ export const evadeHtmlCommentTest = src => {
|
|
|
106
107
|
// /////////////////////////////////////////////////////////////////////////////
|
|
107
108
|
|
|
108
109
|
const importPattern = new FERAL_REG_EXP(
|
|
109
|
-
'(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(
|
|
110
|
+
'(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|\\.|/[/*]))',
|
|
110
111
|
'g',
|
|
111
112
|
);
|
|
112
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Matches one line of a run of `//# sourceURL=` and `//# sourceMappingURL=`
|
|
116
|
+
* comments at the very end of the source (`sourceMetaTrailerStart` finds
|
|
117
|
+
* the run), as module-source, compartment-mapper and
|
|
118
|
+
* bundlers append to evaluated code (a module's location may well contain
|
|
119
|
+
* `import.`, as in `conditional-import.js`).
|
|
120
|
+
*
|
|
121
|
+
* Each line must begin at a line start and its value must hold no whitespace
|
|
122
|
+
* and none of `*`, backtick, `$`, quotes or backslash. Such a line is inert
|
|
123
|
+
* wherever it stands: outside any literal it is a line comment; a regular
|
|
124
|
+
* expression literal cannot span lines; and inside a block comment, a string
|
|
125
|
+
* continued from the line before or a template literal, the line can neither
|
|
126
|
+
* close that context (no `*`, quote or backtick) nor open a substitution (no
|
|
127
|
+
* `$`). Since nothing but whitespace follows the run, an unclosed context
|
|
128
|
+
* there is a SyntaxError. So `rejectImportExpressions` need not scan it.
|
|
129
|
+
*
|
|
130
|
+
* A `/*# sourceMappingURL=` block comment is not skipped but scanned like
|
|
131
|
+
* any other code, which can only make the check stricter.
|
|
132
|
+
*/
|
|
133
|
+
const sourceMetaLinePattern = new FERAL_REG_EXP(
|
|
134
|
+
'^//# source(?:Mapping)?URL=[^\\s*`$\'"\\\\]*$',
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const whitespacePattern = new FERAL_REG_EXP('^\\s$');
|
|
138
|
+
|
|
139
|
+
const lineTerminatorPattern = new FERAL_REG_EXP('^[\\n\\r\\u2028\\u2029]$');
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Returns the index at which the trailing run of source meta comments
|
|
143
|
+
* begins, at its leading line terminator if it has one, or the length of
|
|
144
|
+
* the source if there is no such run. It reads the source backward, one
|
|
145
|
+
* line at a time, and tests each line with `sourceMetaLinePattern` alone,
|
|
146
|
+
* so it takes time linear in the length of the source. A single regular
|
|
147
|
+
* expression for the whole run, `(?:(?:^|[\n\r\u2028\u2029])<line>)+\s*$`,
|
|
148
|
+
* finds the same run, but a search retries it at every line terminator,
|
|
149
|
+
* which takes time quadratic in the number of lines of the run.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} src
|
|
152
|
+
* @returns {number}
|
|
153
|
+
*/
|
|
154
|
+
const sourceMetaTrailerStart = src => {
|
|
155
|
+
let end = src.length;
|
|
156
|
+
while (end > 0 && regexpExec(whitespacePattern, src[end - 1]) !== null) {
|
|
157
|
+
end -= 1;
|
|
158
|
+
}
|
|
159
|
+
let start = src.length;
|
|
160
|
+
for (;;) {
|
|
161
|
+
let lineStart = end;
|
|
162
|
+
while (
|
|
163
|
+
lineStart > 0 &&
|
|
164
|
+
regexpExec(lineTerminatorPattern, src[lineStart - 1]) === null
|
|
165
|
+
) {
|
|
166
|
+
lineStart -= 1;
|
|
167
|
+
}
|
|
168
|
+
if (
|
|
169
|
+
regexpExec(sourceMetaLinePattern, stringSlice(src, lineStart, end)) ===
|
|
170
|
+
null
|
|
171
|
+
) {
|
|
172
|
+
return start;
|
|
173
|
+
}
|
|
174
|
+
if (lineStart === 0) {
|
|
175
|
+
return 0;
|
|
176
|
+
}
|
|
177
|
+
start = lineStart - 1;
|
|
178
|
+
end = lineStart - 1;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
113
182
|
/**
|
|
114
183
|
* Conservatively reject the source text if it may contain a dynamic
|
|
115
184
|
* import expression. To reject without parsing, `rejectImportExpressions` will
|
|
@@ -125,10 +194,23 @@ const importPattern = new FERAL_REG_EXP(
|
|
|
125
194
|
* apparent import expressions in literal strings or comments.
|
|
126
195
|
*
|
|
127
196
|
* The current conservative rule looks for the identifier "import"
|
|
128
|
-
* followed by either an open paren or something that looks like
|
|
129
|
-
* beginning of a comment.
|
|
130
|
-
*
|
|
131
|
-
*
|
|
197
|
+
* followed by either an open paren, a dot, or something that looks like
|
|
198
|
+
* the beginning of a comment. The dot case rejects not just a
|
|
199
|
+
* phase-qualified call such as `import.source(...)` or `import.defer(...)`,
|
|
200
|
+
* but any property access under `import` at all, including `import.meta`,
|
|
201
|
+
* regardless of whether the property is then called. This is broader than
|
|
202
|
+
* strictly necessary: the substring "import." can occur incidentally, for
|
|
203
|
+
* example in a module path or a comment, and such source text is rejected
|
|
204
|
+
* too. That tradeoff is intentional: covering every `import.<name>` form,
|
|
205
|
+
* called or not, without naming specific property names, is judged simpler
|
|
206
|
+
* and safer than narrowing the match to the shape of a call. We assume that
|
|
207
|
+
* we do not need to worry about html comment syntax because that was
|
|
208
|
+
* already rejected by rejectHtmlComments.
|
|
209
|
+
*
|
|
210
|
+
* The scan stops short of a trailing run of `//# sourceURL=` or
|
|
211
|
+
* `//# sourceMappingURL=` comments whose values could not end a comment,
|
|
212
|
+
* string or template (see `sourceMetaTrailerStart`), so that a module
|
|
213
|
+
* whose location contains `import.` still loads.
|
|
132
214
|
*
|
|
133
215
|
* this \s *must* match all kinds of syntax-defined whitespace. If e.g.
|
|
134
216
|
* U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) is treated as
|
|
@@ -141,7 +223,8 @@ const importPattern = new FERAL_REG_EXP(
|
|
|
141
223
|
* @returns {string}
|
|
142
224
|
*/
|
|
143
225
|
export const rejectImportExpressions = src => {
|
|
144
|
-
const
|
|
226
|
+
const scanned = stringSlice(src, 0, sourceMetaTrailerStart(src));
|
|
227
|
+
const lineNumber = getLineNumber(scanned, importPattern);
|
|
145
228
|
if (lineNumber < 0) {
|
|
146
229
|
return src;
|
|
147
230
|
}
|
package/types.d.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// version of harden.
|
|
20
20
|
export type Harden = <T>(value: T) => T; // not Hardened<T>;
|
|
21
21
|
|
|
22
|
-
export interface
|
|
22
|
+
export interface RepairOptions {
|
|
23
23
|
regExpTaming?: 'safe' | 'unsafe';
|
|
24
24
|
localeTaming?: 'safe' | 'unsafe';
|
|
25
25
|
consoleTaming?: 'safe' | 'unsafe';
|
|
@@ -36,6 +36,11 @@ export interface LockdownOptions {
|
|
|
36
36
|
__hardenTaming__?: 'safe' | 'unsafe';
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
// Deprecated in favor of the more specific RepairOptions
|
|
40
|
+
export type LockdownOptions = RepairOptions;
|
|
41
|
+
|
|
42
|
+
export type RepairIntrinsics = (options?: LockdownOptions) => void;
|
|
43
|
+
export type HardenIntrinsics = () => void;
|
|
39
44
|
export type Lockdown = (options?: LockdownOptions) => void;
|
|
40
45
|
|
|
41
46
|
export type __LiveExportMap__ = Record<string, [string, boolean]>;
|
|
@@ -172,19 +177,13 @@ export type Raise = (reason: Error) => void;
|
|
|
172
177
|
// eslint-disable-next-line no-use-before-define
|
|
173
178
|
export type MakeAssert = (raise?: Raise, unredacted?: boolean) => Assert;
|
|
174
179
|
|
|
175
|
-
export interface
|
|
180
|
+
export interface AssertionFunctions {
|
|
176
181
|
(
|
|
177
182
|
value: any,
|
|
178
183
|
details?: Details,
|
|
179
184
|
errorConstructor?: ErrorConstructor,
|
|
180
185
|
): asserts value;
|
|
181
186
|
typeof: AssertTypeof;
|
|
182
|
-
error(
|
|
183
|
-
details?: Details,
|
|
184
|
-
errorConstructor?: ErrorConstructor,
|
|
185
|
-
options?: AssertMakeErrorOptions,
|
|
186
|
-
): Error;
|
|
187
|
-
fail(details?: Details, errorConstructor?: ErrorConstructor): never;
|
|
188
187
|
equal(
|
|
189
188
|
left: any,
|
|
190
189
|
right: any,
|
|
@@ -192,6 +191,15 @@ export interface Assert {
|
|
|
192
191
|
errorConstructor?: ErrorConstructor,
|
|
193
192
|
): void;
|
|
194
193
|
string(specimen: any, details?: Details): asserts specimen is string;
|
|
194
|
+
fail(details?: Details, errorConstructor?: ErrorConstructor): never;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface AssertionUtilities {
|
|
198
|
+
error(
|
|
199
|
+
details?: Details,
|
|
200
|
+
errorConstructor?: ErrorConstructor,
|
|
201
|
+
options?: AssertMakeErrorOptions,
|
|
202
|
+
): Error;
|
|
195
203
|
note(error: Error, details: Details): void;
|
|
196
204
|
details(
|
|
197
205
|
template: TemplateStringsArray | string[],
|
|
@@ -200,9 +208,16 @@ export interface Assert {
|
|
|
200
208
|
Fail(template: TemplateStringsArray | string[], ...args: any): never;
|
|
201
209
|
quote(payload: any, spaces?: string | number): ToStringable;
|
|
202
210
|
bare(payload: any, spaces?: string | number): ToStringable;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface DeprecatedAssertionUtilities {
|
|
203
214
|
makeAssert: MakeAssert;
|
|
204
215
|
}
|
|
205
216
|
|
|
217
|
+
export type Assert = AssertionFunctions &
|
|
218
|
+
AssertionUtilities &
|
|
219
|
+
DeprecatedAssertionUtilities;
|
|
220
|
+
|
|
206
221
|
interface CompartmentEvaluateOptions {
|
|
207
222
|
sloppyGlobalsMode?: boolean;
|
|
208
223
|
__moduleShimLexicals__?: Object;
|
|
@@ -214,6 +229,8 @@ interface CompartmentEvaluateOptions {
|
|
|
214
229
|
declare global {
|
|
215
230
|
var harden: Harden;
|
|
216
231
|
|
|
232
|
+
var repairIntrinsics: RepairIntrinsics;
|
|
233
|
+
var hardenIntrinsics: HardenIntrinsics;
|
|
217
234
|
var lockdown: Lockdown;
|
|
218
235
|
|
|
219
236
|
var assert: Assert;
|