Repository navigation
Description
What happened?
@truefoundry/trueforge-ui's file-download link builds its href by raw string concatenation with a model-controlled path and no URL encoding:
// packages/trueforge-ui/src/atoms/ChatFileDownload.tsx (main @ 506bf5c)
const href = fileDownloadBaseUrl ? `${fileDownloadBaseUrl}${path}` : undefined;The path originates from the model's sandbox_artifacts fence (parseSandboxArtifacts extracts it from [label](path) links emitted by the agent — see packages/trueforge-ui/src/atoms/SandboxArtifactDownload.tsx), so it is arbitrary attacker/model-influenced text flowing into an <a href> in every host application that supplies fileDownloadBaseUrl.
Concrete failure modes:
- Malformed URLs / broken downloads — any path containing a space,
#,?,%,&, or non-ASCII characters produces an invalid or truncated URL. E.g. basehttps://host/api/v1/sessions/s/turns/t/download-sandbox-file?path=+ model outputmy report(final).csvyields...path=my report(final).csv— spaces and parens break the request outright in most clients;#silently truncates everything after it. - Query/fragment injection — a path like
x&next=1#fraginjects additional parameters or discards the tail of the URL, changing what the gateway endpoint receives. - No normalization of scheme-like values — while the concatenation prevents a full open redirect today (the base prefix always leads), a path such as
//cdn.example.com/filesilently rewrites the host when the base ends at the authority boundary (e.g. base configured ashttps:or an empty-path origin variable), which hosts cannot reasonably anticipate.
The server-side counterpart validates and percent-decodes path properly (validateSandboxFilePath + zod query parsing), so only this client-side construction bypasses good practice.
Steps to reproduce
- Render the SDK's
MarkdownwithfileDownloadBaseUrl="https://host/download?path=". - Feed assistant content containing:
```sandbox_artifacts
[Report](/tmp/my report#final,v2.csv)
```
- The rendered anchor resolves to
https://host/download?path=/tmp/my report— everything after the space/# is dropped or misparsed; the download 404s or fetches the wrong path.
Expected behavior
Encode the path component explicitly and keep the base/baseURL join well-defined, e.g.:
const href = fileDownloadBaseUrl ? `${fileDownloadBaseUrl}${encodeURIComponent(path)}` : undefined;(or construct with new URL(path, base) plus an explicit allowlist that path stays a sandbox-relative path), with a test added next to the existing test/atoms/ChatFileDownload.test.tsx cases covering spaces, #, &, %, and unicode names.
How are you running TrueForge?
As a library (@truefoundry/trueforge-core)
Version
main @ 506bf5c
Environment
OS: any
Node.js version: n/a (browser UI)
Browser (if UI-related): any
Activity