fix(web-server): block remote dashboard writes

This commit is contained in:
Tam Nhu Tran committed 2026-04-07 06:10:41 -04:00
1 parent 431c22a16a
commit 5fbe731341
2 files changed
+150

No files matched your search

+25
View File
@@ -6,6 +6,7 @@
*/
import { Router } from 'express';
import { requireLocalAccessWhenAuthDisabled } from '../middleware/auth-middleware';
// Import domain routers
import profileRoutes from './profile-routes';
@@ -36,6 +37,30 @@ import claudeExtensionRoutes from './claude-extension-routes';
// Create the main API router
export const apiRoutes = Router();
const REMOTE_WRITE_ACCESS_ERROR =
'Remote dashboard writes require localhost access when dashboard auth is disabled.';
function isMutationMethod(method: string): boolean {
const normalized = method.toUpperCase();
return (
normalized === 'POST' ||
normalized === 'PUT' ||
normalized === 'PATCH' ||
normalized === 'DELETE'
);
}
apiRoutes.use((req, res, next) => {
if (!isMutationMethod(req.method)) {
next();
return;
}
if (requireLocalAccessWhenAuthDisabled(req, res, REMOTE_WRITE_ACCESS_ERROR)) {
next();
}
});
// ==================== Profile & Settings ====================
// Profile CRUD, settings management, presets, accounts
apiRoutes.use('/profiles', profileRoutes);