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

feat(ses): Allow import and eval methods #669

Merged
merged 3 commits into from
Apr 15, 2021
Merged

feat(ses): Allow import and eval methods #669

merged 3 commits into from
Apr 15, 2021

Conversation

kriskowal
Copy link
Member

Relaxes the censorship of import and eval in programs evaluated under SES to specifically allow the use of import.import() or evaluator.eval() methods.

Fixes #664

Copy link
Contributor

@dckc dckc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

But I defer approval to @erights

Copy link
Contributor

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +6 to +7
under SES to specifically allow the use of `import.import()` or
`evaluator.eval()` methods.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In both cases, the identifier to the left of the dot looks too specific. To avoid misunderstanding but without metasyntactic ceremony, I'd just say something like something.import() or something.eval() methods.

Comment on lines 26 to 30
// The importPattern incidentally captures an initial \n in
// an attempt to reject a . prefix, so we need to offset
// the line number in that case.
const [p1] = stringMatch(src, pattern);
const adjustment = stringStartsWith(p1, '\n') ? 1 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems weird to do both a stringSearch and a stringMatch. Is the following equivalent?

Suggested change
// The importPattern incidentally captures an initial \n in
// an attempt to reject a . prefix, so we need to offset
// the line number in that case.
const [p1] = stringMatch(src, pattern);
const adjustment = stringStartsWith(p1, '\n') ? 1 : 0;
// The importPattern incidentally captures an initial \n in
// an attempt to reject a . prefix, so we need to offset
// the line number in that case.
const adjustment = src[index] === '\n' ? 1 : 0;

@@ -90,7 +103,7 @@ export function evadeHtmlCommentTest(src) {

// /////////////////////////////////////////////////////////////////////////////

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. I never knew a ^ for "beginning of match" could be used as a disjunct. Nice.

Comment on lines -149 to -151
* Finally, if the original appears in code where it is not parsed as an
* expression, for example `foo.import(path)`, then this evasion would rewrite
* to `foo.__import__(path)` which has a surprisingly different meaning.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment no longer applicable, or does it just need a different example?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is no longer applicable. I don’t know of an example to replace this one. Cases where import( is not an expression of dynamic import that I can readily recall are the case where it’s a comment, in which case there’s no change to the meaning at runtime, and when it’s a method, which should no longer apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid censoring eval and import if preceded by a dot
3 participants