Skip to content

Commit 2152e20

Browse files
authoredMar 21, 2025
Remove server rate limit code (#54950)
1 parent 82aa30f commit 2152e20

File tree

4 files changed

+0
-319
lines changed

4 files changed

+0
-319
lines changed
 

‎src/shielding/lib/fastly-ips.ts

-81
This file was deleted.

‎src/shielding/middleware/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import handleOldNextDataPaths from './handle-old-next-data-paths'
66
import handleInvalidQuerystringValues from './handle-invalid-query-string-values'
77
import handleInvalidNextPaths from './handle-invalid-nextjs-paths'
88
import handleInvalidHeaders from './handle-invalid-headers'
9-
import { createRateLimiter } from './rate-limit'
109

1110
const router = express.Router()
1211

13-
router.use(createRateLimiter())
1412
router.use(handleInvalidQuerystrings)
1513
router.use(handleInvalidPaths)
1614
router.use(handleOldNextDataPaths)

‎src/shielding/middleware/rate-limit.ts

-168
This file was deleted.

‎src/shielding/tests/shielding.ts

-68
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { describe, expect, test } from 'vitest'
22

33
import { SURROGATE_ENUMS } from '@/frame/middleware/set-fastly-surrogate-key.js'
44
import { get } from '@/tests/helpers/e2etest.js'
5-
import { DEFAULT_FASTLY_IPS } from '@/shielding/lib/fastly-ips'
65

76
describe('honeypotting', () => {
87
test('any GET with survey-vote and survey-token query strings is 400', async () => {
@@ -95,73 +94,6 @@ describe('index.md and .md suffixes', () => {
9594
})
9695
})
9796

98-
describe('rate limiting', () => {
99-
// We can't actually trigger a full rate limit because
100-
// then all other tests will all fail. And we can't rely on this
101-
// test always being run last.
102-
103-
test('only happens if you have junk query strings', async () => {
104-
const res = await get('/robots.txt?foo=bar', {
105-
headers: {
106-
// Rate limiting only happens in production, so we need to
107-
// make the environment look like production.
108-
'fastly-client-ip': 'abc',
109-
},
110-
})
111-
expect(res.statusCode).toBe(200)
112-
const limit = parseInt(res.headers['ratelimit-limit'])
113-
const remaining = parseInt(res.headers['ratelimit-remaining'])
114-
expect(limit).toBeGreaterThan(0)
115-
expect(remaining).toBeLessThan(limit)
116-
117-
// A second request
118-
{
119-
const res = await get('/robots.txt?foo=buzz', {
120-
headers: {
121-
'fastly-client-ip': 'abc',
122-
},
123-
})
124-
expect(res.statusCode).toBe(200)
125-
const newLimit = parseInt(res.headers['ratelimit-limit'])
126-
const newRemaining = parseInt(res.headers['ratelimit-remaining'])
127-
expect(newLimit).toBe(limit)
128-
// Can't rely on `newRemaining == remaining - 1` because of
129-
// concurrency of test-running.
130-
expect(newRemaining).toBeLessThan(remaining)
131-
}
132-
})
133-
134-
test('nothing happens if no unrecognized query string', async () => {
135-
const res = await get('/robots.txt')
136-
expect(res.statusCode).toBe(200)
137-
expect(res.headers['ratelimit-limit']).toBeUndefined()
138-
expect(res.headers['ratelimit-remaining']).toBeUndefined()
139-
})
140-
141-
test('Fastly IPs are not rate limited', async () => {
142-
// Fastly IPs are in the form `X.X.X.X/Y`
143-
// Rate limited IPs are in the form `X.X.X.X`
144-
// Where the last X could be any 2-3 digit number
145-
const mockFastlyIP =
146-
DEFAULT_FASTLY_IPS[0].split('.').slice(0, 3).join('.') + `.${Math.floor(Math.random() * 100)}`
147-
// Cookies only allows 1 request per minute
148-
const res1 = await get('/api/cookies', {
149-
headers: {
150-
'fastly-client-ip': mockFastlyIP,
151-
},
152-
})
153-
expect(res1.statusCode).toBe(200)
154-
155-
// A second request shouldn't be rate limited because it's from a Fastly IP
156-
const res2 = await get('/api/cookies', {
157-
headers: {
158-
'fastly-client-ip': mockFastlyIP,
159-
},
160-
})
161-
expect(res2.statusCode).toBe(200)
162-
})
163-
})
164-
16597
describe('404 pages and their content-type', () => {
16698
const exampleNonLanguage404plain = ['/_next/image/foo']
16799
test.each(exampleNonLanguage404plain)(

0 commit comments

Comments
 (0)
Failed to load comments.