Link previews the recipient never fetches (§6.12)
🔴 **The obvious implementation is the one that must not be built.** Having each recipient fetch the URL to draw a card tells the site the reader's IP address, that they received a link, and roughly when they opened it — once per member on a group message. A messenger that hides the message and then has every reader announce its contents to a third party has given away what it was protecting. So the SENDER fetches, and the preview travels inside the ciphertext. The receiver renders from those bytes and contacts nobody. ⚠️ Sender-side is a smaller leak, not no leak: the site learns somebody is about to share that URL, from this address. The setting exists for that, and the copy says who learns what rather than implying it is free. 🔴 **The host is shown separately and derived from the URL**, because title and description come from a page the sender did not write — a card claiming one destination while the link points at another is a phishing primitive. Both fields are bounded on the way IN as well as line-limited at render, so the cap does not depend on a future renderer remembering one. ⚠️ `Content.text` still returns the raw body byte-for-byte when there is no preview, so an ordinary message is unchanged on the wire and older clients see exactly what they saw before. ⚠️ The fetch is short-timeout and best-effort, and runs on the IO context. A preview is a decoration and must never be able to delay a send — every failure path ends as a message with a plain URL in it. engine 168, client 96, app 40. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
7f4fa1bf2b
commit
dc1be35816
@@ -217,6 +217,57 @@ class ContentTest {
|
||||
assertNull(Content.disappearSeconds(Content.parse(Content.text("hello"))))
|
||||
}
|
||||
|
||||
/**
|
||||
* Link previews (§6.12).
|
||||
*
|
||||
* 🔴 The SENDER generates these and they ride inside the ciphertext. A card
|
||||
* each recipient fetched would tell the site the reader's IP, that they
|
||||
* received a link, and roughly when they opened it — once per member on a
|
||||
* group message.
|
||||
*/
|
||||
@Test
|
||||
fun `a link preview round-trips`() {
|
||||
val preview = Content.LinkPreview.of("https://example.com/x", "A title", "A desc")
|
||||
val parsed = Content.parse(Content.text("look https://example.com/x", link = preview))
|
||||
assertEquals("https://example.com/x", parsed.link?.url)
|
||||
assertEquals("A title", parsed.link?.title)
|
||||
assertEquals("look https://example.com/x", parsed.text)
|
||||
}
|
||||
|
||||
/**
|
||||
* 🔴 The host comes from the URL, never the page. A card whose title claims
|
||||
* one destination while the link points at another is a phishing primitive.
|
||||
*/
|
||||
@Test
|
||||
fun `the host comes from the url not the title`() {
|
||||
val preview = Content.LinkPreview.of(
|
||||
"https://evil.example/login", "Sign in — yourbank.com", "")
|
||||
assertEquals("evil.example", preview.host)
|
||||
}
|
||||
|
||||
/** ⚠️ Bounded on the way in, so no renderer has to remember a cap. */
|
||||
@Test
|
||||
fun `title and description are bounded`() {
|
||||
val preview = Content.LinkPreview.of(
|
||||
"https://example.com", "A".repeat(5_000), "B".repeat(5_000))
|
||||
assertEquals(Content.LinkPreview.MAX_TITLE, preview.title.length)
|
||||
assertEquals(Content.LinkPreview.MAX_DESC, preview.desc.length)
|
||||
}
|
||||
|
||||
/** A preview with no title is not a preview — it would render as a blank card. */
|
||||
@Test
|
||||
fun `a preview without a title is refused`() {
|
||||
val json = org.json.JSONObject().put("url", "https://example.com").put("title", "")
|
||||
assertNull(Content.LinkPreview.fromJson(json))
|
||||
}
|
||||
|
||||
/** Optional: a plain message must be byte-identical to before. */
|
||||
@Test
|
||||
fun `a message without a preview stays raw text`() {
|
||||
assertEquals("plain", Content.text("plain"))
|
||||
assertNull(Content.parse("plain").link)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an unknown attachment kind shows a label rather than disappearing`() {
|
||||
val parsed = Content.parse("""{"fnc":1,"kind":"hologram"}""")
|
||||
|
||||
Reference in New Issue
Block a user