diff --git a/package-lock.json b/package-lock.json index 5ffa5f9c920c..d75306126004 100644 --- a/package-lock.json +++ b/package-lock.json @@ -154,8 +154,8 @@ "sass": "^1.52.3", "start-server-and-test": "^2.0.3", "ts-jest": "29.1.1", - "tsx": "4.7.0", - "typescript": "^5.2.2", + "tsx": "4.7.1", + "typescript": "^5.3.3", "unist-util-remove": "^4.0.0", "unist-util-visit-parents": "6.0.1", "website-scraper": "^5.3.1" @@ -15279,9 +15279,9 @@ "integrity": "sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w==" }, "node_modules/tsx": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.7.0.tgz", - "integrity": "sha512-I+t79RYPlEYlHn9a+KzwrvEwhJg35h/1zHsLC2JXvhC2mdynMv6Zxzvhv5EMV6VF5qJlLlkSnMVvdZV3PSIGcg==", + "version": "4.7.1", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.7.1.tgz", + "integrity": "sha512-8d6VuibXHtlN5E3zFkgY8u4DX7Y3Z27zvvPKVmLon/D4AjuKzarkUBTLDBgj9iTQ0hg5xM7c/mYiRVM+HETf0g==", "dev": true, "dependencies": { "esbuild": "~0.19.10", @@ -15430,9 +15430,9 @@ } }, "node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", "dev": true, "bin": { "tsc": "bin/tsc", diff --git a/package.json b/package.json index 59446a416e7a..1b2002e3d83f 100644 --- a/package.json +++ b/package.json @@ -375,8 +375,8 @@ "sass": "^1.52.3", "start-server-and-test": "^2.0.3", "ts-jest": "29.1.1", - "tsx": "4.7.0", - "typescript": "^5.2.2", + "tsx": "4.7.1", + "typescript": "^5.3.3", "unist-util-remove": "^4.0.0", "unist-util-visit-parents": "6.0.1", "website-scraper": "^5.3.1" diff --git a/src/shielding/middleware/handle-invalid-headers.js b/src/shielding/middleware/handle-invalid-headers.js index a6cf2df894e1..243fdad7d692 100644 --- a/src/shielding/middleware/handle-invalid-headers.js +++ b/src/shielding/middleware/handle-invalid-headers.js @@ -1,8 +1,3 @@ -import statsd from '#src/observability/lib/statsd.js' -import { errorCacheControl } from '#src/frame/middleware/cache-control.js' - -const STATSD_KEY = 'middleware.handle_invalid_headers' - const INVALID_HEADER_KEYS = [ // Next.js will pick this up and override the status code. // We don't want that to happen because `x-invoke-status: 203` can @@ -15,14 +10,9 @@ const INVALID_HEADER_KEYS = [ export default function handleInvalidNextPaths(req, res, next) { const header = INVALID_HEADER_KEYS.find((key) => req.headers[key]) if (header) { - // This way you can't hammer the backend with invalid requests. - // Since the CDN will cache based on the status code not being one - // of success, we don't have to worry about this being cached when - // the URL is the same but the headers *not invalid*. - errorCacheControl(res) - - const tags = [`ip:${req.ip}`, `path:${req.path}`, `header:${header}`] - statsd.increment(STATSD_KEY, 1, tags) + // There's no point attempting to set a cache-control on this. + // The CDN will not cache if the status code is not a success + // and not a 404. return res.status(400).type('text').send('Invalid request headers') } diff --git a/src/shielding/tests/invalid-headers.js b/src/shielding/tests/invalid-headers.js index 2a28511014d8..240db4b15403 100644 --- a/src/shielding/tests/invalid-headers.js +++ b/src/shielding/tests/invalid-headers.js @@ -4,13 +4,9 @@ describe('invalid headers', () => { test('400 if containing x-invoke-status (instead of redirecting)', async () => { const res = await get('/', { headers: { 'x-invoke-status': '203' } }) expect(res.statusCode).toBe(400) - expect(res.headers['cache-control']).toMatch('public') - expect(res.headers['cache-control']).toMatch(/max-age=[1-9]/) }) test('400 if containing x-invoke-status (instead of 200)', async () => { const res = await get('/en', { headers: { 'x-invoke-status': '203' } }) expect(res.statusCode).toBe(400) - expect(res.headers['cache-control']).toMatch('public') - expect(res.headers['cache-control']).toMatch(/max-age=[1-9]/) }) })