diff --git a/backend/routes/email.js b/backend/routes/email.js index 672ba04..775aec4 100644 --- a/backend/routes/email.js +++ b/backend/routes/email.js @@ -1,10 +1,11 @@ const express = require('express'); const { DEFAULT_RECIPIENTS, sendEmergencyEmail } = require('../services/emailService'); const logger = require('../utils/logger'); +const { verifyToken } = require('../middleware/auth'); const router = express.Router(); -router.post('/', async (req, res) => { +router.post('/', verifyToken, async (req, res) => { try { const report = req?.body?.report; const recipients = Array.isArray(req?.body?.recipients) ? req.body.recipients : DEFAULT_RECIPIENTS; diff --git a/backend/routes/incidents.js b/backend/routes/incidents.js index e107e09..b877063 100644 --- a/backend/routes/incidents.js +++ b/backend/routes/incidents.js @@ -34,12 +34,23 @@ const writeDb = (db) => { fs.renameSync(tmpPath, DB_PATH); }; +const isValidIncidentId = (id) => + typeof id === 'string' && id.length > 0 && id.length <= 64; + const findIncident = (db, incidentId) => db.incidents.find((i) => i.incidentId === incidentId) || null; // All incident routes require auth router.use(verifyToken); +// Validate incidentId parameter format +router.param('incidentId', (req, res, next, id) => { + if (!isValidIncidentId(id)) { + return res.status(400).json({ success: false, error: 'Invalid incidentId format.' }); + } + next(); +}); + /** * POST /api/incidents/mock * Creates a mocked incident report record for the authenticated user. diff --git a/backend/server.js b/backend/server.js index ad7ed78..eba3bdd 100644 --- a/backend/server.js +++ b/backend/server.js @@ -16,7 +16,7 @@ const app = express(); const PORT = process.env.PORT || 5000; app.use(cors()); -app.use(express.json({ limit: '8mb' })); +app.use(express.json({ limit: '1mb' })); app.use((req, res, next) => { const startedAt = Date.now(); @@ -49,7 +49,6 @@ app.use('/api/history', historyRoutes); app.use('/api/vehicle-observations', vehicleObservationRoutes); app.use('/api/incidents', incidentRoutes); app.use('/api/audio', audioRoutes); -app.use(userVideoRoutes); app.use('/api', userVideoRoutes); // Supports both: