nestjs-security-cli 1.5.9 → 1.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Advanced IP blocking, role-based security, and attack detection for NestJS applications.
|
|
4
4
|
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js >= 22.x
|
|
8
|
+
- NestJS >= 11.x
|
|
9
|
+
- TypeScript >= 5.x
|
|
10
|
+
- You'll need to maintain the `@nestjs/cache-manager` and `cache-manager` packages.
|
|
11
|
+
|
|
5
12
|
## Installation
|
|
6
13
|
|
|
7
14
|
```bash
|
|
@@ -18,15 +25,13 @@ import { SecurityModule, BlacklistedIp, BlacklistedIpSchema, SecurityMiddleware
|
|
|
18
25
|
@Module( {
|
|
19
26
|
imports: [
|
|
20
27
|
SecurityModule.forRootAsync( {
|
|
21
|
-
enableAdminPanel: true,
|
|
28
|
+
enableAdminPanel: true,
|
|
22
29
|
useFactory: () => ({
|
|
23
30
|
enableDatabase: true,
|
|
24
31
|
defaultBlockDurationHours: 24,
|
|
25
32
|
enableAutoBlocking: true
|
|
26
33
|
}),
|
|
27
|
-
|
|
28
|
-
// Below required if enableDatabase is true
|
|
29
|
-
imports: [ MongoDbModule ], // This should be your mongoose connection
|
|
34
|
+
imports: [ MongoDbModule ],
|
|
30
35
|
providers: [ ...IpBlockerProvider ]
|
|
31
36
|
} )
|
|
32
37
|
]
|
|
@@ -45,7 +50,7 @@ export class AppModule {
|
|
|
45
50
|
if you're needing to use the database connection, and the import options isn't working, you can try to pass it directly
|
|
46
51
|
into the providers array.
|
|
47
52
|
|
|
48
|
-
```
|
|
53
|
+
```text
|
|
49
54
|
{
|
|
50
55
|
provide: 'DATABASE_CONNECTION',
|
|
51
56
|
inject: [ConfigService],
|
|
@@ -126,7 +131,7 @@ There's a cron that runs to clean up old blocks. By default, it runs every 10 mi
|
|
|
126
131
|
the
|
|
127
132
|
`CLEANUP_CRON` environment variable.
|
|
128
133
|
|
|
129
|
-
```
|
|
134
|
+
```text
|
|
130
135
|
// Cleanup expired entries (runs daily)
|
|
131
136
|
@Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)
|
|
132
137
|
async cleanupExpiredBlocks(): Promise<void> {
|
|
@@ -138,44 +143,14 @@ the
|
|
|
138
143
|
}
|
|
139
144
|
```
|
|
140
145
|
|
|
141
|
-
##
|
|
146
|
+
## Role type
|
|
142
147
|
|
|
143
148
|
The roles that can be defined in your app. Persist the roles in your user model as an array of strings.
|
|
144
149
|
|
|
145
|
-
```
|
|
150
|
+
```text
|
|
146
151
|
export type Role = 'Admin' | 'User' | 'Moderator' | 'Guest'
|
|
147
152
|
```
|
|
148
153
|
|
|
149
|
-
## Config Options
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
export interface SecurityConfigInterface {
|
|
153
|
-
enableDatabase?: boolean
|
|
154
|
-
mongooseConnection?: string
|
|
155
|
-
cache?: {
|
|
156
|
-
ttl?: number
|
|
157
|
-
max?: number
|
|
158
|
-
store?: any
|
|
159
|
-
}
|
|
160
|
-
enableAdminPanel?: boolean
|
|
161
|
-
adminPath?: string
|
|
162
|
-
enableAutoBlocking?: boolean
|
|
163
|
-
suspiciousPatterns?: Array<{
|
|
164
|
-
pattern: string
|
|
165
|
-
name: string
|
|
166
|
-
blockDurationHours?: number
|
|
167
|
-
}>
|
|
168
|
-
defaultBlockDurationHours?: number
|
|
169
|
-
enableRateLimit?: boolean
|
|
170
|
-
rateLimitOptions?: {
|
|
171
|
-
windowMs?: number
|
|
172
|
-
max?: number
|
|
173
|
-
}
|
|
174
|
-
enableLogging?: boolean
|
|
175
|
-
logLevel?: 'error' | 'warn' | 'info' | 'debug'
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
154
|
## Register the IpBlacklistGuard globally
|
|
180
155
|
|
|
181
156
|
```typescript
|
|
@@ -203,9 +178,9 @@ And then in your controllers simply use the `@UseGuards(IpBlacklistGuard)` decor
|
|
|
203
178
|
## Admin & Roles guards
|
|
204
179
|
|
|
205
180
|
* The Admin guard accepts ONLY users with the role `Admin`.
|
|
206
|
-
* The Role guard accepts users with ane of (or all) the type "Roles" [as mentioned above](#
|
|
181
|
+
* The Role guard accepts users with ane of (or all) the type "Roles" [as mentioned above](#role-type).
|
|
207
182
|
* To leverage the admin panel, you'll need to create a role called `Admin`. The user model in your app should have a
|
|
208
|
-
field called "Roles" which is an array of strings.
|
|
183
|
+
field called "Roles", which is an array of strings.
|
|
209
184
|
|
|
210
185
|
To use the `AdminGuard` just add the decorator to your controller method.
|
|
211
186
|
|
|
@@ -233,10 +208,10 @@ const user = await this.jwtService.verifyAsync( token, {
|
|
|
233
208
|
} )
|
|
234
209
|
```
|
|
235
210
|
|
|
236
|
-
## The
|
|
211
|
+
## The admin panel
|
|
237
212
|
|
|
238
|
-
To use the built
|
|
239
|
-
configs [as shown in the](#quick-start)
|
|
213
|
+
To use the built-in admin panel, you can set the `enableAdminPanel: true` in the
|
|
214
|
+
configs [as shown in the](#quick-start) to set the available endpoints.
|
|
240
215
|
|
|
241
216
|
Available endpoints:
|
|
242
217
|
|
|
@@ -292,12 +267,6 @@ export interface SecurityConfigInterface {
|
|
|
292
267
|
|
|
293
268
|
[coming soon]
|
|
294
269
|
|
|
295
|
-
## Requirements
|
|
296
|
-
|
|
297
|
-
- Node.js >= 16.0.0
|
|
298
|
-
- NestJS >= 10.0.0
|
|
299
|
-
- TypeScript >= 5.0.0
|
|
300
|
-
|
|
301
270
|
## License
|
|
302
271
|
|
|
303
272
|
MIT
|
|
@@ -22,7 +22,6 @@ exports.suspiciousPatterns = [
|
|
|
22
22
|
{ pattern: '../../', name: 'Path Traversal' },
|
|
23
23
|
{ pattern: '%2e%2e', name: 'Encoded Path Traversal' },
|
|
24
24
|
{ pattern: '/bin/sh', name: 'Shell Execution' },
|
|
25
|
-
{ pattern: '/favicon.ico', name: 'Favicon' },
|
|
26
25
|
{ pattern: '/robots.txt', name: 'Robots.txt' },
|
|
27
26
|
{ pattern: '/.well-known', name: 'Well-Known Directory' },
|
|
28
27
|
{ pattern: '/wp-admin', name: 'WordPress Admin Panel' },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ip-blacklist.guard.js","sourceRoot":"","sources":["../../src/guards/ip-blacklist.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA8F;AAC9F,mEAA8D;AAEjD,QAAA,kBAAkB,GAAG;IACjC,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,sBAAsB,EAAE;IACnD,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE;IACnD,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,qBAAqB,EAAE;IACpD,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,mBAAmB,EAAE;IACnD,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,kBAAkB,EAAE;IAClD,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,uBAAuB,EAAE;IACvD,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,gBAAgB,EAAE;IAC7C,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,wBAAwB,EAAE;IACrD,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,iBAAiB,EAAE;
|
|
1
|
+
{"version":3,"file":"ip-blacklist.guard.js","sourceRoot":"","sources":["../../src/guards/ip-blacklist.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA8F;AAC9F,mEAA8D;AAEjD,QAAA,kBAAkB,GAAG;IACjC,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,sBAAsB,EAAE;IACnD,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE;IACnD,EAAE,OAAO,EAAE,UAAU,EAAE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