Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Reject CommonJS WASM payload imports

Manav Rathi68eff1c676e2
diff --git a/web/scripts/wasm-imports/eslint.config.mjs b/web/scripts/wasm-imports/eslint.config.mjs
index 57b8cef0a0..d2f38241cb 100644
--- a/web/scripts/wasm-imports/eslint.config.mjs
+++ b/web/scripts/wasm-imports/eslint.config.mjs
@@ -2,6 +2,11 @@ export const rawWasmPath = String.raw`(?:^|/)pkg(?:/|$)|\.wasm(?:[?#].*)?$`;
const selectorRawWasmPath = rawWasmPath.replaceAll("/", "\\u002F");
const payloadImport = `ImportExpression[source.value=/${selectorRawWasmPath}/]`;
+const payloadRequire = `CallExpression[callee.name=require][arguments.0.value=/${selectorRawWasmPath}/]`;
+const restrictedPayloadRequire = {
+ selector: payloadRequire,
+ message: "Load generated WASM with import() inside its wrapper.",
+};
const exportedPayloadLoader = [
"ExportNamedDeclaration > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression > ImportExpression",
"ExportNamedDeclaration > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression > AwaitExpression > ImportExpression",
@@ -51,6 +56,7 @@ export default [
message:
"Load generated WASM through a wrapper in web/packages/wasm.",
},
+ restrictedPayloadRequire,
],
},
},
@@ -73,6 +79,7 @@ export default [
message:
"Export operations instead of the generated WASM module.",
},
+ restrictedPayloadRequire,
],
},
},
diff --git a/web/scripts/wasm-imports/test.mjs b/web/scripts/wasm-imports/test.mjs
index a278c6a09a..c0ed78ed87 100644
--- a/web/scripts/wasm-imports/test.mjs
+++ b/web/scripts/wasm-imports/test.mjs
@@ -87,6 +87,13 @@ test("WASM inner boundary", async (t) => {
error: "no-restricted-imports",
},
],
+ [
+ "CommonJS payload import",
+ {
+ source: 'const wasm = require("./pkg/arbitrary-name");',
+ error: "no-restricted-syntax",
+ },
+ ],
[
"raw binding re-export",
{