+
+ RateLimit tests Route
+
+
diff --git a/src/defaultConfig.ts b/src/defaultConfig.ts
index aa46f987..44e67d78 100644
--- a/src/defaultConfig.ts
+++ b/src/defaultConfig.ts
@@ -55,6 +55,7 @@ export const defaultSecurityConfig = (serverlUrl: string, strict: boolean) => {
driver: {
name: 'lruCache'
},
+ whiteList: undefined,
...defaultThrowErrorValue
},
xssValidator: {
diff --git a/src/runtime/server/middleware/rateLimiter.ts b/src/runtime/server/middleware/rateLimiter.ts
index d8421f14..5b17f46e 100644
--- a/src/runtime/server/middleware/rateLimiter.ts
+++ b/src/runtime/server/middleware/rateLimiter.ts
@@ -28,6 +28,9 @@ export default defineEventHandler(async(event) => {
defaultRateLimiter
)
const ip = getIP(event)
+ if(rateLimiter.whiteList && rateLimiter.whiteList.includes(ip)){
+ return
+ }
const url = ip + route
let storageItem = await storage.getItem(url) as StorageItem
diff --git a/src/types/middlewares.ts b/src/types/middlewares.ts
index 7359aaa6..fcfdab38 100644
--- a/src/types/middlewares.ts
+++ b/src/types/middlewares.ts
@@ -19,6 +19,7 @@ export type RateLimiter = {
options?: BuiltinDriverOptions[driverName] }
}[BuiltinDriverName];
headers?: boolean;
+ whiteList?: string[];
throwError?: boolean;
};
diff --git a/test/fixtures/rateLimiter/nuxt.config.ts b/test/fixtures/rateLimiter/nuxt.config.ts
index 276ce3a0..de35fc0a 100644
--- a/test/fixtures/rateLimiter/nuxt.config.ts
+++ b/test/fixtures/rateLimiter/nuxt.config.ts
@@ -15,6 +15,68 @@ export default defineNuxtConfig({
tokensPerInterval: 10,
}
}
- }
+ },
+ '/whitelistBase': {
+ security: {
+ rateLimiter: {
+ tokensPerInterval: 1,
+ interval: 300000,
+ whiteList: [
+ '127.0.0.1',
+ '192.168.0.1',
+ '172.16.0.1',
+ '10.0.0.1',
+ ],
+ }
+ }
+ },
+ '/whitelistEmpty': {
+ security: {
+ rateLimiter: {
+ tokensPerInterval: 1,
+ interval: 300000,
+ whiteList: [],
+ }
+ }
+ },
+ '/whitelistNotListed': {
+ security: {
+ rateLimiter: {
+ tokensPerInterval: 1,
+ interval: 300000,
+ whiteList: [
+ '10.0.0.1',
+ '10.0.1.1',
+ '10.0.2.1',
+ '10.0.3.1',
+ '10.0.4.1',
+ '10.0.5.1',
+ '10.0.6.1',
+ '10.0.7.1',
+ '10.0.8.1',
+ '10.0.9.1',
+ '10.1.0.1',
+ '10.2.0.1',
+ '10.3.0.1',
+ '10.4.0.1',
+ '10.5.0.1',
+ '10.6.0.1',
+ '10.7.0.1',
+ '10.8.0.1',
+ '10.9.0.1',
+ '192.168.0.1',
+ '192.168.1.1',
+ '192.168.2.1',
+ '192.168.3.1',
+ '192.168.4.1',
+ '192.168.5.1',
+ '192.168.6.1',
+ '192.168.7.1',
+ '192.168.8.1',
+ '192.168.9.1',
+ ],
+ }
+ }
+ },
}
})
diff --git a/test/fixtures/rateLimiter/pages/whitelistBase.vue b/test/fixtures/rateLimiter/pages/whitelistBase.vue
new file mode 100644
index 00000000..0e6f9208
--- /dev/null
+++ b/test/fixtures/rateLimiter/pages/whitelistBase.vue
@@ -0,0 +1,3 @@
+