Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

put a resolver's link destination through the same protocol guard a markdown link gets

[._.]/ Adam Eivy2f777bebfa31
diff --git a/client/src/components/cos/MarkdownOutput.jsx b/client/src/components/cos/MarkdownOutput.jsx
index 24f0b19a3c..6afb590bd3 100644
--- a/client/src/components/cos/MarkdownOutput.jsx
+++ b/client/src/components/cos/MarkdownOutput.jsx
@@ -22,11 +22,17 @@ function renderText(text, linkifyText, key) {
// The common case by far: nothing to link. Hand back the bare string so the
// no-reference path costs exactly what it did before the resolver existed.
if (!segments || (segments.length === 1 && typeof segments[0] === 'string')) return [text];
- return segments.map((seg, i) => (
- seg?.url
- ? <a key={`${key}-${i}`} href={seg.url} className={LINK_CLASS} target="_blank" rel="noopener noreferrer">{seg.ref}</a>
- : seg
- ));
+ return segments.map((seg, i) => {
+ // `safeSrc` for the same reason a markdown link's href gets it: the
+ // resolver is supplied by the caller, and a `javascript:`/`data:`
+ // destination must not become an anchor just because it arrived through a
+ // different door. A rejected destination degrades to the literal text.
+ const href = seg?.url ? safeSrc(seg.url) : null;
+ if (!seg?.url) return seg;
+ return href
+ ? <a key={`${key}-${i}`} href={href} className={LINK_CLASS} target="_blank" rel="noopener noreferrer">{seg.ref}</a>
+ : seg.ref;
+ });
}
function parseInline(text, linkifyText) {
diff --git a/client/src/components/cos/MarkdownOutput.test.jsx b/client/src/components/cos/MarkdownOutput.test.jsx
index 70bd0b565e..0ce7cf90d5 100644
--- a/client/src/components/cos/MarkdownOutput.test.jsx
+++ b/client/src/components/cos/MarkdownOutput.test.jsx
@@ -109,3 +109,12 @@ describe('linkifyText resolver', () => {
expect(screen.getByText('Closes #7640')).toBeInTheDocument();
});
});
+
+it('refuses a resolver destination that would not pass as a markdown link href', () => {
+ // The resolver is caller-supplied, so a `javascript:`/`data:` destination must
+ // not become an anchor just because it arrived through a different door.
+ const hostile = (text) => [{ ref: text, url: 'javascript:alert(1)' }];
+ render(<MarkdownOutput content="click me" linkifyText={hostile} />);
+ expect(screen.queryByRole('link')).toBeNull();
+ expect(screen.getByText('click me')).toBeInTheDocument();
+});
diff --git a/client/src/lib/issueRefs.js b/client/src/lib/issueRefs.js
index 98588c27a5..a1d982f895 100644
--- a/client/src/lib/issueRefs.js
+++ b/client/src/lib/issueRefs.js
@@ -36,7 +36,8 @@
// A qualified `owner/repo#12` is deliberately NOT matched: the stamped base
// names one repository and cannot be retargeted at another, so the honest
// outcome is plain text rather than a same-numbered issue in the wrong repo.
-// The `\/` in the lookbehind is what declines it — the `#` there follows `o`.
+// No extra rule is needed: the `#` in `slashdo#12` follows a word character,
+// which the lookbehind already rejects.
const ISSUE_REF_RE = /(?<![\w#&/:=-])#([1-9]\d{0,4})(?!\w)/g;
/**
@@ -48,8 +49,9 @@ const ISSUE_REF_RE = /(?<![\w#&/:=-])#([1-9]\d{0,4})(?!\w)/g;
*
* @param {string} text
* @param {string|null|undefined} issueUrlBase — `agent.metadata.repoIssueUrl`
- * @returns {Array<string | { ref: string, url: string }>} the input as a single
- * string when there is no tracker to resolve against, or nothing to link.
+ * @returns {Array<string | { ref: string, url: string }>} a single-element
+ * array holding `text` unchanged when there is no tracker to resolve
+ * against, or nothing in the text to link.
*/
export function splitIssueRefs(text, issueUrlBase) {
// `indexOf` before the regex: the overwhelming majority of text runs in a