-
-
Notifications
You must be signed in to change notification settings - Fork 94
fix(extensions): bound the entry-source AST walk instead of overflowing the stack #3025
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
Merged
+169
−13
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c18f548
fix(extensions): make banned-construct check walk the whole entry-scr…
BIMvoice cb68481
fix(extensions): bound the entry-script AST walk instead of recursing
BIMvoice a764c99
Merge branch 'main' into source-wrap-recurse
louistrue 8d9c5b4
Merge branch 'main' into source-wrap-recurse
louistrue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| "@ifc-lite/extensions": patch | ||
| --- | ||
|
|
||
| Make `wrapEntrySource`'s banned-construct check walk the entire entry-script AST instead of only its top-level statements. | ||
|
|
||
| The check existed to flag `import`/`export` syntax at wrap time so extension authors get a clear, early error instead of a confusing runtime failure. It only ever inspected `ast.body`, so any of those constructs written inside a nested function, arrow body, or class method passed silently. In practice the QuickJS sandbox realm has no module loader registered, so a nested dynamic `import(...)` was always going to fail at runtime anyway with an opaque engine error — this change moves that failure earlier and makes it legible, and closes the gap between what the check's name and callers assume ("banned constructs are caught") and what it verified. | ||
|
|
||
| The walk now also flags dynamic `import(...)` anywhere it appears, not just static top-level `import`/`export` declarations (which the ECMAScript grammar restricts to the top level regardless of where the walk looks). `eval` and `new Function` are deliberately left alone: both run confined inside the same non-module sandbox realm with no path to the host bridge, and banning them would restrict legitimate extension code for no isolation benefit. | ||
|
|
||
| The walk iterates over an explicit stack rather than recursing, and stops at a fixed depth of 1000 AST levels. `wrapEntrySource` returns a `ValidationResult`, so a deeply nested entry script has to come back as a reported error; a recursive walk instead threw a `RangeError` ("Maximum call stack size exceeded") out of the middle of it, at roughly 500 nested blocks. Past the bound the script is now rejected with an `invalid_value` error naming the limit, matching how acorn's own parser already degrades on input it cannot handle. Real entry scripts nest a few tens of levels deep. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the nested syntax description.
Static
importandexportdeclarations cannot occur inside function, arrow, or class-method bodies. Acorn rejects those forms during parsing, so they did not bypass the previousast.bodyscan. Describe nested dynamicimport(...)as the bypassed construct.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents