Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

fix(security): count HEAD requests against the same rate limit rule as GET

spacesdrive689e16ccc2b9
diff --git a/backend/lib/rateLimit/rules.ts b/backend/lib/rateLimit/rules.ts
index 9c4cf28..497a299 100644
--- a/backend/lib/rateLimit/rules.ts
+++ b/backend/lib/rateLimit/rules.ts
@@ -58,6 +58,8 @@ export const PUBLISH_ROUTES: readonly RouteMatcher[] = [
{ methods: ['POST'], path: /^\/api\/accounts\/[^/]+\/(ig-publish|ig-media-publish)$/ },
];
+// Hono answers HEAD with the GET handler, so a HEAD request counts against the same rule as GET
export function matchesRoute(routes: readonly RouteMatcher[], method: string, path: string): boolean {
- return routes.some(route => route.methods.includes(method) && route.path.test(path));
+ const routed = method === 'HEAD' ? 'GET' : method;
+ return routes.some(route => route.methods.includes(routed) && route.path.test(path));
}
diff --git a/backend/tests/middleware/rateLimit.test.ts b/backend/tests/middleware/rateLimit.test.ts
index 9c6345e..2a761a4 100644
--- a/backend/tests/middleware/rateLimit.test.ts
+++ b/backend/tests/middleware/rateLimit.test.ts
@@ -132,6 +132,8 @@ test('quota and publish routes match the endpoints that spend platform API calls
assert.equal(quota('PUT', '/api/tracked-content/abc'), false);
assert.equal(quota('POST', '/api/tracked-content/abc/refresh'), true);
assert.equal(quota('GET', '/api/process-scheduled'), true);
+ // Hono answers HEAD with the GET handler, so HEAD cannot slip past the rule
+ assert.equal(quota('HEAD', '/api/process-scheduled'), true);
assert.equal(quota('POST', '/api/automations/accounts/ig1/subscribe'), true);
assert.equal(quota('PUT', '/api/automations/accounts/ig1'), false);
assert.equal(quota('GET', '/api/accounts/abc123/analytics'), false);