Full-codebase-audit 2026-05-30 outputs: - Audit report: 09 - Audits/Full Codebase Audit - 2026-05-30.md - 81 issue files ISSUE-055..135 (decisions + 1 skipped no-brainer). - Scanner docs from scratch (was zero): architecture, data model, API ref, payment flow, operations runbook + repo README. - Doc-sync updates across API reference, data models, flows, design system. - Secret Rotation Runbook (08 - Operations) for the exposed credentials. - Reusable workflow guide (07 - Development) + .claude/workflows/full-codebase-audit.js. Issues remain status:open intentionally — the code fixes are uncommitted-then-committed working-tree changes per repo and aren't "resolved" until merged/deployed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1.8 KiB
Markdown
39 lines
1.8 KiB
Markdown
---
|
|
issue: 055
|
|
title: "DELETE /api/files/delete has no ownership check — requires new persistence layer (NB-27 skipped)"
|
|
severity: high
|
|
domain: File Management
|
|
labels: [security, backend, idor, skipped-nobrainer]
|
|
status: open
|
|
created: 2026-05-30
|
|
source: Full Codebase Audit 2026-05-30
|
|
---
|
|
|
|
# DELETE /api/files/delete has no ownership check — requires new persistence layer (NB-27 skipped)
|
|
|
|
**Severity:** high
|
|
**Domain:** File Management
|
|
**Labels:** security, backend, idor, skipped-nobrainer
|
|
|
|
## Description
|
|
|
|
`fileService.deleteFile()` is a pure filesystem path operation — there is no `File` model and no `createdBy`/`owner` field stored anywhere in the database. Any authenticated user who knows (or guesses) another user's filename can delete that file via `DELETE /api/files/delete?filename=...`.
|
|
|
|
This was triaged as NB-27 but skipped because adding an ownership check requires first creating a new File persistence layer (model + write-on-upload path), which is a larger-than-mechanical change that risks introducing new bugs.
|
|
|
|
## What is Needed
|
|
|
|
1. Create a `File` model (or add an `uploads` sub-document to the User model) that records `{ filename, uploadedBy: ObjectId, createdAt }` when a file is stored.
|
|
2. Add a middleware or controller check in `fileController.deleteFile` that looks up the record and requires `req.user.id === file.uploadedBy` (or admin).
|
|
3. Back-fill the upload handler to write the record on every `POST /api/files/upload`.
|
|
|
|
## Affected Files
|
|
|
|
- `backend/src/services/file/fileController.ts` — add ownership check
|
|
- `backend/src/services/file/fileRoutes.ts` — (route already protected by `authenticateToken`)
|
|
- New: `backend/src/models/File.ts` (or equivalent) — persistence layer
|
|
|
|
## References
|
|
|
|
- [Full Codebase Audit 2026-05-30](../09%20-%20Audits/Full%20Codebase%20Audit%20-%202026-05-30.md)
|