The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Data from "effect/Data"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | |
| 4 | export class BundlePathsInvalidProps extends Data.TaggedError("BundlePathsInvalidProps")<{ |
| 5 | readonly message: string; |
| 6 | readonly cause?: unknown; |
| 7 | }> {} |
| 8 | |
| 9 | /** Validate an untrusted bundler output path before writing it to disk. */ |
| 10 | export const normalizeBundleFilePath = (input: string) => |
| 11 | Effect.gen(function* () { |
| 12 | const normalized = input.replaceAll("\\", "/"); |
| 13 | if (normalized.length === 0 || normalized.startsWith("/") || /^[a-zA-Z]:\//.test(normalized)) { |
| 14 | return yield* new BundlePathsInvalidProps({ |
| 15 | message: `Invalid Compute bundle output path: ${input}`, |
| 16 | }); |
| 17 | } |
| 18 | const segments = normalized.split("/"); |
| 19 | if (segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) { |
| 20 | return yield* new BundlePathsInvalidProps({ |
| 21 | message: `Invalid Compute bundle output path: ${input}`, |
| 22 | }); |
| 23 | } |
| 24 | return segments.join("/"); |
| 25 | }); |