mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-14 00:16:38 +00:00
fix(web-server): block remote dashboard writes
This commit is contained in:
1 parent
431c22a16a
commit
5fbe731341
2 files changed
+150
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user