GHSA-RGG4-476Q-XGCG
@apostrophecms/form: File attachments stored and publicly accessible before CAPTCHA validation is enforced
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Remediación | Parche 1.5.4 | @apostrophecms/form · -33 d desde divulgación | |
| Divulgación | Publicada | GHSA-RGG4-476Q-XGCG divulgada · CVSS 6.5 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
<img width="1919" height="1047" alt="stored" src="https://github.com/user-attachments/assets/4990ff98-f4a7-42c5-8a3d-4975781b68bb" />
server.js https://github.com/user-attachments/files/28651508/server.js
exploit.sh https://github.com/user-attachments/files/28651516/exploit.sh
Summary
In `@apostrophecms/form`, file attachments are stored to the database and served publicly before CAPTCHA validation errors are enforced. When CAPTCHA verification fails, the server returns HTTP 400 and creates no submission record, but `attachment.insert()` has already executed.
The resulting attachment record is never removed by garbage collection, which only targets records with `utilized: true` — a flag that form-uploaded attachments never receive.
An unauthenticated user can generate persistent, publicly accessible files on any site running `@apostrophecms/form` with file upload fields enabled, regardless of CAPTCHA configuration.
---
Details
Root Cause 1 — Incorrect Execution Order in `lib/processor.js`
`submitForm()` calls `checkRecaptcha()`, which pushes to `formErrors` but does not throw. File upload runs unconditionally before `formErrors` is checked:
// lib/processor.js lines 17–101
if (form.enableRecaptcha) {
await self.checkRecaptcha(req, input, formErrors); // records failure, does not throw
}
for (const [field, value] of Object.entries(input)) {
if (value === 'files-pending') {
input[field] = await self.insertFieldFiles(req, field, req.files); // file stored here
}
}
if (formErrors.length > 0) {
throw self.apos.error('invalid', { formErrors }); // too late — file already in DB
}`insertFieldFiles()` calls `attachment.insert()` with `{ permissions: false }`:
// lib/processor.js lines 121–123
const attachment = await self.apos.attachment.insert(req, files[entry], {
permissions: false
});Root Cause 2 — Orphaned Records Never Collected by Garbage Collection
The garbage collector in `modules/@apostrophecms/attachment/index.js` only processes records where `utilized: true`:
async function _delete() {
const docs = await self.db.find({
utilized: true,
'docIds.0': { $exists: 0 },
archived: true
}).toArray();
}Attachments created via `insertFieldFiles()` are never linked to any document and never receive the `utilized` flag. They match none of the garbage collection queries and persist indefinitely.
---
Proof of Concept
Tested Versions
- `apostrophe` v4.30.0
- `@apostrophecms/form` v1.5.3
Requirements
- Node.js ≥ 18
- Docker
Terminal 1 — MongoDB
docker start apos-mongo 2>/dev/null || docker run -d --name apos-mongo -p 27017:27017 mongo:6Terminal 2 — Server
kill $(lsof -ti:3737) 2>/dev/null; sleep 1
cd /tmp/apos-form-inttest && node server.js 2>&1 | grep -v "Nonexistent widget\|doc type @apos\|WARNING: widget\|DeprecationWarning\|Use .node --trace"Wait for:
[*] Ready. Run exploit.sh in Terminal 3.Terminal 3 — Exploit
sleep 16 && bash /tmp/apos-form-inttest/exploit.shExpected Output
✓ Submission rejected (HTTP 400)
✓ Attachment record created (+1 in aposAttachments)
✓ No form submission record created (file completely detached)
✓ utilized flag absent — GC will never collect this record
✓ Attachment publicly accessible without authentication (HTTP 200)
CONFIRMED — all criteria met.---
Impact
Any site running `@apostrophecms/form` with file upload fields is affected, regardless of whether CAPTCHA is enabled.
An unauthenticated attacker can repeatedly submit forms with attached files. Each rejected submission permanently stores an attachment record with a stable public URL.
Characteristics of the resulting attachments:
- The submission is rejected with HTTP 400.
- No form submission record is created.
- The file remains publicly accessible.
- The attachment record persists indefinitely.
- Garbage collection does not remove the record.
As a result, an attacker can generate unbounded persistent storage and publicly accessible attacker-controlled files through requests that are explicitly rejected by the application.
Verified Behavior
- CAPTCHA verification fails.
- The application returns HTTP 400.
- `attachment.insert()` executes before the rejection path.
- A new record is written to `aposAttachments`.
- No new record is written to `aposFormSubmissions`.
- The uploaded file is retrievable through its public attachment URL.
- The attachment record lacks the state required for garbage-collection cleanup.
Remediation
Validate form submissions before processing file uploads.
Specifically, `submitForm()` should enforce CAPTCHA and other validation errors before calling `insertFieldFiles()` or `attachment.insert()`. Failed submissions should not result in attachment creation, public URL generation, or persistent storage.
Additionally, attachments created during form processing should either:
- Be deleted if the submission ultimately fails, or
- Be marked as temporary and automatically garbage collected unless associated with a successful form submission.
This ensures rejected submissions cannot create persistent, publicly accessible attachment records.
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 |
|---|---|---|---|---|
npm@apostrophecms/form |
Corregida | 1.5.4 | -33 d | 1.5.7 no afectada |
1.5.4Arsenal 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-rgg4-476q-xgcgLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
