fix(ui): open and link only http(s) or same-origin URLs from user and agent content (#22639)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The board UI shows content that agents and people write: comments,
tool results, work products, approval cards and runtime links
> - Some of this content becomes a link, an image or a new window
> - Some of these places did not limit the URL scheme, and the chat
image click opened the URL without `noopener`
> - A URL with a script scheme must never open or navigate from the
board, because it would run with the board origin
> - This pull request adds one URL helper and routes the content-fed
link, image-click and window sinks through it
> - The benefit is that only http(s) or same-origin URLs can open from
user or agent content, and new windows never get an opener

## Linked Issues or Issue Description

**What happened?**
The issue-reference parser accepted a URL with any scheme when its path
contained an issue path. The markdown renderer trusted that match and
kept the URL. The chat image click then gave the URL to `window.open`
with no scheme check and no `noopener`. Several other components had
their own copies of a scheme check, and some links used content URLs
with no check.

**What did you expect?**
The board opens or links only http(s) URLs and same-origin paths from
user or agent content. New windows open with `noopener,noreferrer`.

**Steps to reproduce**
Render markdown with an image whose URL uses a non-http scheme and an
issue path, then click the image. The new unit tests cover this case.

**Impact**
Defense-in-depth hardening of the board UI against unsafe URLs in stored
content.

## What Changed

- Add `ui/src/lib/safe-url.ts` with `safeNavigableUrl` (http(s) or
same-origin), `safeExternalHttpUrl` (absolute http(s) only) and
`openSafeUrl` (opens with `noopener,noreferrer`).
- `parseIssueReferenceHref` in `packages/shared` now accepts only
relative paths and http(s) URLs.
- `MarkdownBody` keeps the issue-reference shortcut only for safe URLs.
The image click handler gets only a safe URL.
- The task chat image click, the work products panel and MCP app links
open through `openSafeUrl`.
- The plugin bridge does a top-level navigation only to an http(s) URL.
- Replace the local scheme checks in the task chat thread, protocol
activity row, transcript adapter, MCP app host, workspace detail pages
and artifact cards with the shared helper.
- Apply the helper to artifact rows, rich artifact source and download
links, approval result links, request-confirmation target links,
attachment links in chat bubbles, provider source links, action test
result links and runtime service links.
- Refresh `tests/runner-e2e/source-sdk-public-inputs.json` for the
changed shared files.

## Verification

- `ui/src/lib/safe-url.test.ts`: one table of hostile inputs (script,
data, file, blob, about and custom schemes, whitespace and
control-character variants, non-string values) runs against each helper.
It also checks that `openSafeUrl` uses `noopener,noreferrer`.
- `ui/src/components/MarkdownBody.interaction.test.tsx`: an image with
an unsafe URL never reaches the click handler. An http image still does.
This test failed before the fix (the unsafe URL reached the handler) and
passes now.
- `packages/shared/src/issue-references.test.ts`: non-http schemes with
an issue path return `null`. These cases failed before the fix and pass
now.
- A headless Chromium check confirmed the risk of the old call: a script
URL opened with `window.open(url, "_blank")` ran with access to the
opener. With `noopener,noreferrer` it did not reach the opener.
- `npx vitest run` on the affected UI folders: 116 files, 2119 tests
pass. `tsc --noEmit` for `ui` has no errors in `src`.
- `pnpm verify` exits 2 because the pinned-input registry changed.
Required CI gives the broad coverage.

## Risks

- Low risk. A link from content with a non-http scheme (for example
`mailto:` in an artifact source link) no longer renders as a link in the
changed components. Markdown links keep the existing `react-markdown`
URL rules.
- Mention chips with their own schemes (agent, project, user, skill,
routine) do not change.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, in Claude Code with
tool use and code execution.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DottaandClaude Opus 5.5 authored and GitHub committed 2026-11-23 09:37:06 -06:00
1 parent b7dea0f070
commit ad163d0e36
28 files changed
+256 -128

No files matched your search

@@ -45,6 +45,7 @@ import {
import { TaskChatBubbleActions } from "./TaskChatBubbleActions";
import { TaskChatSystemNotice } from "./TaskChatSystemNotice";
import type { TaskChatMessageItem } from "./task-chat-model";
import { safeNavigableUrl } from "@/lib/safe-url";
interface TaskChatBubbleProps {
item: TaskChatMessageItem;
@@ -372,7 +373,7 @@ function TaskChatBubbleContent({
onClick={video ? () => openImage(ref.url) : undefined}
render={video ? <button type="button" /> :
<a
href={ref.openPath ?? ref.url}
href={safeNavigableUrl(ref.openPath ?? ref.url) ?? undefined}
onClick={(event) => {
if (openText && ref.id && isTextAttachment({ contentType: ref.contentType ?? "", originalFilename: ref.name }) && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
event.preventDefault(); openText(ref.id, ref.name);
@@ -29,6 +29,7 @@ import {
providerNoticeSeverity,
} from "./task-chat-activity-presentation";
import { ANALYTICS_MASK_CLASS } from "@/lib/analytics/privacy";
import { safeNavigableUrl } from "@/lib/safe-url";
const COMPACT_RESEARCH_RESULT_LIMIT = 5;
const COMPACT_WORKSPACE_FILE_LIMIT = 8;
@@ -269,30 +270,18 @@ function detailContent(item: TaskChatProtocolItem, neutral = false): ReactNode |
}
}
function safeActivityHref(value: string | null | undefined): string | undefined {
if (!value) return undefined;
try {
// A fixed HTTPS base accepts relative app paths and fragments as well as
// external HTTP(S) resources, but never executable or local-file schemes.
const url = new URL(value, "https://paperclip.invalid");
return url.protocol === "https:" || url.protocol === "http:" ? value : undefined;
} catch {
return undefined;
}
}
export function hasTaskChatProtocolActivityDetails(item: TaskChatProtocolItem): boolean {
if (item.surface === "provider_activity" && item.autoReview) return true;
// A check expands only when it has an outcome that may not fit on one line.
if (item.surface === "provider_activity" && item.family === "verification") return detailContent(item) !== null;
if (item.surface === "resource") return Boolean(safeActivityHref(item.href));
if (item.surface === "resource") return Boolean(safeNavigableUrl(item.href));
return detailContent(item) !== null || (item.surface === "provider_activity" && Boolean(item.summary?.trim()));
}
export function TaskChatProtocolActivityDetails({ item, neutral = false }: { item: TaskChatProtocolItem; neutral?: boolean }) {
const detail = detailContent(item, neutral);
if (item.surface === "resource") {
const href = safeActivityHref(item.href);
const href = safeNavigableUrl(item.href);
return href ? <a href={href} className="text-foreground underline">{item.title}</a> : <p>{item.title}</p>;
}
return <>{item.surface === "provider_activity" && item.family !== "verification" && item.summary ? <p className="whitespace-pre-wrap break-words">{item.summary}</p> : null}{detail}{item.surface === "provider_activity" && item.autoReview ? <AutoReviewDetail review={item.autoReview} /> : null}</>;
@@ -419,7 +408,7 @@ export function TaskChatProtocolActivityRow({ item }: { item: TaskChatProtocolIt
</>
);
const resourceHref = item.surface === "resource" ? safeActivityHref(item.href) : undefined;
const resourceHref = item.surface === "resource" ? (safeNavigableUrl(item.href) ?? undefined) : undefined;
if (resourceHref) {
return (
<a className="group/activity -mx-1.5 flex min-h-6 w-full min-w-0 max-w-full items-center gap-2 overflow-hidden rounded-sm px-1.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground" href={resourceHref} data-testid="task-chat-protocol-activity-row">
@@ -35,6 +35,7 @@ import {
toolActivityPresentation,
toolTaxonomy,
} from "./tool-taxonomy";
import { safeExternalHttpUrl } from "@/lib/safe-url";
const TERMINAL_STATUSES = new Set([
"failed",
@@ -329,17 +330,6 @@ function titleCaseKey(value: string): string {
.replace(/\b\w/g, (letter) => letter.toUpperCase());
}
function safeHttpHref(value: unknown): string | null {
const href = stringValue(value);
if (!href) return null;
try {
const url = new URL(href);
return url.protocol === "http:" || url.protocol === "https:" ? href : null;
} catch {
return null;
}
}
const PROVIDER_DETAIL_KEYS: Record<
TaskChatProviderActivityItem["family"],
readonly string[]
@@ -504,7 +494,7 @@ function providerActivityItem(
.map(objectRecord)
.slice(0, 64)
.flatMap((source) => {
const href = safeHttpHref(source.url);
const href = safeExternalHttpUrl(source.url);
return href
? [
{