@lastshotlabs/slingshot-embeds
v0.0.2
Published
URL unfurling for slingshot — fetches OG metadata server-side for link previews
Readme
title: Human Guide description: Human-maintained guidance for @lastshotlabs/slingshot-embeds
@lastshotlabs/slingshot-embeds is Slingshot's server-side unfurling package. It fetches a URL on the
server, validates it against SSRF rules, parses Open Graph and related metadata, and returns a
normalized preview payload your app can render in chat, feeds, or editors.
When To Use It
Use this package when your app needs:
- link previews for user-submitted URLs
- server-side metadata extraction so browser clients never hold the fetch logic
- a single internal endpoint that can enforce domain allow/block rules
Do not use it for arbitrary HTML scraping. It is optimized for preview metadata, not full-page extraction pipelines.
Minimum Setup
The package is effectively standalone. Register the plugin and call its unfurl endpoint from your UI or app service.
All config is optional. The defaults are:
mountPath: '/embeds'cacheTtlMs: 300_000cacheMaxEntries: 500timeoutMs: 5000maxResponseBytes: 1_048_576
What You Get
The plugin mounts:
POST {mountPath}/unfurl
The route accepts a JSON body with { url: string } and returns normalized metadata such as:
titledescriptionimagesiteNamefavicontype
It also:
- validates protocols and blocks obvious private or reserved hosts
- applies optional allow-list and block-list domain policy
- uses DNS resolution checks to reduce DNS-rebinding SSRF attacks
- caches successful unfurls in memory for the configured TTL
Common Customization
The main knobs are:
allowedDomains: restrict unfurling to trusted domainsblockedDomains: always reject known-problem domainstimeoutMs: keep external fetch latency under controlmaxResponseBytes: cap how much HTML the server will readmountPath: align the endpoint with your app's route layout
If you need to alter behavior, start in:
src/types.tsfor config defaults and response shapesrc/lib/ssrfGuard.tsfor URL validationsrc/lib/unfurl.tsfor fetch and parsing behaviorsrc/lib/htmlParser.tsfor metadata extraction rules
Gotchas
- This package is safe-by-default only if you keep the SSRF guard intact. Do not bypass it to make local or internal network URLs work.
- Domain allow-lists are exact-domain or subdomain matches. Be deliberate about whether
example.comshould also allowfoo.example.com. - The cache is in-memory and per process. It reduces repeat fetches, but it is not a shared preview store across instances.
- The endpoint returns
502when remote fetches fail. That is expected proxy behavior, not an application bug.
Key Files
src/index.tssrc/plugin.tssrc/types.tssrc/lib/unfurl.tssrc/lib/htmlParser.tssrc/lib/ssrfGuard.ts
