mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-27 11:32:12 +00:00
- Add host-rendered native IDE primitives (PluginCodeEditor/Monaco, PluginDataGrid/@tanstack/react-virtual, PluginSplitPane, PluginErCanvas) with Shadow DOM slot projection (zero iframes, zero plugin JS in renderer) - Expand Remote DOM budgets, expose full 22 Netcatty semantic CSS tokens, add dblclick/contextmenu/scroll/selection events, cursor-anchored PluginPopover, database theme icon, and full-bleed chrome flag - Add dynamic user-approved TCP/TLS byte streams (incl. localhost opt-in blocking internal control ports), in-band STARTTLS upgrade with cert fingerprint confirmation, durable revocable Vault SSH host bindings, plugin-owned encrypted secrets, native ui.openFile/saveFile streaming handles, 4 MiB clipboard, and prefix-filtered storage.keys - Optimize plugin view image pipeline with pooled sandboxed rasterizer window (auto-destroyed on idle/error/dispose), LRU version+hash cache in PluginViewResources, transient failure eviction in HostDrawnViewHost, renderer-side session deduplication, and RemoteImageElement cache + retry - Temporarily enable plugin host by default in hostBootstrap.cjs (marked TODO(revert), opt-out via NETCATTY_PLUGIN_DEV=0)
62 lines
4.4 KiB
JavaScript
62 lines
4.4 KiB
JavaScript
"use strict";
|
|
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const { validatePluginRemoteTree, validatePluginMutationBatch } = require("./pluginRemoteTreePolicy.cjs");
|
|
const text = (id, data) => ({ id, type: 3, data });
|
|
const element = (id, name, attributes = {}, children = []) => ({ id, type: 1, element: name, attributes, children });
|
|
|
|
test("normal HTML layout and styles can be represented without executable code", () => {
|
|
const root = { children: [element("1", "section", { class: "card", style: "display:grid;grid-template-columns:1fr 2fr;gap:12px" }, [element("2", "h1", {}, [text("3", "Hello")]), element("4", "button", { type: "button" }, [text("5", "Click")])])] };
|
|
assert.equal(validatePluginRemoteTree(root), true);
|
|
assert.equal(validatePluginMutationBatch([[0, "~", root.children[0], 0], [3, "1", "class", "ready"], [2, "3", "Updated"]]), true);
|
|
});
|
|
|
|
test("untrusted content cannot introduce executable elements, URLs or dangerous properties", () => {
|
|
const attacks = [
|
|
element("1", "script"), element("1", "iframe"), element("1", "img", { src: "https://example.invalid" }),
|
|
element("1", "a", { href: "javascript:alert(1)" }), element("1", "div", { onclick: "alert(1)" }),
|
|
element("1", "input", { type: "file" }), element("1", "div", { style: "background:url(https://example.invalid)" }),
|
|
element("1", "div", { style: "color:red;} body{color:red" }),
|
|
element("1", "div", { __proto__: "bad" }, [text("1", "duplicate")]),
|
|
{ id: "1", type: 1, element: "div", attributes: {}, properties: { innerHTML: "bad" }, children: [] },
|
|
];
|
|
for (const attack of attacks) assert.throws(() => validatePluginRemoteTree({ children: [attack] }), undefined, JSON.stringify(attack));
|
|
assert.throws(() => validatePluginMutationBatch([[3, "1", "innerHTML", "<script>evil()</script>"]]));
|
|
assert.throws(() => validatePluginMutationBatch([[3, "1", "__proto__", {}]]));
|
|
assert.throws(() => validatePluginMutationBatch([[3, "1", "onclick", "evil()", 2]]));
|
|
assert.throws(() => validatePluginMutationBatch([[3, "1", "class", "x", 3]]));
|
|
});
|
|
|
|
test("remote trees and mutation batches are bounded", () => {
|
|
assert.throws(() => validatePluginRemoteTree({ children: Array.from({ length: 4097 }, (_, i) => text(`${i}`, "x")) }));
|
|
let node = text("33", "x"); for (let i = 32; i >= 0; i--) node = element(`${i}`, "div", {}, [node]);
|
|
assert.throws(() => validatePluginRemoteTree({ children: [node] }));
|
|
assert.throws(() => validatePluginMutationBatch(Array.from({ length: 4097 }, () => [2, "1", "x"])));
|
|
assert.throws(() => validatePluginMutationBatch([[2, "1", "x".repeat(131073)]]));
|
|
assert.equal(validatePluginMutationBatch([[2, "1", "x".repeat(131072)]]), true);
|
|
});
|
|
|
|
test("declarative plugin widget markers and JSON props are strictly validated", () => {
|
|
const validWidget = element("w1", "div", {
|
|
"data-plugin-widget": "code-editor",
|
|
"data-plugin-widget-props": JSON.stringify({ value: "SELECT 1;", language: "sql" }),
|
|
});
|
|
assert.equal(validatePluginRemoteTree({ children: [validWidget] }), true);
|
|
assert.throws(() => validatePluginRemoteTree({ children: [element("w2", "div", { "data-plugin-widget": "iframe-hack" })] }), /widget/);
|
|
assert.throws(() => validatePluginRemoteTree({ children: [element("w3", "div", { "data-plugin-widget": "data-grid", "data-plugin-widget-props": "{bad json" })] }), /JSON/);
|
|
assert.throws(() => validatePluginRemoteTree({ children: [element("w4", "div", { "data-plugin-widget": "data-grid", "data-plugin-widget-props": "[]" })] }), /JSON object/);
|
|
assert.throws(() => validatePluginRemoteTree({ children: [element("w5", "div", { "data-plugin-widget": "data-grid", "data-plugin-widget-props": "{\"__proto__\":{\"polluted\":true}}" })] }), /Forbidden key/);
|
|
});
|
|
|
|
test("void children are rejected in snapshots and mutation insertions", () => {
|
|
for (const name of ["br", "hr", "img", "input"]) {
|
|
const node = element("void", name);
|
|
assert.equal(validatePluginRemoteTree({ children: [node] }), true);
|
|
node.children.push(text("child", "invalid"));
|
|
assert.throws(() => validatePluginRemoteTree({ children: [node] }), /Void view elements/);
|
|
assert.throws(() => validatePluginMutationBatch([[0, "~", node, 0]]), /Void view elements/);
|
|
}
|
|
assert.throws(() => validatePluginRemoteTree({ children: [element("a", "textarea", {}, [element("b", "div")])] }), /Textarea/);
|
|
assert.equal(validatePluginRemoteTree({ children: [element("a", "textarea", {}, [text("b", "Hello"), text("c", " world")])] }), true);
|
|
});
|