Skip to content
SSRF Disclosed report Intermediate CVE-2024-0243

langchain Server-Side Request Forgery vulnerability

The RecursiveUrlLoader in langchain did not properly enforce the prevent_outside=True option, allowing a malicious page to link to external URLs that the crawler would still download. An attacker controlling the initial page could cause the crawler to fetch arbitrary external resources.

langchain-ai/langchain

Originally disclosed on huntr

With the following crawler configuration:

Python
from bs4 import BeautifulSoup as Soup

url = "https://example.com"
loader = RecursiveUrlLoader(
    url=url, max_depth=2, extractor=lambda x: Soup(x, "html.parser").text 
)
docs = loader.load()

An attacker in control of the contents of https://example.com could place a malicious HTML file in there with links like "https://example.completely.different/my_file.html" and the crawler would proceed to download that file as well even though prevent_outside=True.

https://github.com/langchain-ai/langchain/blob/bf0b3cc0b5ade1fb95a5b1b6fa260e99064c2e22/libs/community/langchain_community/document_loaders/recursive_url_loader.py#L51-L51

Resolved in https://github.com/langchain-ai/langchain/pull/15559

From the GitHub Advisory Database (GHSA-h9j7-5xvc-qhg5, CC BY 4.0).

The original report as published on the GitHub Advisory Database. Images and videos are our own copies; raw HTML is shown as text. View it on GitHub Advisory Database.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the URL validation for prevent_outside was insufficient, allowing links to domains that merely start with the same string as the original domain.

Impact

An attacker could cause the crawler to make requests to arbitrary external URLs, potentially leading to server-side request forgery or data exfiltration.

What the attacker needed

Attacker controls the starting page content; crawler uses prevent_outside=True

The fix

The issue was fixed in a pull request.

How it was found

  1. Configure RecursiveUrlLoader with prevent_outside=True and a starting URL.
  2. Place a malicious HTML file at the starting URL containing links to external domains that share a prefix with the original domain.
  3. Run the loader; it downloads the external files despite the setting.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A web crawler is a program that automatically follows links on web pages to download content. The langchain crawler had a setting to stay on the same website, but a bug let it follow links to other websites anyway. This means someone who controls the starting page could trick the crawler into downloading files from anywhere.

What is SSRF?

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.

More from langchain-ai/langchain

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.