nestjs-security-cli 2.0.0 → 2.0.1

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.
Files changed (2) hide show
  1. package/README.md +30 -41
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -29,7 +29,23 @@ import { SecurityModule, BlacklistedIp, BlacklistedIpSchema, SecurityMiddleware
29
29
  useFactory: () => ({
30
30
  enableDatabase: true,
31
31
  defaultBlockDurationHours: 24,
32
- enableAutoBlocking: true
32
+ enableAutoBlocking: true,
33
+ // example of customizing the suspicious patterns
34
+ suspiciousPatterns: [
35
+ { pattern: '/vendor', name: 'Composer Attempt' },
36
+ { pattern: '/phpunit', name: 'PHPUnit Attempt' },
37
+ { pattern: '/lib', name: 'Lib Attempt' },
38
+ { pattern: '/laravel', name: 'Laravel Attempt' },
39
+ { pattern: '/www', name: 'WWW Attempt' },
40
+ { pattern: '/ws', name: 'Web Socket Attempt' },
41
+ { pattern: '/yii', name: 'Yii Attempt' },
42
+ { pattern: '/zend', name: 'Zend Attempt' },
43
+ { pattern: '/test', name: 'Test Attempt' },
44
+ { pattern: '/tests', name: 'Tests Attempt' },
45
+ { pattern: '/testing', name: 'Testing Attempt' },
46
+ { pattern: '/cms', name: 'CMS Attempt' },
47
+ { pattern: '/crm', name: 'CRM Attempt' }
48
+ ]
33
49
  }),
34
50
  imports: [ MongoDbModule ],
35
51
  providers: [ ...IpBlockerProvider ]
@@ -37,11 +53,6 @@ import { SecurityModule, BlacklistedIp, BlacklistedIpSchema, SecurityMiddleware
37
53
  ]
38
54
  } )
39
55
  export class AppModule {
40
- configure(consumer: MiddlewareConsumer): void {
41
- consumer
42
- .apply( SecurityMiddleware )
43
- .forRoutes( { path: '*', method: RequestMethod.ALL } )
44
- }
45
56
  }
46
57
  ```
47
58
 
@@ -85,13 +96,7 @@ import { SecurityModule, BlacklistedIp, BlacklistedIpSchema } from 'nestjs-secur
85
96
  export class AppModule {
86
97
  }
87
98
 
88
- export class AppModule {
89
- configure(consumer: MiddlewareConsumer): void {
90
- consumer
91
- .apply( SecurityMiddleware )
92
- .forRoutes( { path: '*', method: RequestMethod.ALL } )
93
- }
94
- }
99
+ export class AppModule {}
95
100
  ```
96
101
 
97
102
  ## Cache-Only Mode (No Database)
@@ -111,13 +116,7 @@ import { SecurityModule } from 'nestjs-security-cli'
111
116
  } )
112
117
  ]
113
118
  } )
114
- export class AppModule {
115
- configure(consumer: MiddlewareConsumer): void {
116
- consumer
117
- .apply( SecurityMiddleware )
118
- .forRoutes( { path: '*', method: RequestMethod.ALL } )
119
- }
120
- }
119
+ export class AppModule {}
121
120
  ````
122
121
 
123
122
  ## SecurityService
@@ -127,8 +126,7 @@ IpBlockerProvider, it will automatically register the model. More on this down b
127
126
 
128
127
  ## Clean up cron
129
128
 
130
- There's a cron that runs to clean up old blocks. By default, it runs every 10 minutes. You can change this by setting
131
- the
129
+ There's a cron that runs to clean up old blocks. By default, it runs every day at midnight.
132
130
  `CLEANUP_CRON` environment variable.
133
131
 
134
132
  ```text
@@ -152,28 +150,19 @@ export type Role = 'Admin' | 'User' | 'Moderator' | 'Guest'
152
150
  ```
153
151
 
154
152
  ## Register the IpBlacklistGuard globally
155
-
156
- ```typescript
157
- import { Module, APP_GUARD } from '@nestjs/common'
158
- /* other imports */
159
- import { IpBlacklistGuard } from 'nestjs-security-cli'
160
-
161
- @Module( {
162
- imports: [
163
- /* other imports */
164
- ],
165
- providers: [
166
- {
167
- provide: APP_GUARD,
168
- useClass: IpBlacklistGuard // Register globally
169
- }
170
- ]
171
- } )
172
- export class AppModule {
153
+ ### this is no longer needed, since the SecurityModule is now registered globally by default
154
+ All you have to do is apply the guard to your controllers.
155
+ ```
156
+ @UseGuards(IpBlacklistGuard) // add this to any, or all controller endpoints
157
+ @Controller()
158
+ export class AppController {
159
+ @Get()
160
+ someEndpoint(): object {
161
+ return { message: 'Hello World!' }
162
+ }
173
163
  }
174
164
  ```
175
165
 
176
- And then in your controllers simply use the `@UseGuards(IpBlacklistGuard)` decorator.
177
166
 
178
167
  ## Admin & Roles guards
179
168
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-security-cli",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Advanced IP blocking, role-based security, and attack detection for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",