Skip to content

A received link preview shows only if its https link is in the message - #168

Merged
pitis merged 2 commits into
mainfrom
fix/previews-match-their-message
Nov 14, 2026
Merged

pitis merged 2 commits into
mainfrom
fix/previews-match-their-message

Conversation

@pitis

@pitis pitis commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

  • link_preview::previewable(text, url) (next to first_link) decides whether a preview gets a card. Its URL must:
    • parse as https and have no user name or password before the host;
    • be written whole in the text: a whitespace-separated word, or one after opening brackets or quotes (( [ < " '), starts with it, and only closing or sentence punctuation (.,;:!?)]>"') follows it in that word.
  • data_message (projector.rs) keeps a preview only if it passes that check, against the text as stored. Received messages and sent-from-phone transcripts both go through data_message. A view-once caption isn't kept, so a view-once message gets no card. A preview that fails the check is dropped; the message and its files stay.
  • An edit (Op::Edit in db.rs) whose new text no longer passes the check for the stored card's URL drops the card and its image (the attachment row at position -1 and its file). Without this, an edit could keep a card for a link the new text no longer has.

Why

A sender could attach a preview card whose link isn't in the message: the card says "Google Docs", the link opens something else, and only a small host name gives it away. Signal's apps keep a received preview only if its URL is one of the links they find in the message text. The link-previews spec (docs/superpowers/specs/2026-10-17-m4-link-previews-design.md) already says recipients show it only when its URL is in the text. A match anywhere in the text isn't enough: https://github.co sits inside https://github.com/acme/repo, and one link can sit inside another's query or fragment. So the URL must be a whole link.

Other paths:

  • Story text links are a different feature and are unchanged.
  • The history import from the phone (history/import.rs) takes previews the phone has already filtered.
  • The desktop app (core/desktop) doesn't show link previews.
  • presage's own copy of the message (presage.db) still holds the original preview, but the app shows only the projection, so that copy isn't touched.
  • The send-side check (client.rs send_text, body.contains(&p.url)) is unchanged. The draft's URL comes from our own first_link, which also finds a link in the middle of a word (see:https://…). The stricter rule there would drop cards the composer had shown, and our own text isn't the threat.

How it was tested

  • a_preview_is_kept_only_if_its_https_link_is_in_the_message_whole (projector) runs each case as a received message and as a phone transcript.
    • Kept: a plain link; look: https://example.org.; (https://en.wikipedia.org/wiki/Rust_(language)) with or without the final ) in the URL.
    • Dropped: another site; the same host with another path; text with no link; github.co inside github.com/…; accounts.google.com inside accounts.google.com.au/…; a link in another's fragment; a link in another's ?q=; http; an unparseable https://; https://[email protected]/….
    • Kept files with no card: a photo with a mismatched preview, a photo with no text, a view-once photo whose caption has the link.
  • an_edit_without_the_cards_link_drops_the_card_and_its_image (db): an edit that keeps the link keeps the card. One that changes it drops the card, and the downloaded image file goes.
  • Both tests failed before their fix:
    • The projector test first failed on the mismatched link with the original code, then on github.co with the first, match-anywhere version.
    • The db test failed with the card still there after the edit.
  • attachments_and_previews_come_with_their_message: its body was "look", without the preview's link. It now includes the link.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test (sig-core: 480 passed, 3 ignored; the rest pass) all pass.
  • The Swift side and the FFI are unchanged, so the Swift tests weren't run and the xcframework wasn't rebuilt.

Closes #162

A sender could attach a card whose link isn't in the text (it says one site, opens another).
Signal's apps drop such previews; the projector now does too, for received messages and those
sent from the phone. The message itself still shows.
…oves the link removes the card

The card's link was matched anywhere in the text, so part of a longer link counted
(github.co inside github.com/..., a link inside another's query or fragment). It now must be a
whole link: a word, or one in opening brackets or quotes, starts with it and only closing
punctuation follows. Links with a name before the host are refused, and a view-once caption,
which isn't kept, gives no card. An edit whose text no longer has the card's link drops the card
and its image.
@pitis

pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Review findings and fixes (commit e2a7f1a):

Critical 1: a match anywhere in the text let part of a link count (https://github.co inside https://github.com/acme/repo, accounts.google.com inside accounts.google.com.au, a link inside another's #fragment or ?q=).
Fixed. The new link_preview::previewable requires the URL to be a whole link: a word, or one after opening brackets or quotes, starts with it, and only closing or sentence punctuation follows. The sentence-punctuation list is the one first_link uses, now a shared const. All four pairs are in the projector test. look: https://example.org. and the Wikipedia (…Rust_(language)) link, with or without the final ) in the URL, are tested as kept. The comment now says what the code does.
The outgoing check in client.rs send_text is unchanged, on purpose. The draft URL comes from our own first_link, which also finds a link in the middle of a word (see:https://…). The stricter rule there would drop a card the composer had shown, and our own text isn't the threat.

Important 2: an edit kept the old card.
Fixed in db.rs. An applied Op::Edit whose new text fails previewable for the stored card's URL deletes the link_previews row and the position -1 image (row and file, the file removed after commit). An edit that keeps the link keeps the card. Our own edits take the same path. presage's copy of the original message still has the preview, but the app shows only the projection, so that copy is left alone. Test: an_edit_without_the_cards_link_drops_the_card_and_its_image, which failed before the fix. The PR body's "Edits carry no preview" note is corrected.

Important 3: test gaps. All added to the projector test:

  • (a) same host, another path: dropped;
  • (b) a photo with a mismatched preview keeps its photo with preview: None;
  • (c) the trailing . and the Wikipedia ) cases are kept;
  • (d) a photo with no text and a preview keeps its photo without the card.

Suggestions taken:

  • URLs with a user name or password before the host are refused (https://[email protected]/d/1, tested).
  • host_str().is_some() is gone (it can't fail for a parsed https URL). The "https://" case is now labelled as unparseable.
  • The check runs against the text as stored: a view-once caption isn't kept, so a view-once message gets no card (tested).

Declined, for the owner:

  • Mixed-script (homograph) detection: more code, and a product call.
  • Scheme case (Https://): the URL must appear in the text exactly as sent, so the same casing on both sides already works. A different casing between the text and the preview is dropped. That's rare, and accepting it would take extra code.

Checks: cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test pass (sig-core: 480 passed, 3 ignored). The Swift side and the FFI are unchanged.

@pitis
pitis merged commit 40dd0a1 into main Nov 14, 2026
@pitis
pitis deleted the fix/previews-match-their-message branch November 14, 2026 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A received link preview shows only if its link is in the message

1 participant