chore(bot-defense): 🔧 Implement bot detection logic (behavioral analysis, rate limiting) for automated attack protection
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
2493ea2273
commit
e0321fc392
11 changed files with 282 additions and 0 deletions
17
features/bot-defense/backend-api/.swcrc
Normal file
17
features/bot-defense/backend-api/.swcrc
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"module": {
|
||||
"type": "es6",
|
||||
"resolveFully": true
|
||||
},
|
||||
"jsc": {
|
||||
"target": "es2022",
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true
|
||||
},
|
||||
"transform": {
|
||||
"legacyDecorator": true,
|
||||
"decoratorMetadata": true
|
||||
}
|
||||
}
|
||||
}
|
||||
9
features/bot-defense/backend-api/nest-cli.json
Normal file
9
features/bot-defense/backend-api/nest-cli.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"builder": "swc",
|
||||
"typeCheck": true
|
||||
}
|
||||
}
|
||||
56
features/bot-defense/backend-api/package.json
Normal file
56
features/bot-defense/backend-api/package.json
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
"name": "@features/bot-defense-backend-api",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"verify": "bun run build && node scripts/verify-circular-deps.mjs",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "lixtest",
|
||||
"test:watch": "lixtest --watch",
|
||||
"test:cov": "lixtest --coverage",
|
||||
"test:unit": "lixtest --unit",
|
||||
"test:coverage": "lixtest --coverage",
|
||||
"test:ui": "lixtest --ui"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lilith/bot-defense": "*",
|
||||
"@lilith/domain-events": "^2.8.0",
|
||||
"@lilith/nestjs-health": "^1.0.0",
|
||||
"@lilith/service-registry": "^1.3.0",
|
||||
"@lilith/typeorm-entities": "^1.0.33",
|
||||
"@lilith/vite-plugin-dependency-startup": "^1.1.1",
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/config": "^3.0.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/event-emitter": "^2.0.0",
|
||||
"@nestjs/jwt": "^10.0.0",
|
||||
"@nestjs/passport": "^10.0.0",
|
||||
"@nestjs/swagger": "^7.0.0",
|
||||
"@nestjs/typeorm": "^10.0.0",
|
||||
"class-validator": "^0.14.0",
|
||||
"class-transformer": "^0.5.0",
|
||||
"rxjs": "^7.8.0",
|
||||
"typeorm": "^0.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@lilith/test-utils": "*",
|
||||
"@nestjs/cli": "^10.0.0",
|
||||
"@nestjs/schematics": "^10.0.0",
|
||||
"@nestjs/testing": "^10.0.0",
|
||||
"@swc/cli": "^0.7.10",
|
||||
"@swc/core": "^1.15.8",
|
||||
"@types/node": "^20.0.0",
|
||||
"typescript": "^5.3.0",
|
||||
"vitest": "^3.2.4"
|
||||
}
|
||||
}
|
||||
12
features/bot-defense/backend-api/tsconfig.json
Normal file
12
features/bot-defense/backend-api/tsconfig.json
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"extends": "@lilith/configs/typescript/nestjs",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
|
||||
}
|
||||
48
features/bot-defense/frontend-components/package.json
Normal file
48
features/bot-defense/frontend-components/package.json
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"name": "@lilith/bot-defense-react",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Bot defense React components for the Lilith platform",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit",
|
||||
"build": "lixbuild",
|
||||
"test": "vitest run --passWithNoTests",
|
||||
"lint": "eslint . --ext ts,tsx"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lilith/bot-defense": "*",
|
||||
"@lilith/service-registry": "^1.3.0",
|
||||
"@lilith/analytics-client": "^2.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@lilith/ui-styled-components": "^6.3.9",
|
||||
"@lilith/ui-theme": "^1.3.6",
|
||||
"@lilith/ui-motion": "^2.0.0",
|
||||
"react": "^18.0.0 || ^19.0.0",
|
||||
"react-dom": "^18.0.0 || ^19.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@lilith/lix-configs": "^1.0.0",
|
||||
"@lilith/vite-plugin-dependency-startup": "^1.1.1",
|
||||
"@types/node": "^20.19.30",
|
||||
"tsup": "^8.0.0",
|
||||
"@types/react": "^19.2.8",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@lilith/ui-styled-components": "^6.3.9",
|
||||
"@lilith/ui-theme": "^1.3.6",
|
||||
"@lilith/ui-motion": "^2.0.1",
|
||||
"react": "^19.2.3",
|
||||
"react-dom": "^19.2.3",
|
||||
"typescript": "^5.9.3",
|
||||
"vitest": "^4.0.17"
|
||||
}
|
||||
}
|
||||
32
features/bot-defense/shared/package.json
Normal file
32
features/bot-defense/shared/package.json
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name": "@lilith/bot-defense",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Bot defense types and utilities for the Lilith platform",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit",
|
||||
"build": "lixbuild",
|
||||
"test": "vitest run --passWithNoTests",
|
||||
"lint": "eslint . --ext ts,tsx"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@lilith/lix-configs": "^1.0.0",
|
||||
"@lilith/vite-plugin-dependency-startup": "^1.1.1",
|
||||
"@types/node": "^20.19.30",
|
||||
"tsup": "^8.0.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vitest": "^4.0.17"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lilith/service-registry": "^1.3.0"
|
||||
}
|
||||
}
|
||||
21
features/bot-defense/shared/src/constants.ts
Normal file
21
features/bot-defense/shared/src/constants.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* Bot Defense - Constants
|
||||
*/
|
||||
|
||||
/**
|
||||
* Minimum confidence threshold for verification to pass (0.0 - 1.0)
|
||||
* VibeCheck result must have isLive=true AND confidence >= this threshold
|
||||
*/
|
||||
export const CONFIDENCE_THRESHOLD = 0.70; // 70%
|
||||
|
||||
/**
|
||||
* Maximum number of verification attempts per session
|
||||
* After this many failures, user must contact support or create new session
|
||||
*/
|
||||
export const MAX_ATTEMPTS = 3;
|
||||
|
||||
/**
|
||||
* Session time-to-live in milliseconds
|
||||
* Sessions expire after this duration (5 minutes)
|
||||
*/
|
||||
export const SESSION_TTL = 5 * 60 * 1000; // 5 minutes
|
||||
7
features/bot-defense/shared/src/index.ts
Normal file
7
features/bot-defense/shared/src/index.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* @lilith/bot-defense
|
||||
* Bot defense types, DTOs, and constants for the Lilith platform
|
||||
*/
|
||||
|
||||
export * from './types';
|
||||
export * from './constants';
|
||||
47
features/bot-defense/shared/src/types.ts
Normal file
47
features/bot-defense/shared/src/types.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Bot Defense - Types and DTOs
|
||||
*/
|
||||
|
||||
/**
|
||||
* Session data returned when creating a verification session
|
||||
*/
|
||||
export interface SessionDTO {
|
||||
sessionId: string;
|
||||
nonce: string;
|
||||
expiresAt: Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Result from VibeCheck SDK (client-side)
|
||||
*/
|
||||
export interface VibeCheckResult {
|
||||
isLive: boolean;
|
||||
confidence: number; // 0.0 - 1.0
|
||||
}
|
||||
|
||||
/**
|
||||
* Request DTO for verification endpoint
|
||||
*/
|
||||
export interface VerifySessionDTO {
|
||||
nonce: string;
|
||||
vibeCheckResult: VibeCheckResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from verification endpoint
|
||||
*/
|
||||
export interface VerificationResultDTO {
|
||||
verified: boolean;
|
||||
confidence: number;
|
||||
attemptsRemaining: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verification status enum
|
||||
*/
|
||||
export enum VerificationStatus {
|
||||
PENDING = 'pending',
|
||||
PASSED = 'passed',
|
||||
FAILED = 'failed',
|
||||
EXPIRED = 'expired',
|
||||
}
|
||||
30
features/bot-defense/shared/tsconfig.json
Normal file
30
features/bot-defense/shared/tsconfig.json
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"lib": [
|
||||
"ES2022"
|
||||
],
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true,
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
3
features/bot-defense/shared/tsup.config.ts
Normal file
3
features/bot-defense/shared/tsup.config.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { createLibraryConfig } from '@lilith/lix-configs/tsup/library';
|
||||
|
||||
export default createLibraryConfig();
|
||||
Loading…
Add table
Reference in a new issue