Repository navigation
fix(messaging): keep a link's parenthesised URL whole on every channel - #14314
bolichen97 merged 1 commit into
Conversation
|
Intent: A Markdown link whose URL holds a balanced pair of parentheses reaches Slack, Telegram, WhatsApp and iMessage readers whole, and the display-safety screen still collapses every link those channels show, so a credential split around such a link is scanned as the reader sees it. |
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Design Review (Fable 5, fork) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Worst-case delivery latency is asserted in comments and micro-tests, never measured end-to-end at the largest channel budgets. WatchThe seam grade grew from 2 readings to up to 10 per chunk ( SuggestionsThe [DESIGN-REVIEWED] 94648a9 Description read[DESCRIPTION-READ] 1d0cec88740c2e42171a7e97737a78a8977021ef4e5aa65fb8666f8b0f969460 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify the first- Not justified as shipped
What this change shipsInventory (10 items) — 9 justifiedIntent: FIX — a Markdown link whose URL holds a balanced
The 2 unfixed first- [FIRST-PRINCIPLES-REVIEWED] 94648a9 Description read[DESCRIPTION-READ] 05305a5a5c24324d64f7f11e5ae1cbdec04d3e5bff3b7465156a840bae042770 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5 Review (fork) — ✅ no blocking findingsReviewed |
13095b3 to
3cd48e8
Compare
|
self-added: yes
|
3cd48e8 to
48a53b2
Compare
|
self-added: yes
|
|
self-added: yes
|
48a53b2 to
c5d44d1
Compare
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
Rebased: main moved by 13 commits since |
|
self-added: yes
|
|
The red |
|
Rebased: main moved by 3 commits since |
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
|
|
A Markdown link such as [Python](https://en.wikipedia.org/wiki/Python_(programming_language)) is valid CommonMark: a destination may hold a balanced pair of parentheses. The Slack, Telegram and WhatsApp renderers ended the URL at its first ")", so the link opened a page that does not exist and a stray ")" trailed the label. iMessage refused parentheses and left the markup raw. Every renderer now builds its destination from one shared unit, constants.md_link_destination(): one URL character, or a "(...)" group of them, one level deep. A backslash and the character after it are one token, so an escaped "[" or backslash stays whole and a backslash before a parenthesis is refused. A "[" that opens a nested "[label](" is refused, so the inner link renders on its own and the outer text stays as written, while a "](" that opens no link stays part of the URL. An unbalanced "(", a second level of nesting or an escaped "\)" leaves the link as written instead of linking a cut URL. The unit is the grammar outbound_files walks to find local image files, bounded to one level; wherever it matches it ends at the walker's ")", and a test pins this. Slack's destination also excludes "|" and ">", which would end or split its <url|label> form, and every renderer's link label excludes "[", "]" and line breaks, as the screen's does. The display-safety screen collapses each link to its label so the credential scan reads what the reader sees, and a wider link match drops more URL text from that scan. So besides the literal text and the renderers' own grammar, the screen always scans four readings that model no single client: Telegram's plain-text fallback, applying that fallback's own fence, inline-code, heading, "**", "__" and link passes in its order with lone delimiters kept; each link closed at its balanced ")" at any depth, as a CommonMark reader such as Discord closes it; each link closed at the first ")", as a lazy reader closes it; and no link parsing at all, so a key split by markup inside a URL is still scanned. Telegram's renderer imports the fallback passes from the screen, one definition for both. Each converted Slack block, and the joined message, is also scanned as the Slack client displays it and settled until that view shows no key. A key found in any reading is answered with the collapsed, redacted form, which carries no URL, and that answer is itself scanned under every reading. Collapsing can itself close a link ("[AKIA]*(u)" reads as "[AKIA](u)" once the "*" is gone), so rewritten text is collapsed and scanned again until a pass changes nothing, for at most four passes; past that it strips markup outside redaction tags and collapses and scans once more. A cut splitting a long message, each boundary of a message rotated into several, and a cut's repair are graded under the same readings as one message, and the repair always runs with the channel's own cutter. Text with no "](" is graded under the canonical form and the plain fallback only, since each link reading equals the canonical form there.
|
Rebased: |
|
self-added: yes
|
|
self-added: yes
|
|
self-added: yes
|
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed on behalf of the maintainers (sweep 2026-09-29): readiness passed, required checks green on 94648a9, no blocking review threads, security posture unchanged. Ruling on the author's needs-a-decision item: the bundled shape (link grammar + display-safety readings in one PR) is accepted as-is. Approving and merging.
Problem / Motivation
Goal: A Markdown link whose URL holds a balanced pair of parentheses reaches Slack, Telegram, WhatsApp and iMessage readers whole, and the display-safety screen still collapses every link those channels show, so a credential split around such a link is scanned as the reader sees it.
A link to a URL that contains a pair of parentheses arrives broken on chat channels. An answer citing
[Python](https://en.wikipedia.org/wiki/Python_(programming_language))reaches Slack as a link tohttps://en.wikipedia.org/wiki/Python_(programming_language, a page that does not exist, followed by a stray). Telegram puts the same cut URL in its<a href>, and iMessage shows the raw markdown instead of the link.<https://en.wikipedia.org/wiki/Python_(programming_language|Python>)<https://en.wikipedia.org/wiki/Python_(programming_language)|Python><a href="…/Python_(programming_language">Python</a>)<a href="…/Python_(programming_language)">Python</a>[Python](https://…/Python_(programming_language))Python (https://…/Python_(programming_language))The same happens to every URL with a balanced
(...): Wikipedia disambiguation pages, MSDN'sms123401(v=vs.85)pages, many docs anchors.Why it matters
Agents cite Wikipedia and vendor docs all the time, and Slack and Telegram are the main chat channels. The reader clicks the link, lands on "page does not exist" or the wrong page, and nothing on screen says why.
Not a goal
What changed (motivation → approach → change)
Links whose URL contains a
(...)pair now reach Slack, Telegram, WhatsApp and iMessage whole, so they open the right page. Each renderer's link regex stopped the URL at the first)([^)]+), and iMessage's refused parentheses outright; they now accept a balanced pair, as CommonMark does.kiro_crew/constants.pymd_link_destination(): one URL character, or a(...)group of them, one level deep; a backslash and the character after it are one token, so an escaped[or backslash stays whole and a backslash before a parenthesis is refused; a[that opens a nested[label](is refusedslack/format.pytelegram/renderer.py,whatsapp/renderer.pyhttp(s)URL with no whitespace; Telegram's plain-text fallback passes are imported from the screen, one definition for bothimessage/plaintext.pymessaging/display_safety.pymessaging/split.pymessaging/outbound_files.pydocs/system-specs/modules/messaging.mdAn unbalanced
(, a second level of nesting, or a backslash-escaped\)is left as written instead of being linked to a cut URL. A[label](inside a URL opens a link of its own, so that inner link renders on its own and the outer text stays as written. A](that opens no link, as inhttps://x/a](b), stays part of the URL.The helper spells the grammar
messaging/outbound_files.pywalks to find local image files, limited to one level of nesting. Wherever the helper matches, it ends at the same)as that walker, and a test pins this. It stays a regex because four renderers compose it into onere.subpass, and the display-safety screen must stay linear-time.The display-safety screen had to change with the renderers. It collapses each link to its label so the credential scan reads what the reader will see, and a wider link match drops more URL text from that scan. So besides the literal text and the renderers' own grammar, it always scans four readings that model no single client:
**,__and link passes in its order, lone delimiters kept;)at any depth, as a CommonMark reader such as Discord closes it, with a backslash escape read as one character and an<...>destination taken whole;), as a lazy reader closes it;Each converted Slack block, and the joined message, is also scanned as the Slack client displays it and settled until that view shows no key, and so is every part a long message is cut into; a block dirty only as written keeps its links and emphasis.
A key found in any reading is answered with the collapsed, redacted form, which carries no URL. That answer is itself scanned under every reading, because one message can carry two keys that different readings join. Whatever a reading still shows is redacted and settled, for at most four passes, then the strip below. A cut splitting a long message, and each boundary of a message rotated into several, is refused when any reading joins a key across it.
Collapsing can itself close a link (
[AKIA]*(u)reads as[AKIA](u)once the*is gone), so rewritten text is collapsed and scanned again until a pass changes nothing, for at most four passes; past that it strips markup outside redactor tags and collapses and scans once more. Each renderer's link label excludes[,]and line breaks, as the screen's does.Backwards compatibility
Compatible: no input is refused. A link renders exactly as before unless its URL holds parentheses: a balanced pair is kept whole, and an unbalanced
(, deeper nesting, an escaped\)or a nested[label](is left as written instead of being linked to a cut URL. A message hiding a key that any reading shows joined (Telegram's plain-text fallback, a balanced or first-)link close, or the URL text once markup is dropped) is redacted and sent in its collapsed form, as a message hiding a key elsewhere already is. A lone or unpaired delimiter in a URL leaves the link as it is. That collapsed form is collapsed again until it settles, and one that still changes after four passes also loses its markup characters, redaction tags excepted. A link whose label holds[,]or a line break is left as written on every channel; for[x[y](u)only[y](u)becomes a link. On Slack a link whose URL holds|or>is left as written.Tests
test/test_markdown_link_parentheses.py: the exact text each channel receives for Wikipedia and MSDN URLs (Slack, Telegram HTML and plain, WhatsApp, iMessage), an aside's)staying outside the link, two links on one line, an unbalanced URL left unlinked, an escaped parenthesis left as written, and images left raw on Slack. One contract test runs every renderer over the same inputs and fails if a renderer shows a link the display screen does not collapse. Another checks the helper against theoutbound_fileswalker: for every character class a renderer passes, each row states whether the helper matches, a match ends at the walker's), and deeper nesting, an escaped parenthesis or a nested[label](gives no match whilehttps://x/a](b)matches. A key split around a link nested in another link's URL is redacted, with and without a space before it, and so is one split around a URL ending in an escaped backslash; titled, angle-bracketed and spaced destinations still collapse on the screen. A key split by**inside a link's URL is redacted, with and without parentheses and in Slack's<url|label>form, and Telegram's plain-text fallback never shows it; bold text beside a key-free link is left untouched. A differential test runs Telegram's real fallback over 130 generated splits of a key inside a URL and requires the screen to redact exactly the ones the fallback shows joined; a lone or unpaired delimiter,~~and single*or_pairs leave the link untouched, and the reading's inline-code,**and__patterns are pinned to the fallback's own. Its fence pattern gives the fallback's result on all 29,524 strings of up to nine backticks, letters and newlines and on 20,000 seeded longer ones, and a key joined by an empty fence or by a fence's info string, inside a URL or in plain text, is redacted and never shown by the fallback. Text the screen rewrites never renders into a key on Slack, on screen or in Telegram's fallback: a link closed once*, a format character or a Slack link is dropped, the same shape on the canonical branch, one nested a level deeper, and nesting past the pass bound, which leaves no](behind; the construct alone is sent as written. Slack linkshttps://x/a](b)whole and still links an IPv6http://[::1]:8080/. Every renderer's label class is pinned to the screen's, and a key split around a link whose label holds[or a line break is never shown joined on Slack, Telegram, WhatsApp or iMessage. Past the pass bound, a redaction tag stays whole and the output is its own redaction. The screen's plain reading is pinned pass by pass to Telegram's fallback, so a pass added to or reordered in the fallback fails a test. The bound itself is pinned: four rewrites settle, a fifth reaches the fallback, and the fallback removes every markup character it lists.test/test_slack_render_pipeline.py: a key split around a parenthesised link is redacted; a plain parenthesised link renders whole with no redaction; the ReDoS structure guard expects seven negated classes in the screen's link pattern, each still excluding its own delimiters; the controls that prove Slack's own display scan and settling pass are needed narrow the shared screen first, so removing either Slack pass still reopens the leak.test/test_markdown_link_parentheses.pyalso covers each of the screen's readings: a key split around a link a CommonMark reader closes at its balanced)is redacted at nesting depths 2, 3, 4 and 8, behind an escaped\), inside an<...>destination holding), before a stray), and around a link written inside a destination; titled destinations and a[label](nested in a URL stay caught;[AKIA](a)(b)IOSFODNN7EXAMPLE, Wikipedia and MSDN URLs, a nested balanced URL and unclosed openers are returned byte-identical; five hostile inputs (unclosed openers, 3,000-deep nesting,[runs, 400 openers against 400 closers,](<runs) stay linear; no renderer links two-level nesting or an escaped\);AKIA[IOSFODNN7EXAMPLE]**(https://x)**and 192 generated link-and-emphasis shapes against the real Telegram fallback (110 redacted, 82 unchanged); a<url|label>inside a raw Markdown link, with a generator over key cuts; a model-written[REDACTED: AKIA](https://v)past the pass bound;~~,||,*and_pairs inside a parenthesised URL through the Discord path; a redaction tag followed by(,*(,_(or||(keeping its brackets, its count and the text after it through the Discord path, the settling passes, the last resort and the split's repairs; a credential or suspicious-URL tag inside a link destination still delivered and counted when a reading joins a key across that link; and the Telegram renderer and the screen sharing the same fallback pattern objects in order.test/test_markdown_link_parentheses.pypins what the balanced and first-close walks return on escaped brackets and parentheses, a trailing backslash, open and closed angle destinations, and openers with no).test/test_display_split_safety.pypins that a window with no](reads the same under every link reading, which lets the split grading render such a window once.test/test_display_split_safety.py: a rotation split into two or three messages is refused when the heading-marker reading or the balanced-link reading joins a key across a boundary, and a clean heading sequence is not.test/test_split_credential_boundary.py: the repair refuses to run without the channel's cutter, and the last resort strips the markup of a tag an author wrote to look like the redactor's, so no cut of it rejoins a key.test/test_discord.py: the control proving a seal grades its own split narrows the shared screen first.]reds the](URL cases and the structure guard; running a***pass before**reds the case where a URL's**pairs with a later***; adding a~~pass reds the~~case; dropping only the fence pass reds the three code-fence cases; a greedy one-alternative fence pattern reds the fence equivalence check; sending the rewritten text without collapsing it again reds seven of the eight new rewrite cases, all but the construct alone; reading\\as two separate backslashes reds the escaped-backslash cases; restoring the old[^\]]+label class on Slack and Telegram reds the label cases and their speed tests; stripping tag brackets in the fallback reds the tag cases; an extra or swapped pass in Telegram's fallback reds the pass-list pin; a bound of three or five reds the bound tests.Manual verification
Ran each renderer on the examples above and got the "now" column verbatim. Not checked in a live Slack, Telegram or Discord workspace; the tests pin the exact wire text each platform receives. The screen does not model a client that closes a link at a
)that is neither the balanced one nor the first.The changed destination unit scales linearly on hostile input: unclosed
[label](openers,](runs, nested[label](openers,**runs, backslashes and parentheses, up to 320,000 characters. Doubling the input about doubles the time. The screen's fence pass is linear too, about 3 ms on an unclosed fence at 320,000 characters, where Telegram's own fence pattern takes about 2.8 s at 20,000 and grows with the square of the length. Measured end to end with the real redactor on messages that hide a key, the screen takes at most about 0.4 s at 320,000 characters (links nested past the pass bound) against about 0.1 s on main, and under 50 ms at Slack's 40,000-character message cap. On the same unclosed openers, main's Telegram and WhatsApp renderers take about 45 s, because their URL pattern rescans to the end of the message from every opener. A long unclosed run of[btook about 4.7 s at 20,000 repeats in the old Slack and Telegram label class; the narrowed class takes under 2 ms. The degenerate rotation test (a 5,000-backtick run cut into thousands of messages) takes about 4.6 s here against 2.7 s on main, under its 30 s limit. With one link in that run, grading the split takes about 4.8 s of CPU against 1.7 s on main, because every window is read under each reading; the link walks skip ordinary text, and a window with no](is rendered once for all four link readings. When a cut would rejoin a key,_under_a_safe_budgetwalks back through at most 135 budgets (at Teams' 16,000-character budget, the largest a channel passes), and can run once more after the span that rejoins is redacted. With every budget refused, one walk over 16,000 characters takes about 0.7 s of CPU with no](, 2 s with one link and 4 s when a link with nested parentheses in its URL comes every 30 characters, against 0.4 s, 0.4 s and 1 s on main. It grows linearly: the link-dense walk takes about 16 s at 64,000 characters against 4 s on main. End to end through the call pair Teams makes at that budget (split_markdown_safethenbounded_for_delivery, best of three), a markdown reply with a plain access-key pair after every sixth section takes about 0.06 s of CPU at 32,000 characters and 0.13 s at 64,000, against 0.02 s and 0.04 s on main;render_for_slacktakes 0.04 s and 0.08 s on it against 0.02 s and 0.03 s. With every cut of a 32,000-character reply forced to rejoin a key, so both walks run to the end, delivery takes about 2.8 s with no](, 8.2 s with one link and 16.7 s on the link-dense text, against 1.7 s, 1.7 s and 4.3 s on main.Related Issues
no linked issue: found by reading the channel renderers; no report exists yet.
Pattern harvest
Rule candidate: semgrep
Pattern: a Markdown-link regex whose destination is spelled
[^)]…instead of built fromconstants.md_link_destination. The session preview, voice reply, artifact snippet and artifact-deploy page still spell it that way; there it only leaves a stray)or a cuthrefoutside chat, so they are left for a follow-up.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)docs/system-specs/modules/messaging.md