The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 09:45 UTC
fix(client): validate signed asset URLs at the RPC boundary (#37812)
Julius Marminge committed
Nov 16, 2026 at 15:49 UTC
e65a790ac5599108d812116867372db3b2a671ea
2 files changed
+43
-2
packages/contracts/src/assets.ts
+8
-2
@@ -90,7 +90,10 @@ export const AssetImageDimensions = Schema.Struct({
90
export type AssetImageDimensions = typeof AssetImageDimensions.Type;
91
92
export const AssetCreateUrlResult = Schema.Struct({
93
- relativeUrl: TrimmedNonEmptyString.check(Schema.isMaxLength(4096)),
93
+ relativeUrl: TrimmedNonEmptyString.check(
94
+ Schema.isMaxLength(4096),
95
+ Schema.isPattern(/^\/api\/assets\/(?!\.{1,2}\/)[\w.-]+\/(?!(?:\.|%2[eE]){1,2}$)[^/\\?#\s]+$/u),
96
+ ),
97
expiresAt: Schema.Number,
98
sourcePath: Schema.optional(
99
TrimmedNonEmptyString.check(Schema.isMaxLength(ASSET_PATH_MAX_LENGTH)),
@@ -131,7 +134,10 @@ export type AttachmentCreateUploadUrlInput = typeof AttachmentCreateUploadUrlInp
134
135
export const AttachmentCreateUploadUrlResult = Schema.Struct({
136
attachmentId: TrimmedNonEmptyString.check(Schema.isMaxLength(256)),
134
- relativeUrl: TrimmedNonEmptyString.check(Schema.isMaxLength(4096)),
137
+ relativeUrl: TrimmedNonEmptyString.check(
138
+ Schema.isMaxLength(4096),
139
+ Schema.isPattern(/^\/api\/attachments\/upload\/(?!\.{1,2}$)[\w.-]+$/u),
140
+ ),
141
expiresAt: Schema.Number,
142
});
143
export type AttachmentCreateUploadUrlResult = typeof AttachmentCreateUploadUrlResult.Type;
packages/contracts/src/rpc.test.ts
+35
@@ -2,10 +2,45 @@ import { describe, expect, it } from "vite-plus/test";
2
import * as Exit from "effect/Exit";
3
import * as Schema from "effect/Schema";
4
5
+import { AssetCreateUrlResult, AttachmentCreateUploadUrlResult } from "./assets.ts";
6
import { ORCHESTRATION_V2_WS_METHODS } from "./orchestrationV2.ts";
7
import { WS_METHODS, WsRpcGroup } from "./rpc.ts";
8
9
describe("WebSocket RPC contracts", () => {
10
+ it("only accepts asset and upload URLs on their own server routes", () => {
11
+ const decodeAsset = Schema.decodeUnknownExit(AssetCreateUrlResult);
12
+ const decodeUpload = Schema.decodeUnknownExit(AttachmentCreateUploadUrlResult);
13
+ const expiresAt = 10_000;
14
+
15
+ expect(
16
+ Exit.isSuccess(
17
+ decodeAsset({ relativeUrl: "/api/assets/token.sig/my%20file.png", expiresAt }),
18
+ ),
19
+ ).toBe(true);
20
+ expect(
21
+ Exit.isSuccess(
22
+ decodeUpload({
23
+ relativeUrl: "/api/attachments/upload/token.sig",
24
+ expiresAt,
25
+ attachmentId: "attachment",
26
+ }),
27
+ ),
28
+ ).toBe(true);
29
+
30
+ for (const relativeUrl of [
31
+ "data:text/plain,hello",
32
+ "file:///tmp/document",
33
+ "https://other.example/document",
34
+ "//other.example/document",
35
+ "/api/assets/token/../../../other",
36
+ ]) {
37
+ expect(Exit.isFailure(decodeAsset({ relativeUrl, expiresAt }))).toBe(true);
38
+ expect(
39
+ Exit.isFailure(decodeUpload({ relativeUrl, expiresAt, attachmentId: "attachment" })),
40
+ ).toBe(true);
41
+ }
42
+ });
43
+
44
it("rejects server-internal commands sent to dispatchCommand", () => {
45
const dispatchCommand = WsRpcGroup.requests.get(ORCHESTRATION_V2_WS_METHODS.dispatchCommand);
46
if (dispatchCommand === undefined) throw new Error("dispatchCommand is not registered");