fix: nodejs wrapper передаёт require в new Function (v1.3.95)

This commit is contained in:
“Naeel”
2026-05-19 16:48:19 +04:00
parent 27dbe3bccb
commit fe8870af71
5 changed files with 20 additions and 16 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ spec:
serviceAccountName: fission-console
containers:
- name: console
image: naeel/fission-console:v1.3.94
image: naeel/fission-console:v1.3.95
imagePullPolicy: Always
ports:
- containerPort: 8090
+1 -1
View File
@@ -113,7 +113,7 @@ func decodeArchiveBytesToSource(decoded []byte) (string, error) {
return "", io.ErrUnexpectedEOF
}
var nodeJSWrapperPattern = regexp.MustCompile(`(?s)^const __mod = \{ exports: \{\} \};\s*\(new Function\('module', 'exports', (.+?)\)\)\(__mod, __mod\.exports\);\s*const _fn = __mod\.exports;`)
var nodeJSWrapperPattern = regexp.MustCompile(`(?s)^const __mod = \{ exports: \{\} \};\s*\(new Function\('module', 'exports', (?:'require', )?(.+?)\)\)\(__mod, __mod\.exports(?:, require)?\);\s*const _fn = __mod\.exports;`)
func decodeNodeJSWrapperSource(decoded []byte) (string, bool) {
text := string(decoded)
+5 -3
View File
@@ -23,10 +23,12 @@ func BuildJSDeployZip(code string) ([]byte, error) {
// main.js — CommonJS wrapper:
// 1. new Function создаёт функцию в пустом модульном контексте (нет import/export)
// 2. Передаём ей module и exports как параметры → пользовательский CJS код работает
// 3. Экспортируем main/handler/default через module.exports
// 2. Передаём ей module, exports и require как параметры → пользовательский CJS код работает
// 3. require передаётся явно, т.к. new Function выполняется в глобальном scope
// и не имеет доступа к module-local require из CJS контекста main.js
// 4. Экспортируем main/handler/default через module.exports
wrapper := fmt.Sprintf(`const __mod = { exports: {} };
(new Function('module', 'exports', %s))(__mod, __mod.exports);
(new Function('module', 'exports', 'require', %s))(__mod, __mod.exports, require);
const _fn = __mod.exports;
async function __invoke(ctx) {
+11 -9
View File
@@ -33,18 +33,20 @@ func TestBuildJSDeployZipExportsMainAndHandler(t *testing.T) {
files[file.Name] = string(content)
}
if files["package.json"] != `{"type":"module"}` {
t.Fatalf("package.json = %q, want ESM marker", files["package.json"])
}
mainJS := files["main.js"]
if !strings.Contains(mainJS, `export { __invoke as main, __invoke as handler };`) {
t.Fatalf("main.js does not export both main and handler: %s", mainJS)
if mainJS == "" {
t.Fatalf("main.js not found in zip, files: %v", files)
}
if !strings.Contains(mainJS, `export default __invoke;`) {
t.Fatalf("main.js does not export default invoke: %s", mainJS)
if !strings.Contains(mainJS, `new Function('module', 'exports', 'require',`) {
t.Fatalf("main.js does not pass require to new Function: %s", mainJS)
}
if !strings.Contains(mainJS, `__mod.exports, require)`) {
t.Fatalf("main.js does not forward require: %s", mainJS)
}
if !strings.Contains(mainJS, `module.exports = __invoke`) {
t.Fatalf("main.js does not export __invoke via module.exports: %s", mainJS)
}
if !strings.Contains(mainJS, `_fn.default || _fn.handler || _fn.main`) {
t.Fatalf("main.js lost user export resolution: %s", mainJS)
}
}
}
+2 -2
View File
@@ -103,7 +103,7 @@
<div class="nubes">NUBES</div>
<div class="product">FISSION CONSOLE</div>
</div>
<div style="font-size:0.65rem; color:var(--text-secondary); margin-left:10px; align-self:center; opacity:0.7;">v1.3.94</div>
<div style="font-size:0.65rem; color:var(--text-secondary); margin-left:10px; align-self:center; opacity:0.7;">v1.3.95</div>
</div>
<div class="row" style="margin:0;">
<button class="btn ghost" onclick="reloadAll()">Refresh</button>
@@ -626,7 +626,7 @@ psycopg2-binary" style="width:100%; box-sizing:border-box; font-family:monospace
</div>
<div class="actions" style="justify-content:space-between; align-items:center;">
<span style="font-size:0.75rem; color:var(--text-secondary);">v1.3.94</span>
<span style="font-size:0.75rem; color:var(--text-secondary);">v1.3.95</span>
<button class="btn ghost" onclick="closeHelp()">Закрыть</button>
</div>
</div>