Skip to content

fix(jawn): close cross-tenant IDOR in prompt version forking - #5825

Closed
lokeshramchand-ctrl wants to merge 2 commits into
Helicone:mainfrom
lokeshramchand-ctrl:fix/prompt-version-fork-org-scope
Closed

lokeshramchand-ctrl wants to merge 2 commits into
Helicone:mainfrom
lokeshramchand-ctrl:fix/prompt-version-fork-org-scope

Conversation

@lokeshramchand-ctrl

Copy link
Copy Markdown

Fixes #5824

Summary

PromptManager.createNewPromptVersion (used by POST /v1/prompt/version/{promptVersionId}/subversion and .../subversion-from-ui) forks a prompt version by id with no organization filter:

WITH parent_prompt_version AS (
  SELECT * FROM prompts_versions WHERE id = $1
), ...

promptVersionId comes directly from the URL path (promptController.ts), and nothing upstream checks that it belongs to the caller's org.

Impact

The new row is inserted with organization = <caller's own org> but prompt_v2 = <victim's real prompt id> (copied straight from the unscoped parent). Every read path that serves production prompt content authorizes on prompt_v2.organization, never on prompts_versions.organization:

  • getCompiledPromptVersions — backs POST /v1/prompt/{name}/compile, the endpoint customers call at request time to fetch their production prompt template.
  • getPormptVersionsTemplates — same pattern, backs .../template.

Both do:

FROM prompts_versions
left join prompt_v2 on prompt_v2.id = prompts_versions.prompt_v2
WHERE prompt_v2.organization = $1
  AND (prompts_versions.metadata->>'isProduction')::boolean = true

Since prompt_v2.organization is the victim's org (the real owner of the prompt), a forged row with the victim's prompt_v2 id passes this check regardless of who's in prompts_versions.organization.

Combined with promotePromptVersionToProduction, which only checks prompts_versions.organization = caller (trivially true — the attacker owns the row they just inserted), the full chain is:

  1. Attacker obtains a prompts_versions id belonging to another org (e.g. leaked via logs, a shared link, support thread).
  2. Attacker calls POST /v1/prompt/version/{victimVersionId}/subversion with an arbitrary newHeliconeTemplate. This inserts a version owned by the attacker's org but linked to the victim's prompt_v2.
  3. Attacker calls POST /v1/prompt/version/{forgedId}/promote. Passes, because the forged row's organization is the attacker's own.
  4. The victim org's own next call to /v1/prompt/{name}/compile (which they'd make to fetch their production prompt for a real LLM request) can return the attacker's forged template instead of their own, since the query never checks who authored the version row — only that it points at the victim's prompt_v2 and is flagged production.

This is a cross-tenant write into another tenant's live prompt template — not just a data-exposure read — with follow-on impact on whatever the victim's production LLM traffic does with that prompt.

Fix

Scope both the parent-version and bump-version CTEs to organization = $4 (the caller's own org, already a bound parameter in this query), matching every other method in PromptManager.ts. An out-of-org promptVersionId now resolves to zero rows, the INSERT inserts nothing, and the manager returns an explicit error instead of silently mapping undefined through resultMap.

Testing

  • Manual code review tracing every read/write path that touches prompts_versions.organization vs prompt_v2.organization in PromptManager.ts to confirm this is the only method with the gap.
  • Verified the new error-handling branch type-checks against the existing Result<PromptVersionResult, string> return type and mirrors the ok/err pattern already used elsewhere in this file.
  • Was not able to run the full yarn test:jawn / tsc --noEmit workspace build in my environment; would appreciate CI running the full suite on this PR.

createNewPromptVersion resolved the parent version via
`SELECT * FROM prompts_versions WHERE id = $1` with no organization
filter, and used the same unscoped predicate for the optional
major-version bump lookup. The controller (promptController.ts,
POST /v1/prompt/version/{promptVersionId}/subversion[-from-ui]) passes
promptVersionId straight from the URL path with no ownership check, so
any authenticated caller could name another organization's
prompts_versions id.

The forged row is inserted with organization = the caller's own org,
but prompt_v2 = the victim's real prompt_v2 id (copied from
ppv.prompt_v2). Every read path that serves compiled/production prompt
content authorizes via prompt_v2.organization, not
prompts_versions.organization:

  getCompiledPromptVersions (POST /v1/prompt/{name}/compile) and
  getPormptVersionsTemplates both join
  `prompt_v2 on prompt_v2.id = prompts_versions.prompt_v2` and filter
  `WHERE prompt_v2.organization = $1`, with no check on
  prompts_versions.organization at all.

So the forged row is indistinguishable from a legitimate version of
the victim's prompt once it is marked production. And
promotePromptVersionToProduction only checks
`prompts_versions.organization = caller`, which the attacker satisfies
trivially since they own the row they just inserted. Net effect: an
attacker who obtains any org's prompt version id can fork it with an
arbitrary attacker-controlled template, promote their own fork to
production, and have it served back to the victim org as their live
production prompt on their next /compile call - a cross-tenant write
into another tenant's LLM request path, not just a read.

Scope both CTEs to organization = $4 (the caller's own org), matching
the pattern already used by every sibling method in this file
(editPromptVersionTemplate, promotePromptVersionToProduction,
editPromptVersionLabel, etc). Also stop mapping an empty RETURNING set
through resultMap, which silently produced {data: undefined, error:
null} - return an explicit error instead so a blocked fork attempt is
unambiguous.

No behavior change for legitimate same-org forks.

Fixes Helicone#5824

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@vercel

vercel Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated
helicone Skipped Skipped Oct 20, 2026 9:30am UTC
helicone-bifrost Skipped Skipped Oct 20, 2026 9:30am UTC
helicone-eu Skipped Skipped Oct 20, 2026 9:30am UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – helicone-eu September 27, 2026 20:13 Inactive
@vercel
vercel Bot temporarily deployed to Preview – helicone-bifrost September 27, 2026 20:13 Inactive
@vercel
vercel Bot temporarily deployed to Preview – helicone September 27, 2026 20:13 Inactive
@lokeshramchand-ctrl

Copy link
Copy Markdown
Author

@chitalian Flagging for priority review — #5825 fixes a cross-tenant write into another org's production prompt (same bug class as CIRT-77/81/82), reported in #5824. Would appreciate a quick look given the severity.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cursor

cursor Bot commented Oct 20, 2026

Copy link
Copy Markdown

Bugbot is paused — your team has an unpaid invoice

Bugbot is paused because your team has an unpaid invoice.

Pay it from the billing page in the Cursor dashboard and Bugbot resumes automatically.

(requestId: f60d6fde-90ec-448b-8d35-091263cf78e3)

@vercel
vercel Bot temporarily deployed to Preview – helicone-bifrost October 20, 2026 09:30 Inactive
@vercel
vercel Bot temporarily deployed to Preview – helicone-eu October 20, 2026 09:30 Inactive
@vercel
vercel Bot temporarily deployed to Preview – helicone October 20, 2026 09:30 Inactive
@lokeshramchand-ctrl

Copy link
Copy Markdown
Author

Closing: the org-scoping fix in this PR was already applied upstream in #5842 (63879c1), which scopes both CTEs to organization = $4. After merging main, the only remaining difference is an error message wording change, which isn't worth a separate PR. Fixes #5824 (also closed).

@lokeshramchand-ctrl
lokeshramchand-ctrl deleted the fix/prompt-version-fork-org-scope branch October 20, 2026 09:40

This branch was previously deployed

3 inactive deployments
Preview – helicone-eu — a86c3a83 Deployed Oct 20, 2026 by vercel[bot]
Preview – helicone — a86c3a83 Deployed Oct 20, 2026 by vercel[bot]
Preview – helicone-bifrost — a86c3a83 Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cross-tenant prompt injection via missing org filter when forking a prompt version

1 participant