Skip to content

trueforge-ui ChatFileDownload builds href by concatenating model-controlled artifact paths without URL-encoding #424

Closed

Description

@aniruddhaadak80

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:

  1. Malformed URLs / broken downloads — any path containing a space, #, ?, %, &, or non-ASCII characters produces an invalid or truncated URL. E.g. base https://host/api/v1/sessions/s/turns/t/download-sandbox-file?path= + model output my report(final).csv yields ...path=my report(final).csv — spaces and parens break the request outright in most clients; # silently truncates everything after it.
  2. Query/fragment injection — a path like x&next=1#frag injects additional parameters or discards the tail of the URL, changing what the gateway endpoint receives.
  3. 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/file silently rewrites the host when the base ends at the authority boundary (e.g. base configured as https: 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

  1. Render the SDK's Markdown with fileDownloadBaseUrl="https://host/download?path=".
  2. Feed assistant content containing:
```sandbox_artifacts
[Report](/tmp/my report#final,v2.csv)
```
  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions