nestjs-security-cli 1.0.0

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 (33) hide show
  1. package/README.md +41 -0
  2. package/dist/controllers/security.controller.d.ts +20 -0
  3. package/dist/controllers/security.controller.js +94 -0
  4. package/dist/controllers/security.controller.js.map +1 -0
  5. package/dist/decorators/roles.decorator.d.ts +3 -0
  6. package/dist/decorators/roles.decorator.js +8 -0
  7. package/dist/decorators/roles.decorator.js.map +1 -0
  8. package/dist/guards/admin.guard.d.ts +8 -0
  9. package/dist/guards/admin.guard.js +56 -0
  10. package/dist/guards/admin.guard.js.map +1 -0
  11. package/dist/guards/ip-blacklist.guard.d.ts +13 -0
  12. package/dist/guards/ip-blacklist.guard.js +109 -0
  13. package/dist/guards/ip-blacklist.guard.js.map +1 -0
  14. package/dist/guards/roles.guard.d.ts +8 -0
  15. package/dist/guards/roles.guard.js +44 -0
  16. package/dist/guards/roles.guard.js.map +1 -0
  17. package/dist/index.d.ts +9 -0
  18. package/dist/index.js +21 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/interfaces/security-config.interface.d.ts +25 -0
  21. package/dist/interfaces/security-config.interface.js +3 -0
  22. package/dist/interfaces/security-config.interface.js.map +1 -0
  23. package/dist/schemas/blacklisted-ip.schema.d.ts +23 -0
  24. package/dist/schemas/blacklisted-ip.schema.js +69 -0
  25. package/dist/schemas/blacklisted-ip.schema.js.map +1 -0
  26. package/dist/security.module.d.ts +2 -0
  27. package/dist/security.module.js +47 -0
  28. package/dist/security.module.js.map +1 -0
  29. package/dist/services/security.service.d.ts +24 -0
  30. package/dist/services/security.service.js +126 -0
  31. package/dist/services/security.service.js.map +1 -0
  32. package/dist/tsconfig.tsbuildinfo +1 -0
  33. package/package.json +56 -0
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # NestJS Security CLI
2
+
3
+ Advanced IP blocking, role-based security, and attack detection for NestJS applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install nestjs-security-cli
9
+ ```
10
+
11
+ ## Qucik Start
12
+ ```
13
+ import { Module } from '@nestjs/common';
14
+ import { SecurityShieldModule } from 'nestjs-security-cli';
15
+
16
+ @Module({
17
+ imports: [
18
+ SecurityShieldModule.forRoot({
19
+ enableDatabase: true,
20
+ mongooseConnection: 'mongodb://localhost:27017/myapp',
21
+ defaultBlockDurationHours: 24,
22
+ enableAutoBlocking: true,
23
+ }),
24
+ ],
25
+ })
26
+ export class AppModule {}
27
+ ```
28
+
29
+ ## Features
30
+ - 🛡️ IP Blacklisting with MongoDB persistence
31
+ - 🚫 Automatic attack pattern detection
32
+ - ⚡ Redis/Memory caching for fast lookups
33
+ - 👥 Role-based access control (RBAC)
34
+ - 📊 Security analytics and reporting
35
+ - ⏰ Scheduled cleanup of expired blocks
36
+
37
+ ## API Documentation
38
+ [need to add api docs]
39
+
40
+ ## License
41
+ MIT
@@ -0,0 +1,20 @@
1
+ import { SecurityService } from '../services/security.service';
2
+ export declare class SecurityController {
3
+ private readonly securityService;
4
+ constructor(securityService: SecurityService);
5
+ blacklistIp(body: {
6
+ ip: string;
7
+ hours?: number;
8
+ reason?: string;
9
+ }, req: any): Promise<{
10
+ message: string;
11
+ }>;
12
+ removeFromBlacklist(ip: string): Promise<{
13
+ message: string;
14
+ }>;
15
+ getBlacklisted(query: any): Promise<any[]>;
16
+ getAnalytics(days?: string): Promise<any>;
17
+ blockMalwareIp(req: any): Promise<{
18
+ message: string;
19
+ }>;
20
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SecurityController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const security_service_1 = require("../services/security.service");
18
+ const admin_guard_1 = require("../guards/admin.guard");
19
+ let SecurityController = class SecurityController {
20
+ constructor(securityService) {
21
+ this.securityService = securityService;
22
+ }
23
+ async blacklistIp(body, req) {
24
+ const { ip, hours = 24, reason = 'Manual blacklist' } = body;
25
+ const blockedBy = req.user?._id || req.user?.id;
26
+ await this.securityService.blacklistIp(ip, hours, reason, blockedBy);
27
+ return { message: `IP ${ip} blacklisted for ${hours} hours` };
28
+ }
29
+ async removeFromBlacklist(ip) {
30
+ await this.securityService.removeFromBlacklist(ip);
31
+ return { message: `IP ${ip} removed from blacklist` };
32
+ }
33
+ async getBlacklisted(query) {
34
+ const options = {
35
+ active: query.active !== 'false',
36
+ limit: parseInt(query.limit) || 50,
37
+ skip: parseInt(query.skip) || 0,
38
+ sortBy: query.sortBy || 'createdAt',
39
+ sortOrder: query.sortOrder || 'desc'
40
+ };
41
+ return await this.securityService.getBlacklistedIps(options);
42
+ }
43
+ async getAnalytics(days = '7') {
44
+ return await this.securityService.getSecurityAnalytics(parseInt(days));
45
+ }
46
+ async blockMalwareIp(req) {
47
+ const blockedBy = req.user?._id || req.user?.id;
48
+ await this.securityService.blacklistIp('94.69.234.122', 24 * 30, 'Malware deployment attempt', blockedBy);
49
+ return { message: 'Malware IP blocked for 30 days' };
50
+ }
51
+ };
52
+ exports.SecurityController = SecurityController;
53
+ __decorate([
54
+ (0, common_1.Post)('blacklist'),
55
+ __param(0, (0, common_1.Body)()),
56
+ __param(1, (0, common_1.Req)()),
57
+ __metadata("design:type", Function),
58
+ __metadata("design:paramtypes", [Object, Object]),
59
+ __metadata("design:returntype", Promise)
60
+ ], SecurityController.prototype, "blacklistIp", null);
61
+ __decorate([
62
+ (0, common_1.Delete)('blacklist/:ip'),
63
+ __param(0, (0, common_1.Param)('ip')),
64
+ __metadata("design:type", Function),
65
+ __metadata("design:paramtypes", [String]),
66
+ __metadata("design:returntype", Promise)
67
+ ], SecurityController.prototype, "removeFromBlacklist", null);
68
+ __decorate([
69
+ (0, common_1.Get)('blacklist'),
70
+ __param(0, (0, common_1.Query)()),
71
+ __metadata("design:type", Function),
72
+ __metadata("design:paramtypes", [Object]),
73
+ __metadata("design:returntype", Promise)
74
+ ], SecurityController.prototype, "getBlacklisted", null);
75
+ __decorate([
76
+ (0, common_1.Get)('analytics'),
77
+ __param(0, (0, common_1.Query)('days')),
78
+ __metadata("design:type", Function),
79
+ __metadata("design:paramtypes", [String]),
80
+ __metadata("design:returntype", Promise)
81
+ ], SecurityController.prototype, "getAnalytics", null);
82
+ __decorate([
83
+ (0, common_1.Post)('block-malware-ip'),
84
+ __param(0, (0, common_1.Req)()),
85
+ __metadata("design:type", Function),
86
+ __metadata("design:paramtypes", [Object]),
87
+ __metadata("design:returntype", Promise)
88
+ ], SecurityController.prototype, "blockMalwareIp", null);
89
+ exports.SecurityController = SecurityController = __decorate([
90
+ (0, common_1.UseGuards)(admin_guard_1.AdminGuard),
91
+ (0, common_1.Controller)('security'),
92
+ __metadata("design:paramtypes", [security_service_1.SecurityService])
93
+ ], SecurityController);
94
+ //# sourceMappingURL=security.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.controller.js","sourceRoot":"","sources":["../../src/controllers/security.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAkG;AAClG,mEAA8D;AAC9D,uDAAkD;AAI3C,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC9B,YAA6B,eA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AC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;IACvE,CAAC;IAGK,AAAN,KAAK,CAAC,cAAc,CAAQ,GAAQ;QACnC,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAA;QAC/C,MAAM,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,eAAe,EAAE,EAAE,GAAG,EAAE,EAAE,4BAA4B,EAAE,SAAS,CAAC,CAAA;QACzG,OAAO,EAAE,OAAO,EAAE,gCAAgC,EAAE,CAAA;IACrD,CAAC;CACD,CAAA;AAzCY,gDAAkB;AAIxB;IADL,IAAA,aAAI,EAAC,WAAW,CAAC;IACC,WAAA,IAAA,aAAI,GAAE,CAAA;IAAyD,WAAA,IAAA,YAAG,GAAE,CAAA;;;;qDAMtF;AAGK;IADL,IAAA,eAAM,EAAC,eAAe,CAAC;IACG,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;6DAGrC;AAGK;IADL,IAAA,YAAG,EAAC,WAAW,CAAC;IACK,WAAA,IAAA,cAAK,GAAE,CAAA;;;;wDAS5B;AAGK;IADL,IAAA,YAAG,EAAC,WAAW,CAAC;IACG,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;;;;sDAEhC;AAGK;IADL,IAAA,aAAI,EAAC,kBAAkB,CAAC;IACH,WAAA,IAAA,YAAG,GAAE,CAAA;;;;wDAI1B;6BAxCW,kBAAkB;IAF9B,IAAA,kBAAS,EAAC,wBAAU,CAAC;IACrB,IAAA,mBAAU,EAAC,UAAU,CAAC;qCAEwB,kCAAe;GADjD,kBAAkB,CAyC9B"}
@@ -0,0 +1,3 @@
1
+ import type { Role } from '../guards/roles.guard';
2
+ export declare const ROLES_KEY = "roles";
3
+ export declare const Roles: (...roles: Role[]) => import("@nestjs/common").CustomDecorator<string>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Roles = exports.ROLES_KEY = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.ROLES_KEY = 'roles';
6
+ const Roles = (...roles) => (0, common_1.SetMetadata)(exports.ROLES_KEY, roles);
7
+ exports.Roles = Roles;
8
+ //# sourceMappingURL=roles.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.decorator.js","sourceRoot":"","sources":["../../src/decorators/roles.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAG/B,QAAA,SAAS,GAAG,OAAO,CAAA;AACzB,MAAM,KAAK,GAAG,CAAC,GAAG,KAAa,EAAE,EAAE,CAAC,IAAA,oBAAW,EAAC,iBAAS,EAAE,KAAK,CAAC,CAAA;AAA3D,QAAA,KAAK,SAAsD"}
@@ -0,0 +1,8 @@
1
+ import { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ export declare class AdminGuard implements CanActivate {
3
+ private readonly logger;
4
+ private readonly jwtService;
5
+ private readonly configService;
6
+ canActivate(context: ExecutionContext): Promise<boolean>;
7
+ private extractTokenFromCookie;
8
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AdminGuard = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const jwt_1 = require("@nestjs/jwt");
12
+ const config_1 = require("@nestjs/config");
13
+ const common_2 = require("@nestjs/common");
14
+ let AdminGuard = class AdminGuard {
15
+ constructor() {
16
+ this.logger = new common_2.Logger('AdminGuard');
17
+ this.jwtService = new jwt_1.JwtService();
18
+ this.configService = new config_1.ConfigService();
19
+ }
20
+ async canActivate(context) {
21
+ const request = context.switchToHttp().getRequest();
22
+ const token = this.extractTokenFromCookie(request);
23
+ if (!token) {
24
+ throw new common_1.UnauthorizedException('You are not logged in.');
25
+ }
26
+ try {
27
+ const user = await this.jwtService.verifyAsync(token, {
28
+ secret: this.configService.get('JWT_SECRET')
29
+ });
30
+ request.user = user;
31
+ if (!user.roles || !user.roles.includes('ADMIN')) {
32
+ throw new common_1.ForbiddenException('Access denied: Admin role required');
33
+ }
34
+ return true;
35
+ }
36
+ catch (err) {
37
+ this.logger.error('Authentication/Authorization error:', err?.message);
38
+ if (err instanceof common_1.ForbiddenException) {
39
+ throw err;
40
+ }
41
+ let description = err?.message ?? err;
42
+ if (err?.message === 'jwt expired') {
43
+ description = 'Your session has expired. Please login again.';
44
+ }
45
+ throw new common_1.UnauthorizedException(description);
46
+ }
47
+ }
48
+ extractTokenFromCookie(request) {
49
+ return request?.cookies?.access_token;
50
+ }
51
+ };
52
+ exports.AdminGuard = AdminGuard;
53
+ exports.AdminGuard = AdminGuard = __decorate([
54
+ (0, common_1.Injectable)()
55
+ ], AdminGuard);
56
+ //# sourceMappingURL=admin.guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.guard.js","sourceRoot":"","sources":["../../src/guards/admin.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAqH;AACrH,qCAAwC;AACxC,2CAA8C;AAE9C,2CAAuC;AAGhC,IAAM,UAAU,GAAhB,MAAM,UAAU;IAAhB;QACW,WAAM,GAAG,IAAI,eAAM,CAAC,YAAY,CAAC,CAAA;QACjC,eAAU,GAAG,IAAI,gBAAU,EAAE,CAAA;QAC7B,kBAAa,GAAG,IAAI,sBAAa,EAAE,CAAA;IA0CrD,CAAC;IAxCA,KAAK,CAAC,WAAW,CAAC,OAAyB;QAC1C,MAAM,OAAO,GA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AAU,GAAE;GACA,UAAU,CA6CtB"}
@@ -0,0 +1,13 @@
1
+ import { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import { SecurityService } from '../services/security.service';
3
+ export declare const suspiciousPatterns: {
4
+ pattern: string;
5
+ name: string;
6
+ }[];
7
+ export declare class IpBlacklistGuard implements CanActivate {
8
+ private readonly securityService;
9
+ constructor(securityService: SecurityService);
10
+ canActivate(context: ExecutionContext): Promise<boolean>;
11
+ private getClientIp;
12
+ private checkSuspiciousActivity;
13
+ }
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.IpBlacklistGuard = exports.suspiciousPatterns = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const security_service_1 = require("../services/security.service");
15
+ exports.suspiciousPatterns = [
16
+ { pattern: '/shell', name: 'Shell Access Attempt' },
17
+ { pattern: '/.env', name: 'Environment File Scan' },
18
+ { pattern: '/cgi-bin', name: 'CGI Exploit Attempt' },
19
+ { pattern: '/actuator', name: 'Spring Boot Probe' },
20
+ { pattern: 'wget+http', name: 'Malware Download' },
21
+ { pattern: 'chmod+777', name: 'Permission Escalation' },
22
+ { pattern: '../../', name: 'Path Traversal' },
23
+ { pattern: '%2e%2e', name: 'Encoded Path Traversal' },
24
+ { pattern: '/bin/sh', name: 'Shell Execution' },
25
+ { pattern: '/favicon.ico', name: 'Favicon' },
26
+ { pattern: '/robots.txt', name: 'Robots.txt' },
27
+ { pattern: '/.well-known', name: 'Well-Known Directory' },
28
+ { pattern: '/wp-admin', name: 'WordPress Admin Panel' },
29
+ { pattern: '/admin', name: 'WordPress Admin Panel' },
30
+ { pattern: '/wp-config.php', name: 'WordPress Configuration File' },
31
+ { pattern: '/config.php', name: 'WordPress Configuration File' },
32
+ { pattern: '/phpMyAdmin', name: 'phpMyAdmin' },
33
+ { pattern: '/wp-content/plugins', name: 'WordPress Plugin Directory' },
34
+ { pattern: '/wp-content/themes', name: 'WordPress Theme Directory' },
35
+ { pattern: '/wp-content/uploads', name: 'WordPress Upload Directory' },
36
+ { pattern: '/wp-content/cache', name: 'WordPress Cache Directory' },
37
+ { pattern: '/wp-content/languages', name: 'WordPress Language Directory' },
38
+ { pattern: '/wp-content/db.php', name: 'WordPress Database File' },
39
+ { pattern: '/wp-content/wp-settings.php', name: 'WordPress Settings File' },
40
+ { pattern: '/wp-content/index.php', name: 'WordPress Index File' },
41
+ { pattern: '/wp-content/plugins/index.php', name: 'WordPress Plugin Index File' },
42
+ { pattern: '/wp-content/themes/index.php', name: 'WordPress Theme Index File' },
43
+ { pattern: '/wp-content/uploads/index.php', name: 'WordPress Upload Index File' },
44
+ { pattern: '/wp-content/cache/index.php', name: 'WordPress Cache Index File' },
45
+ { pattern: '/wp-content/languages/index.php', name: 'WordPress Language Index File' },
46
+ { pattern: '/wp-content/db.php', name: 'WordPress Database File' },
47
+ { pattern: '/wp-content/wp-settings.php', name: 'WordPress Settings File' },
48
+ { pattern: '/wp-content/index.php', name: 'WordPress Index File' },
49
+ { pattern: '/webpages', name: 'Webpages' },
50
+ { pattern: '/manager', name: 'Manager' },
51
+ { pattern: '/.git', name: 'Git Repository' },
52
+ { pattern: '/.svn', name: 'Subversion Repository' },
53
+ { pattern: '/ecp', name: 'ECP' },
54
+ { pattern: '/app_dev.php', name: 'app dev php' },
55
+ { pattern: '/?phpinfo', name: 'phpinfo' },
56
+ { pattern: '/+CSCOE+', name: 'Cisco' },
57
+ { pattern: '/debug', name: 'debug' },
58
+ { pattern: '/config', name: 'config' },
59
+ { pattern: '/.json', name: 'json' },
60
+ { pattern: '/library', name: 'library' },
61
+ { pattern: '/API', name: 'API' },
62
+ { pattern: '\x16', name: 'special characters' },
63
+ { pattern: '/form.html', name: 'form' },
64
+ { pattern: '/upl.php', name: 'upl' },
65
+ { pattern: '/t4', name: 't4' },
66
+ { pattern: '/geoip', name: 'geoip' }
67
+ ];
68
+ let IpBlacklistGuard = class IpBlacklistGuard {
69
+ constructor(securityService) {
70
+ this.securityService = securityService;
71
+ }
72
+ async canActivate(context) {
73
+ const request = context.switchToHttp().getRequest();
74
+ const clientIp = this.getClientIp(request);
75
+ const isBlacklisted = await this.securityService.isBlacklisted(clientIp);
76
+ if (isBlacklisted) {
77
+ throw new common_1.ForbiddenException('Access denied: IP address blocked');
78
+ }
79
+ await this.checkSuspiciousActivity(clientIp, request);
80
+ return true;
81
+ }
82
+ getClientIp(request) {
83
+ return (request.headers['x-forwarded-for']?.split(',')[0]?.trim() ||
84
+ request.headers['x-real-ip'] ||
85
+ request.connection?.remoteAddress ||
86
+ request.ip ||
87
+ 'unknown');
88
+ }
89
+ async checkSuspiciousActivity(ip, request) {
90
+ const url = request.url.toLowerCase();
91
+ const userAgent = request.headers['user-agent']?.toLowerCase() || '';
92
+ for (const { pattern, name } of exports.suspiciousPatterns) {
93
+ if (url.includes(pattern) || userAgent.includes(pattern)) {
94
+ await this.securityService.blacklistIp(ip, 3600, `Auto-blocked: ${name}`, undefined, {
95
+ userAgent,
96
+ requestUrl: url,
97
+ attackPattern: name
98
+ });
99
+ throw new common_1.ForbiddenException(`Access denied: ${name} detected`);
100
+ }
101
+ }
102
+ }
103
+ };
104
+ exports.IpBlacklistGuard = IpBlacklistGuard;
105
+ exports.IpBlacklistGuard = IpBlacklistGuard = __decorate([
106
+ (0, common_1.Injectable)(),
107
+ __metadata("design:paramtypes", [security_service_1.SecurityService])
108
+ ], IpBlacklistGuard);
109
+ //# sourceMappingURL=ip-blacklist.guard.js.map
@@ -0,0 +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;IAC/C,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE;IAC5C,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,EAAE;IAC9C,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,sBAAsB,EAAE;IACzD,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,uBAAuB,EAAE;IACvD,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,uBAAuB,EAAE;IACpD,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,8BAA8B,EA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AAE,IAAI;iBACnB,CACD,CAAA;gBACD,MAAM,IAAI,2BAAkB,CAAC,kBAAkB,IAAI,WAAW,CAAC,CAAA;YAChE,CAAC;QACF,CAAC;IACF,CAAC;CACD,CAAA;AA7CY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAEkC,kCAAe;GADjD,gBAAgB,CA6C5B"}
@@ -0,0 +1,8 @@
1
+ import { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import { Reflector } from '@nestjs/core';
3
+ export type Role = 'admin' | 'user' | 'moderator';
4
+ export declare class RolesGuard implements CanActivate {
5
+ private reflector;
6
+ constructor(reflector: Reflector);
7
+ canActivate(context: ExecutionContext): boolean;
8
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RolesGuard = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const core_1 = require("@nestjs/core");
15
+ const roles_decorator_1 = require("../decorators/roles.decorator");
16
+ let RolesGuard = class RolesGuard {
17
+ constructor(reflector) {
18
+ this.reflector = reflector;
19
+ }
20
+ canActivate(context) {
21
+ const requiredRoles = this.reflector.getAllAndOverride(roles_decorator_1.ROLES_KEY, [
22
+ context.getHandler(),
23
+ context.getClass()
24
+ ]);
25
+ if (!requiredRoles) {
26
+ return true;
27
+ }
28
+ const { user } = context.switchToHttp().getRequest();
29
+ if (!user) {
30
+ throw new common_1.ForbiddenException('User not authenticated');
31
+ }
32
+ const hasRole = requiredRoles.some((role) => user.roles?.includes(role));
33
+ if (!hasRole) {
34
+ throw new common_1.ForbiddenException(`Access denied. Required roles: ${requiredRoles.join(', ')}`);
35
+ }
36
+ return true;
37
+ }
38
+ };
39
+ exports.RolesGuard = RolesGuard;
40
+ exports.RolesGuard = RolesGuard = __decorate([
41
+ (0, common_1.Injectable)(),
42
+ __metadata("design:paramtypes", [core_1.Reflector])
43
+ ], RolesGuard);
44
+ //# sourceMappingURL=roles.guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.guard.js","sourceRoot":"","sources":["../../src/guards/roles.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA8F;AAC9F,uCAAwC;AACxC,mEAAyD;AAKlD,IAAM,UAAU,GAAhB,MAAM,UAAU;IACtB,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAE5C,WAAW,CAAC,OAAyB;QACpC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAS,2BAAS,EAAE;YACzE,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SAClB,CAAC,CAAA;QAEF,IAAI,CAAC,aAAa,EAAE,CAAC;YACpB,OAAO,IAAI,CAAA;QACZ,CAAC;QAED,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAA;QAEpD,IAAI,CAAC,IAAI,EAAE,CAAC;YACX,MAAM,IAAI,2BAAkB,CAAC,wBAAwB,CAAC,CAAA;QACvD,CAAC;QAGD,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;QAExE,IAAI,CAAC,OAAO,EAAE,CAAC;YACd,MAAM,IAAI,2BAAkB,CAAC,kCAAkC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC3F,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;CACD,CAAA;AA5BY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;qCAEmB,gBAAS;GAD5B,UAAU,CA4BtB"}
@@ -0,0 +1,9 @@
1
+ export { SecurityModule } from './security.module';
2
+ export { SecurityService } from './services/security.service';
3
+ export { IpBlacklistGuard } from './guards/ip-blacklist.guard';
4
+ export { RolesGuard } from './guards/roles.guard';
5
+ export { AdminGuard } from './guards/admin.guard';
6
+ export { Roles } from './decorators/roles.decorator';
7
+ export { BlacklistedIp, BlacklistedIpSchema } from './schemas/blacklisted-ip.schema';
8
+ export { SecurityConfigInterface } from './interfaces/security-config.interface';
9
+ export { SecurityController } from './controllers/security.controller';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecurityController = exports.BlacklistedIpSchema = exports.BlacklistedIp = exports.Roles = exports.AdminGuard = exports.RolesGuard = exports.IpBlacklistGuard = exports.SecurityService = exports.SecurityModule = void 0;
4
+ var security_module_1 = require("./security.module");
5
+ Object.defineProperty(exports, "SecurityModule", { enumerable: true, get: function () { return security_module_1.SecurityModule; } });
6
+ var security_service_1 = require("./services/security.service");
7
+ Object.defineProperty(exports, "SecurityService", { enumerable: true, get: function () { return security_service_1.SecurityService; } });
8
+ var ip_blacklist_guard_1 = require("./guards/ip-blacklist.guard");
9
+ Object.defineProperty(exports, "IpBlacklistGuard", { enumerable: true, get: function () { return ip_blacklist_guard_1.IpBlacklistGuard; } });
10
+ var roles_guard_1 = require("./guards/roles.guard");
11
+ Object.defineProperty(exports, "RolesGuard", { enumerable: true, get: function () { return roles_guard_1.RolesGuard; } });
12
+ var admin_guard_1 = require("./guards/admin.guard");
13
+ Object.defineProperty(exports, "AdminGuard", { enumerable: true, get: function () { return admin_guard_1.AdminGuard; } });
14
+ var roles_decorator_1 = require("./decorators/roles.decorator");
15
+ Object.defineProperty(exports, "Roles", { enumerable: true, get: function () { return roles_decorator_1.Roles; } });
16
+ var blacklisted_ip_schema_1 = require("./schemas/blacklisted-ip.schema");
17
+ Object.defineProperty(exports, "BlacklistedIp", { enumerable: true, get: function () { return blacklisted_ip_schema_1.BlacklistedIp; } });
18
+ Object.defineProperty(exports, "BlacklistedIpSchema", { enumerable: true, get: function () { return blacklisted_ip_schema_1.BlacklistedIpSchema; } });
19
+ var security_controller_1 = require("./controllers/security.controller");
20
+ Object.defineProperty(exports, "SecurityController", { enumerable: true, get: function () { return security_controller_1.SecurityController; } });
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,qDAAkD;AAAzC,iHAAA,cAAc,OAAA;AAGvB,gEAA6D;AAApD,mHAAA,eAAe,OAAA;AAGxB,kEAA8D;AAArD,sHAAA,gBAAgB,OAAA;AACzB,oDAAiD;AAAxC,yGAAA,UAAU,OAAA;AACnB,oDAAiD;AAAxC,yGAAA,UAAU,OAAA;AAGnB,gEAAoD;AAA3C,wGAAA,KAAK,OAAA;AAGd,yEAAoF;AAA3E,sHAAA,aAAa,OAAA;AAAE,4HAAA,mBAAmB,OAAA;AAM3C,yEAAsE;AAA7D,yHAAA,kBAAkB,OAAA"}
@@ -0,0 +1,25 @@
1
+ export interface SecurityConfigInterface {
2
+ enableDatabase?: boolean;
3
+ mongooseConnection?: string;
4
+ cache?: {
5
+ ttl?: number;
6
+ max?: number;
7
+ store?: any;
8
+ };
9
+ enableAdminPanel?: boolean;
10
+ adminPath?: string;
11
+ enableAutoBlocking?: boolean;
12
+ suspiciousPatterns?: Array<{
13
+ pattern: string;
14
+ name: string;
15
+ blockDurationHours?: number;
16
+ }>;
17
+ defaultBlockDurationHours?: number;
18
+ enableRateLimit?: boolean;
19
+ rateLimitOptions?: {
20
+ windowMs?: number;
21
+ max?: number;
22
+ };
23
+ enableLogging?: boolean;
24
+ logLevel?: 'error' | 'warn' | 'info' | 'debug';
25
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=security-config.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security-config.interface.js","sourceRoot":"","sources":["../../src/interfaces/security-config.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import { Document } from 'mongoose';
2
+ export declare class BlacklistedIp extends Document {
3
+ ip: string;
4
+ reason: string;
5
+ blockedAt: Date;
6
+ expiresAt: Date;
7
+ durationHours: number;
8
+ blockedBy: string;
9
+ userAgent?: string;
10
+ requestUrl?: string;
11
+ active: boolean;
12
+ blockType: 'manual' | 'auto';
13
+ attackPattern?: string;
14
+ }
15
+ export declare const BlacklistedIpSchema: import("mongoose").Schema<BlacklistedIp, import("mongoose").Model<BlacklistedIp, any, any, any, Document<unknown, any, BlacklistedIp, any, {}> & BlacklistedIp & Required<{
16
+ _id: unknown;
17
+ }> & {
18
+ __v: number;
19
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, BlacklistedIp, Document<unknown, {}, import("mongoose").FlatRecord<BlacklistedIp>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<BlacklistedIp> & Required<{
20
+ _id: unknown;
21
+ }> & {
22
+ __v: number;
23
+ }>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BlacklistedIpSchema = exports.BlacklistedIp = void 0;
13
+ const mongoose_1 = require("@nestjs/mongoose");
14
+ const mongoose_2 = require("mongoose");
15
+ let BlacklistedIp = class BlacklistedIp extends mongoose_2.Document {
16
+ };
17
+ exports.BlacklistedIp = BlacklistedIp;
18
+ __decorate([
19
+ (0, mongoose_1.Prop)({ required: true, unique: true }),
20
+ __metadata("design:type", String)
21
+ ], BlacklistedIp.prototype, "ip", void 0);
22
+ __decorate([
23
+ (0, mongoose_1.Prop)({ required: true }),
24
+ __metadata("design:type", String)
25
+ ], BlacklistedIp.prototype, "reason", void 0);
26
+ __decorate([
27
+ (0, mongoose_1.Prop)({ required: true }),
28
+ __metadata("design:type", Date)
29
+ ], BlacklistedIp.prototype, "blockedAt", void 0);
30
+ __decorate([
31
+ (0, mongoose_1.Prop)({ required: true }),
32
+ __metadata("design:type", Date)
33
+ ], BlacklistedIp.prototype, "expiresAt", void 0);
34
+ __decorate([
35
+ (0, mongoose_1.Prop)({ required: true }),
36
+ __metadata("design:type", Number)
37
+ ], BlacklistedIp.prototype, "durationHours", void 0);
38
+ __decorate([
39
+ (0, mongoose_1.Prop)(),
40
+ __metadata("design:type", String)
41
+ ], BlacklistedIp.prototype, "blockedBy", void 0);
42
+ __decorate([
43
+ (0, mongoose_1.Prop)(),
44
+ __metadata("design:type", String)
45
+ ], BlacklistedIp.prototype, "userAgent", void 0);
46
+ __decorate([
47
+ (0, mongoose_1.Prop)(),
48
+ __metadata("design:type", String)
49
+ ], BlacklistedIp.prototype, "requestUrl", void 0);
50
+ __decorate([
51
+ (0, mongoose_1.Prop)({ default: true }),
52
+ __metadata("design:type", Boolean)
53
+ ], BlacklistedIp.prototype, "active", void 0);
54
+ __decorate([
55
+ (0, mongoose_1.Prop)({ default: 'manual' }),
56
+ __metadata("design:type", String)
57
+ ], BlacklistedIp.prototype, "blockType", void 0);
58
+ __decorate([
59
+ (0, mongoose_1.Prop)(),
60
+ __metadata("design:type", String)
61
+ ], BlacklistedIp.prototype, "attackPattern", void 0);
62
+ exports.BlacklistedIp = BlacklistedIp = __decorate([
63
+ (0, mongoose_1.Schema)({ timestamps: true })
64
+ ], BlacklistedIp);
65
+ exports.BlacklistedIpSchema = mongoose_1.SchemaFactory.createForClass(BlacklistedIp);
66
+ exports.BlacklistedIpSchema.index({ expiresAt: 1 });
67
+ exports.BlacklistedIpSchema.index({ active: 1, expiresAt: 1 });
68
+ exports.BlacklistedIpSchema.index({ createdAt: -1 });
69
+ //# sourceMappingURL=blacklisted-ip.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blacklisted-ip.schema.js","sourceRoot":"","sources":["../../src/schemas/blacklisted-ip.schema.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA8D;AAC9D,uCAAmC;AAG5B,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,mBAAQ;CAiC1C,CAAA;AAjCY,sCAAa;AAEzB;IADC,IAAA,eAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;yCAC7B;AAGV;IADC,IAAA,eAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;6CACX;AAGd;IADC,IAAA,eAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;8BACd,IAAI;gDAAA;AAGf;IADC,IAAA,eAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;8BACd,IAAI;gDAAA;AAGf;IADC,IAAA,eAAI,E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