mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-16 08:14:45 +00:00
fix(usage): block remote refresh without auth
This commit is contained in:
1 parent
5fbe731341
commit
1603f19388
2 files changed
+107
No files matched your search
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user