Skip to content

Commit

Permalink
fix(fix): Censor spread import
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Aug 7, 2023
1 parent ee5961d commit fc90c64
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/ses/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
User-visible changes in SES:

# Next

- Censors the pattern `{...import(specifier)`}.
We previously censored `import(specifier)` and expressly allowed
`object.import(specifier)`.
The relaxation for the latter form in version 0.13.0 inadvertently allowed
import with the spread operator.

# v0.18.5 (2023-07-14)

- Adds `assert.bare` for embedding unquoted strings in details.
Expand Down
2 changes: 1 addition & 1 deletion packages/ses/src/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const evadeHtmlCommentTest = src => {
// /////////////////////////////////////////////////////////////////////////////

const importPattern = new FERAL_REG_EXP(
'(^|[^.])\\bimport(\\s*(?:\\(|/[/*]))',
'(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|/[/*]))',
'g',
);

Expand Down
28 changes: 27 additions & 1 deletion packages/ses/test/test-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../src/transforms.js';

test('no-import-expression regexp', t => {
t.plan(9);
t.plan(14);

// Note: we cannot define these as regular functions (and then stringify)
// because the 'esm' module loader that we use for running the tests (i.e.
Expand All @@ -20,17 +20,23 @@ test('no-import-expression regexp', t => {
const safe = 'const a = 1';
const safe2 = "const a = notimport('evil')";
const safe3 = "const a = importnot('evil')";
const safe4 = "const a = compartment.import('name')";

const obvious = "const a = import('evil')";
const whitespace = "const a = import ('evil')";
const comment = "const a = import/*hah*/('evil')";
const doubleSlashComment = "const a = import // hah\n('evil')";
const newline = "const a = import\n('evil')";
const multiline = "\nimport('a')\nimport('b')";
const spread = "{...import('exfil')}";
const spread2 = "{... import('exfil')}";
const spread3 = "{\n...\nimport\n('exfil')}";
const spread4 = "{\n...\nimport/**/\n('exfil')}";

t.is(rejectImportExpressions(safe), safe, 'safe');
t.is(rejectImportExpressions(safe2), safe2, 'safe2');
t.is(rejectImportExpressions(safe3), safe3, 'safe3');
t.is(rejectImportExpressions(safe4), safe4, 'safe4');
t.throws(
() => rejectImportExpressions(obvious),
{ instanceOf: SyntaxError },
Expand Down Expand Up @@ -62,6 +68,26 @@ test('no-import-expression regexp', t => {
'possible import expression rejected around line 2',
'multiline',
);
t.throws(
() => rejectImportExpressions(spread),
{ instanceOf: SyntaxError },
'spread',
);
t.throws(
() => rejectImportExpressions(spread2),
{ instanceOf: SyntaxError },
'spread2',
);
t.throws(
() => rejectImportExpressions(spread3),
{ instanceOf: SyntaxError },
'spread3',
);
t.throws(
() => rejectImportExpressions(spread4),
{ instanceOf: SyntaxError },
'spread4',
);
});

test('no-html-comment-expression regexp', t => {
Expand Down

0 comments on commit fc90c64

Please sign in to comment.