mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 14:20:12 +01:00
## 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>
81 lines
2.8 KiB
TypeScript
81 lines
2.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildIssueReferenceHref,
|
|
extractIssueReferenceIdentifiers,
|
|
findIssueReferenceMatches,
|
|
normalizeIssueIdentifier,
|
|
parseIssueReferenceHref,
|
|
} from "./issue-references.js";
|
|
|
|
describe("issue references", () => {
|
|
it("normalizes identifiers to uppercase", () => {
|
|
expect(normalizeIssueIdentifier("pap-123")).toBe("PAP-123");
|
|
expect(normalizeIssueIdentifier("pc1a2-7")).toBe("PC1A2-7");
|
|
expect(normalizeIssueIdentifier("not-an-issue")).toBeNull();
|
|
});
|
|
|
|
it("parses relative and absolute issue hrefs", () => {
|
|
expect(parseIssueReferenceHref("/issues/PAP-123")).toEqual({ identifier: "PAP-123" });
|
|
expect(parseIssueReferenceHref("/PAP/issues/pap-456")).toEqual({ identifier: "PAP-456" });
|
|
expect(parseIssueReferenceHref("https://paperclip.ing/PAP/issues/pap-789#comment-1")).toEqual({
|
|
identifier: "PAP-789",
|
|
});
|
|
expect(parseIssueReferenceHref("https://paperclip.ing/projects/PAP-789")).toBeNull();
|
|
});
|
|
|
|
it.each([
|
|
"javascript:alert(1)//issues/PAP-1",
|
|
"JavaScript:void(0)//issues/PAP-1",
|
|
"data:text/html,x//issues/PAP-1",
|
|
"vbscript:x//issues/PAP-1",
|
|
"file:///issues/PAP-1",
|
|
"blob:https://paperclip.ing/issues/PAP-1",
|
|
])("rejects issue hrefs with a non-http scheme: %s", (href) => {
|
|
expect(parseIssueReferenceHref(href)).toBeNull();
|
|
});
|
|
|
|
it("builds canonical issue hrefs", () => {
|
|
expect(buildIssueReferenceHref("pap-123")).toBe("/issues/PAP-123");
|
|
});
|
|
|
|
it("finds identifiers and issue paths in plain text", () => {
|
|
expect(findIssueReferenceMatches("See PAP-1, /issues/PC1A2-2, and https://x.test/PAP/issues/pc1a2-3.")).toEqual([
|
|
{ index: 4, length: 5, identifier: "PAP-1", matchedText: "PAP-1" },
|
|
{ index: 11, length: 15, identifier: "PC1A2-2", matchedText: "/issues/PC1A2-2" },
|
|
{
|
|
index: 32,
|
|
length: 33,
|
|
identifier: "PC1A2-3",
|
|
matchedText: "https://x.test/PAP/issues/pc1a2-3",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("trims unmatched square brackets from issue path tokens", () => {
|
|
expect(findIssueReferenceMatches("See /issues/PAP-123] for context.")).toEqual([
|
|
{ index: 4, length: 15, identifier: "PAP-123", matchedText: "/issues/PAP-123" },
|
|
]);
|
|
});
|
|
|
|
it("extracts and dedupes references from markdown", () => {
|
|
expect(extractIssueReferenceIdentifiers("PAP-1 [again](/issues/pap-1) PAP-2")).toEqual(["PAP-1", "PAP-2"]);
|
|
});
|
|
|
|
it("ignores inline code and fenced code blocks", () => {
|
|
const markdown = [
|
|
"Use PAP-1 here.",
|
|
"",
|
|
"`PAP-2` should not count.",
|
|
"",
|
|
"```md",
|
|
"PAP-3",
|
|
"/issues/PAP-4",
|
|
"```",
|
|
"",
|
|
"Final /issues/PAP-5 mention.",
|
|
].join("\n");
|
|
|
|
expect(extractIssueReferenceIdentifiers(markdown)).toEqual(["PAP-1", "PAP-5"]);
|
|
});
|
|
});
|