Force no-store header on server error and rate limit responses

This commit is contained in:
Alex Gleason 2025-01-23 15:23:48 -06:00
parent afa0a337d3
commit 3fdd6e2213
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 6 additions and 0 deletions

View file

@ -2,6 +2,8 @@ import { ErrorHandler } from '@hono/hono';
import { HTTPException } from '@hono/hono/http-exception';
export const errorHandler: ErrorHandler = (err, c) => {
c.header('Cache-Control', 'no-store');
if (err instanceof HTTPException) {
if (err.res) {
return err.res;

View file

@ -9,6 +9,10 @@ export function rateLimitMiddleware(limit: number, windowMs: number): Middleware
return rateLimiter({
limit,
windowMs,
handler: (c) => {
c.header('Cache-Control', 'no-store');
return c.text('Too many requests, please try again later.', 429);
},
skip: (c) => !c.req.header('x-real-ip'),
keyGenerator: (c) => c.req.header('x-real-ip')!,
});