mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-22 14:51:45 +00:00
security: require auth for file and photo uploads
/uploads/files/ and /uploads/photos/ now require a valid Bearer token. Covers and avatars remain public (needed for shared pages and profiles). Prevents unauthenticated access to uploaded documents and trip photos.
This commit is contained in:
+4
-3
@@ -109,13 +109,14 @@ if (DEBUG) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Avatars are public (shown on login, sharing screens)
|
// Avatars are public (shown on login, sharing screens)
|
||||||
|
import { authenticate } from './middleware/auth';
|
||||||
app.use('/uploads/avatars', express.static(path.join(__dirname, '../uploads/avatars')));
|
app.use('/uploads/avatars', express.static(path.join(__dirname, '../uploads/avatars')));
|
||||||
app.use('/uploads/covers', express.static(path.join(__dirname, '../uploads/covers')));
|
app.use('/uploads/covers', express.static(path.join(__dirname, '../uploads/covers')));
|
||||||
|
|
||||||
// All other uploads require authentication
|
// Files and photos require authentication (covers and avatars are public — served statically above)
|
||||||
app.get('/uploads/:type/:filename', (req: Request, res: Response) => {
|
app.get('/uploads/:type/:filename', authenticate, (req: Request, res: Response) => {
|
||||||
const { type, filename } = req.params;
|
const { type, filename } = req.params;
|
||||||
const allowedTypes = ['covers', 'files', 'photos'];
|
const allowedTypes = ['files', 'photos'];
|
||||||
if (!allowedTypes.includes(type)) return res.status(404).send('Not found');
|
if (!allowedTypes.includes(type)) return res.status(404).send('Not found');
|
||||||
|
|
||||||
// Prevent path traversal
|
// Prevent path traversal
|
||||||
|
|||||||
Reference in New Issue
Block a user