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:
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.
Resolved in https://github.com/langchain-ai/langchain/pull/15559
From the GitHub Advisory Database (GHSA-h9j7-5xvc-qhg5, CC BY 4.0).
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
- Configure RecursiveUrlLoader with prevent_outside=True and a starting URL.
- Place a malicious HTML file at the starting URL containing links to external domains that share a prefix with the original domain.
- 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.