Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -53,6 +53,13 @@ describe("PluginSettingsFrame", () => {
expect(PLUGIN_SETTINGS_FRAME_DEFAULT_ERROR_MESSAGES).toEqual(en.settings.plugins.settings.frameErrors);
});
it("never falls back to predictable randomness for channel or nonce generation", () => {
const source = readRepoFile("apps/web/app/modules/plugins/components/PluginSettingsFrame.tsx");
expect(source).not.toContain("Math.random");
expect(source).toContain("Secure randomness is required for the plugin settings frame channel.");
expect(source).toContain("Secure randomness is required for the plugin settings frame nonce.");
});
it("renders a sandboxed opaque-origin iframe with an embedded CSP", () => {
render(<PluginSettingsFrame pluginId="com.acme.settings" title="Acme settings" trustedHtml="<main><h1>Settings</h1></main>" />);
@@ -510,19 +510,19 @@ function assertSafePluginSettingsFrameScriptNonce(scriptNonce: string): void {
}
function createPluginSettingsFrameChannelId() {
const bytes = new Uint8Array(16);
globalThis.crypto?.getRandomValues?.(bytes);
if (bytes.some((byte) => byte !== 0)) {
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
if (!globalThis.crypto?.getRandomValues) {
throw new Error("Secure randomness is required for the plugin settings frame channel.");
}
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
const bytes = new Uint8Array(16);
globalThis.crypto.getRandomValues(bytes);
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
}
function createPluginSettingsFrameScriptNonce() {
const bytes = new Uint8Array(16);
globalThis.crypto?.getRandomValues?.(bytes);
if (bytes.some((byte) => byte !== 0)) {
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
if (!globalThis.crypto?.getRandomValues) {
throw new Error("Secure randomness is required for the plugin settings frame nonce.");
}
return createPluginSettingsFrameChannelId();
const bytes = new Uint8Array(16);
globalThis.crypto.getRandomValues(bytes);
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
}
@@ -148,13 +148,21 @@ describe("PluginSettingsService", () => {
});
});
test("rejects symlink traversal out of the plugin bundle", async () => {
test("rejects symlink traversal out of the plugin bundle", async ({ skip }) => {
const root = await mkdtemp(path.join(os.tmpdir(), "plugin-settings-"));
const outside = path.join(root, "outside.html");
const bundleRoot = path.join(root, "com.acme.settings", "1.0.0", "ui");
await mkdir(bundleRoot, { recursive: true });
await writeFile(outside, "<main>Outside</main>");
await symlink(outside, path.join(bundleRoot, "settings.html"));
try {
await symlink(outside, path.join(bundleRoot, "settings.html"));
} catch (error) {
if (process.platform === "win32" && error && typeof error === "object" && "code" in error && error.code === "EPERM") {
skip("Windows symlink creation requires Developer Mode; Linux CI covers the traversal guard.");
return;
}
throw error;
}
process.env.PLUGIN_BINARY_BASE_PATH = root;
getPluginForTenantMock.mockResolvedValue(pluginFixture());
@@ -106,10 +106,11 @@ describe("emitPluginHookFireAndForget", () => {
{
hookName: "workflow.failed",
tenantId: "tenant_1",
error: "outbox unavailable",
errorName: "Error",
},
"plugin.hook.emit_failed"
);
expect(JSON.stringify(mocks.loggerError.mock.calls)).not.toContain("outbox unavailable");
});
it("publishes a plugin hook outbox event inside its one-shot transaction", async () => {
@@ -147,7 +148,14 @@ describe("emitPluginHookFireAndForget", () => {
});
it("records hook validation failures in logs without failing the caller", async () => {
const issues = [{ path: ["workflowId"], message: "Required" }];
const issues = [
{
code: "invalid_type",
path: ["workflowId"],
message: "Required: SECRET_API_KEY",
received: "owner@example.test",
},
];
mocks.emitPluginHook.mockRejectedValueOnce(new TestPluginHookValidationError("workflow.failed", issues));
await expect(
@@ -159,10 +167,13 @@ describe("emitPluginHookFireAndForget", () => {
{
hookName: "workflow.failed",
tenantId: "tenant_1",
issues,
issueCount: 1,
issues: [{ code: "invalid_type", path: ["workflowId"] }],
},
"plugin.hook.payload_invalid"
);
expect(JSON.stringify(mocks.loggerWarn.mock.calls)).not.toContain("SECRET_API_KEY");
expect(JSON.stringify(mocks.loggerWarn.mock.calls)).not.toContain("owner@example.test");
});
it("records transaction failures in logs without failing the caller", async () => {
@@ -190,9 +201,10 @@ describe("emitPluginHookFireAndForget", () => {
{
hookName: "user.created",
tenantId: "tenant_1",
error: "db down",
errorName: "Error",
},
"plugin.hook.emit_failed"
);
expect(JSON.stringify(mocks.loggerError.mock.calls)).not.toContain("db down");
});
});
@@ -18,18 +18,29 @@
*/
import { db } from "~/utils/db.server";
import {
publishOutboxEvent,
type OutboxPublisherTransaction,
} from "@hivegrid/db/outbox";
import {
emitPluginHook,
PluginHookValidationError,
type PluginHookDefinition,
} from "@hivegrid/plugin-runtime";
import { publishOutboxEvent, type OutboxPublisherTransaction } from "@hivegrid/db/outbox";
import { emitPluginHook, PluginHookValidationError, type PluginHookDefinition } from "@hivegrid/plugin-runtime";
import { createScopedLogger } from "~/utils/logger.server";
import { toSafeErrorLog } from "~/utils/safeErrorLog.server";
const pluginHookLogger = createScopedLogger("plugin-hook-publisher");
const SAFE_ISSUE_PATH_SEGMENT = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/u;
function summarizeValidationIssues(issues: readonly unknown[]) {
return issues.slice(0, 20).map((issue) => {
const candidate = issue && typeof issue === "object" ? (issue as { code?: unknown; path?: unknown }) : null;
const path = Array.isArray(candidate?.path)
? candidate.path.slice(0, 8).map((segment) => {
if (typeof segment === "number" && Number.isSafeInteger(segment)) return segment;
return typeof segment === "string" && SAFE_ISSUE_PATH_SEGMENT.test(segment) ? segment : "<redacted>";
})
: [];
return {
code: typeof candidate?.code === "string" && SAFE_ISSUE_PATH_SEGMENT.test(candidate.code) ? candidate.code : "unknown",
path,
};
});
}
/**
* Emit a plugin hook outside an existing transaction. Use this for the
@@ -68,7 +79,8 @@ export async function emitPluginHookFireAndForget<TPayload>(
{
hookName: def.name,
tenantId: options.tenantId ?? null,
issues: error.issues,
issueCount: error.issues.length,
issues: summarizeValidationIssues(error.issues),
},
"plugin.hook.payload_invalid"
);
@@ -78,7 +90,7 @@ export async function emitPluginHookFireAndForget<TPayload>(
{
hookName: def.name,
tenantId: options.tenantId ?? null,
error: error instanceof Error ? error.message : String(error),
...toSafeErrorLog(error),
},
"plugin.hook.emit_failed"
);