GHSA-CQPF-FF9V-MX8X
Authenticated disk-exhaustion DoS: @apostrophecms/attachment crop() orphans a full-size temp on every zero-area crop
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-CQPF-FF9V-MX8X divulgada · CVSS 6.5 (GitHub) | |
| Divulgación | Modificada | Última actualización del registro | |
| Remediación | Parche 4.34.1 | apostrophe · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
## Summary
`@apostrophecms/attachment`'s `crop()` method copies the original image out of uploadfs to a temp file, then image-processes it, and only unlinks the temp on the happy path. A zero-area crop (`width:0, height:0`) makes the image backend (sharp/libvips) throw during processing, so the cleanup `unlink` is skipped and the temp file is orphaned. Because the throw occurs before the crop is persisted, the per-crop dedup never matches, so the same payload leaks a fresh full-image-size temp on every request — an authenticated contributor can exhaust server disk by repeating one cheap request.
## Root Cause
In `packages/apostrophe/modules/@apostrophecms/attachment/index.js`, `crop()` (lines 584–626):
- `:609` `copyOut` writes the full original to `tempFile = ${getTempPath()}/${generateId()}.${ext}`
- `:610` `copyImageIn(tempFile, …, {crop, sizes})` runs the image backend
- `:615` `db.updateOne(...)` persists the crop
- `:625` (happy path only) `unlink(tempFile)`
There is no `try/finally` spanning lines 609–625 (0 occurrences in 584–626). When `copyImageIn` rejects, control unwinds `crop()` before reaching either `updateOne` or `unlink`. The sibling `upload` route (:168–196) and `aiHelperWriteImageToUploadfs` DO use `finally{unlink}`, confirming the omission is a real gap.
`sanitizeCrop` (:627) launders each dimension with `launder.integer(v, 0, 0, 10000)` — min is 0, so `{top:0,left:0,width:0,height:0}` is a valid, truthy crop object and passes the `!sanitizedCrop` guard (:221). A width/height of 0 is passed to sharp `.extract({left:0,top:0,width:0,height:0})`, which libvips rejects ("extract_area: parameter width not set / parameter height not set"); the rejection surfaces at `toFile` inside `copyImageIn`'s `convert` and propagates through the promisified callback so `crop()` rejects at :610.
## Impact
Authenticated disk-exhaustion DoS (A:H). Each request leaks one full-original-size temp (attacker controls the size by first uploading a large croppable image). Since the crop is never persisted, the dedup `_.find(crops, crop)` (:597) never matches, so each repeat of the identical payload writes a new unique-id temp. Nothing sweeps `getTempPath()` (default `data/temp/uploadfs`) — core and uploadfs have no periodic cleanup of this directory. Unbounded growth at zero marginal attacker cost → disk/inode exhaustion halts all writes app-wide.
## Proof of Concept
1. As a contributor (role granting `upload-attachment`), upload one large croppable image (png/jpg/gif/webp) via the attachment `upload` route → obtain attachment `_id`.
2. Repeatedly:
`POST /api/v1/@apostrophecms/attachment/crop` with body `{"_id":"<id>","crop":{"top":0,"left":0,"width":0,"height":0}}`
3. Each response errors, but a fresh full-size temp accumulates under `data/temp/uploadfs`. Loop until disk is full.
## Attack Chain
1. Entry: `POST /api/v1/@apostrophecms/attachment/crop` body `{_id, crop:{top:0,left:0,width:0,height:0}}` (route index.js:209–234).
- Guard: `self.canUpload` (index.js:210 → :1535) requires `upload-attachment`. Bypass: permission/index.js:110–112 grants `upload-attachment` to contributor/editor → satisfiable at contributor level. PASS.
2. Check: route body check (index.js:215) — `{top:0,...}` is a non-null, non-array object → PASS.
3. Check: `sanitizeCrop` (index.js:219 → :627) — `launder.integer(0, 0, 0, 10000)` keeps `0` (0 < min(0) is false), returns truthy `{0,0,0,0}`; `!sanitizedCrop` (:221) PASS.
4. Sink: `crop()` (index.js:584) — `findOne({_id})` resolves; `_.find(crops, crop)` (:597) does not match (crops empty); `copyOut` (:609) writes the full original to `tempFile`; `copyImageIn` (:610) runs sharp → throws on width:0.
5. Impact: throw at :610 skips `updateOne` (:615) and `unlink` (:625). Temp orphaned. Crop never persisted → dedup never matches on retry → every repeat leaks a fresh temp → unbounded disk fill.
## Bypass Evidence
- No try/finally spans index.js:609–625 (grep: 0 occurrences in 584–626).
- `sanitizeCrop` min=0: `launder.integer(0,0,0,10000)` returns 0 (launder/index.js:97–120 keeps 0 because `0 < min(0)` is false) → zero-area crop is a valid payload.
- Sharp-throws lynchpin empirically verified (sharp 0.35.5, the version uploadfs requires `^0.35.4`): `Sharp(src).rotate().extract({left:0,top:0,width:0,height:0}).clone().resize({...}).toFile(...)` → REJECTS: "extract_area: parameter width not set / parameter height not set". `.extract()` returns the pipeline without a sync throw; the rejection surfaces at `toFile`, inside `copyImageIn`'s `convert`, and propagates via the promisified callback so `crop()` rejects at :610 (copyImageIn error propagation verified in uploadfs.js:306–420).
- `_.find(crops, crop)` dedup (:597) never matches because the throw precedes `updateOne`, so `crops` stays `[]`.
## Affected Versions
`apostrophe <= 4.34.0` (= current npm `latest`). Vulnerable code present on HEAD `a01f937`; no fix on HEAD.
## Suggested Fix
Wrap the copy-out/process/persist block in `try/finally` and always `unlink(tempFile)` in the `finally`, matching the sibling `upload` route and `aiHelperWriteImageToUploadfs`. Additionally, reject zero-area crops in `sanitizeCrop` (require width/height >= 1).
---
Reported by zx (Jace) — GitHub: @manus-use
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
npmapostrophe |
Corregida | 4.34.1 | 0 d | 4.34.1 no afectada |
4.34.1Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/apostrophecms/apostrophe/security/advisories/GHSA-cqpf-ff9v-mx8xLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
