fix(usage): block remote refresh without auth

This commit is contained in:
Tam Nhu Tran committed 2026-04-07 07:04:57 -04:00
1 parent 5fbe731341
commit 1603f19388
2 files changed
+107

No files matched your search

+15
View File
@@ -8,6 +8,7 @@
*/
import { Router } from 'express';
import { requireLocalAccessWhenAuthDisabled } from '../middleware/auth-middleware';
import {
handleSummary,
handleDaily,
@@ -24,6 +25,20 @@ export { prewarmUsageCache, clearUsageCache, getLastFetchTimestamp } from './agg
export const usageRoutes = Router();
const USAGE_WRITE_ACCESS_ERROR =
'Usage refresh requires localhost access when dashboard auth is disabled.';
usageRoutes.use((req, res, next) => {
if (req.method.toUpperCase() !== 'POST') {
next();
return;
}
if (requireLocalAccessWhenAuthDisabled(req, res, USAGE_WRITE_ACCESS_ERROR)) {
next();
}
});
// Summary endpoint
usageRoutes.get('/summary', handleSummary);