forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: fix code injection through export names
createDynamicModule() properly escapes import names, but not export names. In WebAssembly, any string is a valid export name. Importing a WebAssembly module that uses a non-identifier export name leads to either a syntax error in createDynamicModule() or to code injection, that is, to the evaluation of almost arbitrary JavaScript code outside of the WebAssembly module. To address this issue, adopt the same mechanism in createExport() that createImport() already uses. Add tests for both exports and imports. PR-URL: nodejs-private/node-private#461 Backport-PR-URL: nodejs-private/node-private#489 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> CVE-ID: CVE-2023-39333
- Loading branch information
Showing
8 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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
Binary file not shown.
This file contains 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,8 @@ | ||
;; Compiled using the WebAssembly Binary Toolkit (https://github.com/WebAssembly/wabt) | ||
;; $ wat2wasm export-name-code-injection.wat | ||
|
||
(module | ||
(global $0 i32 (i32.const 123)) | ||
(global $1 i32 (i32.const 456)) | ||
(export ";import.meta.done=()=>{};console.log('code injection');{/*" (global $0)) | ||
(export "/*/$;`//" (global $1))) |
Binary file not shown.
This file contains 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,6 @@ | ||
;; Compiled using the WebAssembly Binary Toolkit (https://github.com/WebAssembly/wabt) | ||
;; $ wat2wasm export-name-syntax-error.wat | ||
|
||
(module | ||
(global $0 i32 (i32.const 12682)) | ||
(export "?f!o:o<b>a[r]" (global $0))) |
Binary file not shown.
This file contains 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,10 @@ | ||
;; Compiled using the WebAssembly Binary Toolkit (https://github.com/WebAssembly/wabt) | ||
;; $ wat2wasm import-name.wat | ||
|
||
(module | ||
(global $0 (import "./export-name-code-injection.wasm" ";import.meta.done=()=>{};console.log('code injection');{/*") i32) | ||
(global $1 (import "./export-name-code-injection.wasm" "/*/$;`//") i32) | ||
(global $2 (import "./export-name-syntax-error.wasm" "?f!o:o<b>a[r]") i32) | ||
(func $xor (result i32) | ||
(i32.xor (i32.xor (global.get $0) (global.get $1)) (global.get $2))) | ||
(export "xor" (func $xor))) |