Skip to content

Commit cc34f24

Browse files
fix(plugins): reject ambiguous filenames and repair stack compatibility
Refuse invalid UTF-8 names before directory lookups so raw Linux names cannot alias valid replacement-character paths during consent digesting. Carry the verified web/mobile compatibility repair from adjacent stack layers and format the catalogue.
1 parent d5c6b3b commit cc34f24

19 files changed

Lines changed: 276 additions & 212 deletions

‎apps/mobile/src/features/threads/ThreadContributionStatusStrip.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
import { useMemo } from "react";
99
import { Alert, Platform, Pressable, ScrollView, View } from "react-native";
1010

11-
import { AppText as Text } from "../../components/AppText";
11+
import { AppText as Text } from "../../components/ui/AppText";
1212
import { ProviderIcon } from "../../components/ProviderIcon";
1313
import { cn } from "../../lib/cn";
1414
import { contributionStatusEnvironment } from "../../state/contribution-status";

‎apps/server/src/plugins/PluginCatalog.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ export const make = Effect.fn("PluginCatalog.make")(function* (
413413
`${directory} is already installed.`,
414414
existing.record.installationId,
415415
);
416-
const installationId = PluginInstallationId.make(yield* crypto.randomUUIDv4().pipe(Effect.orDie));
416+
const installationId = PluginInstallationId.make(
417+
yield* crypto.randomUUIDv4().pipe(Effect.orDie),
418+
);
417419
const at = yield* now;
418420
const record: PluginInstallationRecord = {
419421
installationId,

‎apps/server/src/plugins/pluginSource.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
// @effect-diagnostics nodeBuiltinImport:off -- Raw filename bytes are not supported by Effect FileSystem paths.
2+
import * as NodeFSP from "node:fs/promises";
3+
14
import * as NodeServices from "@effect/platform-node/NodeServices";
5+
import * as HostProcess from "@t3tools/shared/HostProcess";
26
import { describe, expect, it } from "@effect/vitest";
37
import * as Effect from "effect/Effect";
48
import * as FileSystem from "effect/FileSystem";
@@ -43,6 +47,36 @@ it.layer(NodeServices.layer)("digestPluginSource", (it) => {
4347
}),
4448
);
4549

50+
it.effect("covers valid filenames containing the Unicode replacement character", () =>
51+
Effect.gen(function* () {
52+
const fs = yield* FileSystem.FileSystem;
53+
const path = yield* Path.Path;
54+
const directory = yield* makeTree({ "a�.js": "A" });
55+
const first = yield* digestPluginSource(directory);
56+
yield* fs.writeFileString(path.join(directory, "a�.js"), "B");
57+
expect((yield* digestPluginSource(directory)).digest).not.toBe(first.digest);
58+
}),
59+
);
60+
61+
it.effect.each(["file", "directory"] as const)(
62+
"refuses invalid UTF-8 %s names",
63+
(kind, context) =>
64+
Effect.gen(function* () {
65+
const platform = yield* HostProcess.Platform;
66+
if (platform !== "linux") context.skip();
67+
const directory = yield* makeTree({ "a�.js": "B" });
68+
const raw = Buffer.concat([
69+
Buffer.from(`${directory}/`),
70+
Buffer.from([0x61, 0xff, 0x2e, 0x6a, 0x73]),
71+
]);
72+
yield* Effect.tryPromise(() =>
73+
kind === "file" ? NodeFSP.writeFile(raw, "A") : NodeFSP.mkdir(raw),
74+
);
75+
const error = yield* digestPluginSource(directory).pipe(Effect.flip);
76+
expect(error.reason).toBe("a filename is not valid UTF-8.");
77+
}),
78+
);
79+
4680
it.effect("covers hidden paths, which an entry or import may use", () =>
4781
Effect.gen(function* () {
4882
const fs = yield* FileSystem.FileSystem;

‎apps/server/src/plugins/pluginSource.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ const walk = async (
6464
const files: Array<string> = [];
6565
let declaredBytes = 0;
6666
const visit = async (relative: string) => {
67-
const entries = await NodeFSP.readdir(NodePath.join(root, relative), { withFileTypes: true });
67+
const entries = await NodeFSP.readdir(NodePath.join(root, relative), {
68+
withFileTypes: true,
69+
encoding: "buffer",
70+
});
6871
for (const entry of entries) {
6972
if (signal.aborted) throw new Refusal("the inspection was cancelled.");
70-
const child = relative === "" ? entry.name : `${relative}/${entry.name}`;
73+
const name = entry.name.toString("utf8");
74+
if (!Buffer.from(name, "utf8").equals(entry.name))
75+
throw new Refusal("a filename is not valid UTF-8.");
76+
const child = relative === "" ? name : `${relative}/${name}`;
7177
if (entry.isSymbolicLink()) throw new Refusal(`${child} is a symbolic link.`);
7278
if (entry.isDirectory()) {
7379
await visit(child);

apps/web/src/components/RightPanelTabs.browserProfile.test.tsx renamed to apps/web/src/components/RightPanelTabs.browserProfile.browser.test.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// @vitest-environment jsdom
2-
31
import {
42
BUILT_IN_BROWSER_PROFILES,
53
DEFAULT_BROWSER_PROFILE_ID,
64
INCOGNITO_BROWSER_PROFILE_ID,
75
} from "@t3tools/contracts";
86
import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
97
import { act } from "react";
8+
import { userEvent } from "vite-plus/test/browser";
109
import { createRoot, type Root } from "react-dom/client";
1110
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
1211

@@ -24,7 +23,7 @@ let opened: string[];
2423

2524
beforeEach(() => {
2625
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
27-
// Browser is desktop-only; the launcher offers it once the preview bridge exists.
26+
// Expose the preview bridge so the launcher offers Browser.
2827
vi.stubGlobal("desktopBridge", { preview: {} });
2928
vi.stubGlobal(
3029
"ResizeObserver",
@@ -34,8 +33,6 @@ beforeEach(() => {
3433
disconnect() {}
3534
},
3635
);
37-
// jsdom lacks the Web Animations API that the tab bar's scroll area waits on.
38-
Element.prototype.getAnimations ??= () => [];
3936
opened = [];
4037
container = document.createElement("div");
4138
document.body.append(container);
@@ -115,11 +112,7 @@ function menuItem(label: string): HTMLElement {
115112

116113
async function click(element: Element) {
117114
await act(async () => {
118-
element.dispatchEvent(new MouseEvent("pointerdown", { bubbles: true }));
119-
element.dispatchEvent(new MouseEvent("mousedown", { bubbles: true }));
120-
element.dispatchEvent(new MouseEvent("pointerup", { bubbles: true }));
121-
element.dispatchEvent(new MouseEvent("mouseup", { bubbles: true }));
122-
element.dispatchEvent(new MouseEvent("click", { bubbles: true }));
115+
await userEvent.click(element);
123116
});
124117
}
125118

apps/web/src/components/RightPanelTabs.terminal.test.tsx renamed to apps/web/src/components/RightPanelTabs.terminal.browser.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @vitest-environment jsdom
2-
31
import { EnvironmentId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
42
import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
53
import { act } from "react";
@@ -28,8 +26,6 @@ beforeEach(() => {
2826
disconnect() {}
2927
},
3028
);
31-
// jsdom lacks the Web Animations API that the tab bar's scroll area waits on.
32-
Element.prototype.getAnimations ??= () => [];
3329
useRightPanelStore.setState({ byThreadKey: {} });
3430
container = document.createElement("div");
3531
document.body.append(container);

apps/web/src/components/chat/ThreadContributionStatus.test.tsx renamed to apps/web/src/components/chat/ThreadContributionStatus.browser.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @vitest-environment jsdom
2-
31
import {
42
type ContributionStatusEntry,
53
EnvironmentId,

‎apps/web/src/components/chat/ThreadContributionStatus.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ContributionStatusTone, EnvironmentId, ThreadId } from "@t3tools/contracts";
2-
import { memo, useMemo } from "react";
2+
import { memo } from "react";
33

44
import { useThreadContributionStatus } from "../../state/contributionStatus";
55
import { Badge } from "../ui/badge";
@@ -100,7 +100,7 @@ export const ThreadContributionStatus = memo(function ThreadContributionStatus(p
100100
threadId: ThreadId;
101101
}) {
102102
const entries = useThreadContributionStatus(props.environmentId, props.threadId);
103-
const chips = useMemo(() => contributionStatusChips(entries), [entries]);
103+
const chips = contributionStatusChips(entries);
104104
if (chips.length === 0) return null;
105105
return <ContributionStatusChips chips={chips} />;
106106
});

apps/web/src/panels/bundledPanels.test.tsx renamed to apps/web/src/panels/bundledPanels.browser.test.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EnvironmentId, ProjectId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
22
import { act, Suspense } from "react";
3-
import { create } from "react-test-renderer";
4-
import { describe, expect, it, vi } from "vite-plus/test";
3+
import { createRoot, type Root } from "react-dom/client";
4+
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
55

66
const loaded = vi.hoisted(() => ({
77
diff: 0,
@@ -65,6 +65,20 @@ const host: PanelHost = {
6565
sendAnnotation: () => undefined,
6666
};
6767

68+
let root: Root;
69+
let container: HTMLDivElement;
70+
beforeEach(() => {
71+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
72+
container = document.createElement("div");
73+
document.body.append(container);
74+
root = createRoot(container);
75+
});
76+
afterEach(async () => {
77+
await act(() => root.unmount());
78+
container.remove();
79+
vi.unstubAllGlobals();
80+
});
81+
6882
describe("bundled side panels", () => {
6983
it("loads only the selected panel body and lends it the host", async () => {
7084
expect(loaded).toMatchObject({
@@ -77,7 +91,7 @@ describe("bundled side panels", () => {
7791
files: 0,
7892
});
7993
await act(async () => {
80-
create(
94+
root.render(
8195
<PanelHostContext value={host}>
8296
<Suspense fallback={null}>
8397
<RegisteredSidePanel id="preview" tabId="tab-1" />
@@ -106,7 +120,7 @@ describe("bundled side panels", () => {
106120
activeTerminalId: "term-1",
107121
};
108122
await act(async () => {
109-
create(
123+
root.render(
110124
<PanelHostContext value={host}>
111125
<Suspense fallback={null}>
112126
<RegisteredSidePanel

0 commit comments

Comments
 (0)