Skip to content

feat: clickable links and preview cards for links in commits - #73

Merged
nunomaduro merged 3 commits into
dev-null-sh:productionfrom
simonhamp:feat/link-previews
Oct 15, 2026
Merged

nunomaduro merged 3 commits into
dev-null-sh:productionfrom
simonhamp:feat/link-previews

Conversation

@simonhamp

@simonhamp simonhamp commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Links in a commit's body are now clickable, and the first link gets a small preview card under the commit with the site name, title, description and thumbnail from the page's Open Graph tags. Replies get them too.

A commit linking to a YouTube video, with a preview card underneath

Light Dark
The log in light mode with three link previews The log in dark mode with three link previews
On a phone The log at phone width in dark mode

The card is a hairline-bordered row with no shadow, so commits are still rows and not cards. The text stays the main thing.

How this relates to #36

#36 does something similar for GitHub only. It recognises GitHub references, including short forms like laravel/framework#1, and shows live details from the GitHub API, like issue state and stars. This PR is more generic. It works for any site that has Open Graph tags (YouTube, docs sites, blogs, GitHub too) and doesn't depend on any one API.

If both land they overlap on full GitHub URLs. The simple fix would be to skip the generic preview when #36 already has a card for the link. Happy to do that here or in a follow-up, whichever order they go in.

Also, #57 and #69 call their feature "link previews" too, but that's the other direction: the cards devnull serves when its own links are shared elsewhere. This one shows cards for other sites inside devnull. Nothing collides in the code, but it's worth knowing the name now means two things.

What counts as a link

  • Anything starting with http:// or https://.
  • Bare domains like nativephp.com or github.com/nunomaduro/devnull.com. They get https:// added.

Bare domains only match a list of 92 common TLDs, because lots of file extensions are real TLDs. So deploy.sh, README.md, main.rs, Makefile.in, Node.js and app.php stay plain text. A few TLDs that read like code are left out too (user.id, app.run()). Emails and @Handles don't match, a domain followed by ( doesn't match (array.at(-1)), and the TLD has to be all lowercase or all uppercase, so a missing space in Fixed the bug.It works doesn't turn into a link.

The PHP side (FindFirstUrl) and the React side (linkified-text.tsx) follow the same rules, and each points at the other.

How it works

  • CreateCommit finds the first link in the body. Each URL gets one row in a new link_previews table, shared by every commit that links to it, so a page is only fetched once. Commits point at it with a nullable link_preview_id.
  • The page is fetched by a queued job (UnfurlLink), so posting stays fast. The card shows up once the job has run. composer dev already runs a queue listener, but production needs a worker.
  • If a page can't be fetched or has no title, it's marked as done and the commit just shows the plain link. It isn't retried.

Fetching user-supplied URLs

The server fetches whatever people link to, so FetchLinkPreview is careful about where it connects:

  • Only http and https on the default ports, and no credentials in the URL.
  • The host is resolved first. If any address is private, loopback, link-local (including the cloud metadata address), CGNAT or otherwise non-public, nothing is sent.
  • The connection is pinned to the address that was checked, so DNS rebinding can't swap in a private one.
  • Redirects are followed by hand, at most 3, and each hop is checked again.
  • 5 second timeout, a 1 MB cap on the body, and only HTML is parsed.
  • Thumbnails are only kept if they're https, and they load with referrerPolicy="no-referrer".

Things to look at

  • PRODUCT.md lists images and media as "not now". The thumbnails come close to that line. If that's a problem, dropping the image and keeping the text card is a small change.
  • Thumbnails are hotlinked, so people reading the log make requests to the linked sites' image hosts. Proxying them would fix that but felt like too much for this PR.
  • If the server sets HTTP_PROXY/HTTPS_PROXY, curl goes through the proxy and the IP pin no longer applies.
  • Previews are never refreshed. Existing commits don't get one.

Testing

All gates pass locally: Pest (589 tests) at 100% coverage, type coverage, PHPStan, Rector, Pint, oxlint and tsc. The tests use Http::fake() and a fake DNS resolver, so nothing touches the network. I also ran the fetch by hand against GitHub, YouTube (over 1 MB, so the cap kicks in), laravel.com and an http to https redirect, and checked that the metadata address and a redirect to 127.0.0.1 were refused.

Links in a commit's body become clickable, and the first one gets an Open
Graph preview under the commit. Replies get them too. Bare domains like
nativephp.com count as links, as long as the TLD is on an allowlist that
skips file-extension TLDs such as .sh, .md and .rs.

Previews live in a link_previews table shared by every commit that links to
the same URL. A queued job fetches the page with SSRF guards: public
addresses only, the connection pinned to the checked address, redirects
followed by hand and re-checked, a 5 second timeout and a 1 MB cap.
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.

2 participants