Blinkist for URLs with LangChain and OpenAI

Summarize any web page or PDF link with LangChain and OpenAI, and fetch URLs safely so users can't point your app at internal addresses.

In my previous post, I built a news digest that reads and summarizes search results. This one does the same for a web link: paste any URL, pick a summary style, and get the gist of the page, essentially a Blinkist for web pages. It's the URL option in the Summarize tool of my LangChain examples app, which also handles pasted text and PDFs.

Retrieve URL Content

The app downloads the page with httpx and passes the HTML to trafilatura, which strips navigation, ads, footers and comments and keeps the main content. If the URL points to a PDF, the app parses it with pypdf instead:

def fetch_text(url: str) -> tuple[str, str]:
    data, content_type, final_url = _download(url.strip())
    if "pdf" in content_type or final_url.lower().endswith(".pdf"):
        return final_url, "\n\n".join(pdf_text(data))
    html = data.decode("utf-8", errors="replace")
    text = trafilatura.extract(html, url=final_url, include_comments=False, include_tables=True)
    if not text:
        raise FetchError("No readable text found on that page.")
    return final_url, text

The summary itself is one LangChain call with a prompt for the chosen style: short, detailed or bullet points. The prompt wraps the page in tags and tells the model to ignore any instructions inside it to minimize indirect prompt injection attempts.

This app is pretty simple: it reads the HTML the server sends, without running JavaScript. Most articles, docs and blog posts work fine, but a single-page app or a site behind bot protection may come back with "No readable text found on that page." For those, a hosted scraper such as Firecrawl renders the page in a browser and returns clean markdown. If you want more options, I compared it with Scrapy, Playwright and BeautifulSoup in this post.

Fetch URLs with SSRF Protection

Any URL input by a user can potentially turn the app into a proxy, and should be treated as untrusted by default. If the server is in a cloud environment, a request to http://169.254.169.254/ can return instance metadata and credentials, and http://localhost:5432 reaches services that were never meant to be public. This is server-side request forgery (SSRF), and URL summarizers, link previews and "chat with a web page" tools are all prone to it.

Checking the hostname isn't enough, because a public-looking domain can resolve to a private address. The app resolves the name first and rejects it unless every address is publicly routable:

infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
addresses = [info[4][0] for info in infos]
if not addresses or not all(ipaddress.ip_address(a.split("%")[0]).is_global for a in addresses):
    raise FetchError("That address is not publicly reachable.")

It then connects to the IP it just checked, rather than letting the HTTP client resolve the name again. That closes the DNS rebinding gap, where a domain returns a public address for the check and a private one a moment later for the request. TLS still verifies the certificate against the original hostname. The app also turns off automatic redirects and checks every hop before following it, up to five. Downloads stop at 5 MB, and URLs with embedded credentials are rejected.

Deploy the App on Railway

My LangChain Apps template on Railway deploys the app with Postgres and pgvector. Set OPENAI_API_KEY and APP_PASSWORD, so strangers can't spend your credits through the public URL.

Deploy on Railway

Summarize a URL

Open Summarize, choose URL, paste a link and pick Short, Detailed or Bullets. The app shows the final URL it fetched, after any redirects, above the summary.

Summarize tool showing a short summary of a web page with its source URL
Summarize tool showing a short summary of a web page with its source URL

Frequently Asked Questions

Can it summarize a PDF from a link? Yes. If the link returns a PDF, the app extracts its text and summarizes that instead of HTML.

Why does a page return "No readable text found"? The page probably builds its content with JavaScript, or blocks automated requests. Try a hosted scraper like Firecrawl for those pages.

Does this app protect against SSRF? It rejects private, loopback and link-local addresses, pins each request to the IP it checked, and re-checks every redirect. If you build your own URL fetcher, apply the same checks before you deploy it.

Subscribe to alphasec

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe