1.5 KiB
1.5 KiB
A05: Injection
Last updated: March 1, 2026
Findings addressed
- API route used unsafe Prisma raw SQL helper (
$queryRawUnsafe) for/health/db. - Restore script accepted unvalidated external inputs that could be abused for command/SQL injection scenarios during operational use.
Fixes implemented
- Replaced unsafe raw SQL helper:
app.prisma.$queryRawUnsafe("SELECT now() as now")- replaced with tagged, parameter-safe:
app.prisma.$queryRaw\SELECT now() as now``
- Hardened
scripts/restore.shinput handling:
- Added required file existence check for
BACKUP_FILE. - Added strict identifier validation for
RESTORE_DB(^[A-Za-z0-9_]+$).
Files changed
api/src/server.tsscripts/restore.shapi/tests/injection-safety.test.tsapi/vitest.security.config.ts
Verification
Command:
cd api
npx vitest run -c vitest.security.config.ts tests/injection-safety.test.ts
Verified output:
- Test Files:
1 passed (1) - Tests:
2 passed (2)
Dedicated A05 checks in injection-safety.test.ts:
- Verifies no usage of
$queryRawUnsafe/$executeRawUnsafeacross API source files. - Executes
scripts/restore.shwith adversarialRESTORE_DBinput and verifies restore is rejected before DB commands execute.
Residual notes
- Main API query paths use Prisma query builder + zod input schemas (reduces SQL injection risk).
- Operational scripts should remain restricted to trusted operators and environments.