
CVE-2026-91940: arbitrary file write in crawl4ai <=0.9.2 via the untrusted-config gate (PDFContentScrapingStrategy image_save_dir). Analysis, reproduction harness and verified 0.9.2 vs 0.9.3 boundary.
| CVE | CVE-2026-91940 |
| Product | crawl4ai, ~84k stars |
| Affected | >= 0.9.0, <= 0.9.2 |
| Fixed | 0.9.3 |
| Class | CWE-22, arbitrary file write (attacker-chosen directory, byte-exact content) |
| Privileges | a caller able to reach POST /crawl. See Privileges |
| Verdict | CONFIRMED VULNERABLE on 0.9.2, PATCHED on 0.9.3, both reproduced end to end |
| CVSS 3.1 | 6.5 AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N (NVD publishes 7.5 with PR:N, which does not hold for 0.9.2) |
| Advisory | GHSA-xpp7-j28w-2gvx |
crawl4ai's HTTP API accepts a configuration object inside the request body. Because a body
is attacker-controlled, the project built a trust boundary for it: configs loaded with
Provenance.UNTRUSTED are passed through a gate that is supposed to drop or reject any
field that an untrusted caller must not set.
That gate fails open for one reachable class. PDFContentScrapingStrategy is explicitly
constructible from an untrusted body, but it has no field allowlist, and the gate's rule for
"no allowlist" is "keep everything". So its image_save_dir reaches the PDF processor
untouched, and the processor creates that directory and writes the images of the fetched PDF
into it with no containment check. The result is a write to any directory the service
account can reach, with content the caller supplies.
1. The endpoint marks the body untrusted (deploy/docker/server.py):
crawler_config = CrawlerRunConfig.load(
crawl_request.crawler_config, provenance=Provenance.UNTRUSTED
)
2. The gate keeps every field of a type that has no allowlist (crawl4ai/async_configs.py):
def _filter_untrusted_fields(type_name: str, params: dict) -> dict:
"""Drop non-allowlisted fields and raise on forbidden (power) fields."""
forbidden = UNTRUSTED_FORBIDDEN_FIELDS.get(type_name, set())
allowlist = UNTRUSTED_FIELD_ALLOWLIST.get(type_name) # None => keep all non-forbidden
out = {}
for key, value in params.items():
if key in forbidden:
raise UntrustedConfigError(...)
if allowlist is not None and key not in allowlist:
continue # silently drop unknown/unsafe fields (forward-compatible)
out[key] = value
return out
3. The PDF strategy is reachable but has neither an allowlist nor a forbidden list.
UNTRUSTED_ALLOWED_TYPES contains PDFContentScrapingStrategy, so a body can build one
through CrawlerRunConfig.scraping_strategy. But UNTRUSTED_FIELD_ALLOWLIST has keys only
for BrowserConfig and CrawlerRunConfig, and UNTRUSTED_FORBIDDEN_FIELDS likewise. So
allowlist is None, forbidden is empty, and extract_images, save_images_locally and
image_save_dir all survive.
4. The sink trusts that path (crawl4ai/processors/pdf/processor.py):
if self.extract_images and self.save_images_locally:
if self.image_save_dir:
image_dir = Path(self.image_save_dir)
image_dir.mkdir(exist_ok=True, parents=True)
Absolute path accepted, directories created recursively, no realpath containment check
against a storage root. _extract_images() then writes each image of the PDF there.
5. The PDF is fetched by the strategy itself. PDFContentScrapingStrategy.scrap() calls
self._get_pdf_path(url), which downloads the URL independently of the crawler's browser
stage. So the bytes that get written come from a file the attacker hosts.
This part is absent from the advisory, which only says "attacker-controlled bytes" without
saying how. Only the /FlateDecode branch of _extract_images() goes through PIL
(img.save(final_path)) and is therefore re-encoded to PNG. The other three branches write
the raw PDF stream:
PDF /Filter | written extension | how it writes |
|---|---|---|
/DCTDecode | .jpg | open(final_path, 'wb').write(data) |
/CCITTFaxDecode | .tiff | same, and a TIFF header is prepended only when data[:4] != b'II*\x00' |
/JPXDecode | .jp2 | same |
/FlateDecode | .png | re-encoded by PIL, so not byte-exact |
Embedding the payload as a /DCTDecode image XObject therefore puts those exact bytes on
disk. This was confirmed by comparing checksums: the md5 of the file written on the server
equals the md5 of the payload handed to exploit.py.
NVD scores this PR:N. On the 0.9.2 build that does not hold, and the difference was
measured rather than assumed.
The image ships auth_gate.py, a fail-closed AuthGateMiddleware mounted at the outermost
ASGI layer. Its own docstring explains why it exists:
The previous design decided auth in a per-route FastAPI dependency that, when
jwt_enabledwas false (the default), returnedlambda: None, so everyDepends(token_dep)was decorative and the whole API was open.
It now covers every route, mount and sub-app, HTTP and WebSocket, and rejects a request
without a valid credential before any handler runs. On top of that, when no
CRAWL4AI_API_TOKEN is set the entrypoint binds loopback only and logs an ephemeral token
for that session. A request with no credential gets:
HTTP/1.1 401
{"detail": "Authentication required"}
The vulnerability is still real, and the reason matters: crawl4ai treats the request body as
untrusted even when it comes from a legitimate API caller. That is the entire purpose of
Provenance.UNTRUSTED. So a caller who is allowed to use the API, a tenant, a downstream
service, a low-privileged user of a shared deployment, escalates to arbitrary file write on
the host. That is PR:L, which is where the 6.5 comes from instead of 7.5.
pypdf is not in the official image. The advisory states that it is, and that therefore
no extra install is needed. In unclecode/crawl4ai:0.9.2, pip list reports only
Crawl4AI 0.9.2 and pillow 12.3.0, and find / -iname 'pypdf*' returns nothing. Without
it, NaivePDFProcessorStrategy.__init__ raises ImportError, so the write requires a
deployment that installed the crawl4ai[pdf] extra or built a custom image.
That failure is itself useful, because it proves the gate bypass without the write even
happening. The ImportError surfaces from inside the construction call:
async_configs.py:470 k: from_serializable_dict(v, provenance) for k, v in params.items()
async_configs.py:472 return cls(**constructor_args)
processors/pdf/__init__.py:63 self.pdf_processor = NaivePDFProcessorStrategy(
processors/pdf/processor.py:64 raise ImportError("pypdf is required for PDF processing...")
The untrusted image_save_dir reached the strategy constructor. It was not dropped and not
rejected. The only thing standing between that and a write is a missing library.