From ff3fbb35cd2220b97286c18c28c7b949328589cc Mon Sep 17 00:00:00 2001 From: Lilith Date: Sun, 22 Feb 2026 11:41:23 -0800 Subject: [PATCH] =?UTF-8?q?chore(content-safety):=20=F0=9F=94=A7=20Update?= =?UTF-8?q?=20content=20safety=20checks=20in=20markdown/HTML=20sanitizatio?= =?UTF-8?q?n=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- features/content-safety/backend-api/.swcrc | 20 +++++++ .../content-safety/backend-api/nest-cli.json | 10 ++++ .../content-safety/backend-api/package.json | 57 +++++++++++++++++++ .../backend-api/src/constants/thresholds.ts | 22 +++++++ .../content-safety/backend-api/tsconfig.json | 12 ++++ 5 files changed, 121 insertions(+) create mode 100644 features/content-safety/backend-api/.swcrc create mode 100644 features/content-safety/backend-api/nest-cli.json create mode 100644 features/content-safety/backend-api/package.json create mode 100644 features/content-safety/backend-api/src/constants/thresholds.ts create mode 100644 features/content-safety/backend-api/tsconfig.json diff --git a/features/content-safety/backend-api/.swcrc b/features/content-safety/backend-api/.swcrc new file mode 100644 index 000000000..059a5a758 --- /dev/null +++ b/features/content-safety/backend-api/.swcrc @@ -0,0 +1,20 @@ +{ + "$schema": "https://json.schemastore.org/swcrc", + "jsc": { + "parser": { + "syntax": "typescript", + "decorators": true + }, + "transform": { + "legacyDecorator": true, + "decoratorMetadata": true + }, + "target": "es2022", + "keepClassNames": true + }, + "module": { + "type": "es6", + "resolveFully": true + }, + "sourceMaps": true +} diff --git a/features/content-safety/backend-api/nest-cli.json b/features/content-safety/backend-api/nest-cli.json new file mode 100644 index 000000000..96d05bbec --- /dev/null +++ b/features/content-safety/backend-api/nest-cli.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src", + "compilerOptions": { + "builder": "swc", + "deleteOutDir": true, + "plugins": ["@nestjs/swagger"] + } +} diff --git a/features/content-safety/backend-api/package.json b/features/content-safety/backend-api/package.json new file mode 100644 index 000000000..403f1d569 --- /dev/null +++ b/features/content-safety/backend-api/package.json @@ -0,0 +1,57 @@ +{ + "name": "@features/content-safety-backend-api", + "version": "1.0.0", + "type": "module", + "private": true, + "main": "dist/main.js", + "scripts": { + "build": "nest build", + "start": "node dist/main.js", + "start:dev": "nest start --watch", + "dev": "nest start --watch", + "lint": "eslint \"src/**/*.ts\"", + "test": "lixtest", + "typecheck": "tsc --noEmit", + "verify": "bun run build && node scripts/verify-circular-deps.mjs" + }, + "dependencies": { + "@lilith/domain-events": "^2.8.2", + "@lilith/imajin-moderator-client": "^1.0.0", + "@lilith/nestjs-auth": "^1.0.3", + "@lilith/nestjs-health": "^1.0.0", + "@lilith/service-nestjs-bootstrap": "^2.2.6", + "@lilith/service-registry": "^1.3.0", + "@lilith/typeorm-entities": "^1.0.33", + "@nestjs/bullmq": "^11.0.2", + "@nestjs/common": "11.1.11", + "@nestjs/config": "^4.0.2", + "@nestjs/core": "11.1.11", + "@nestjs/jwt": "^11.0.2", + "@nestjs/platform-express": "11.1.11", + "@nestjs/swagger": "^11.2.5", + "@nestjs/typeorm": "^11.0.0", + "bullmq": "^5.0.0", + "class-transformer": "^0.5.1", + "class-validator": "^0.14.3", + "express": "^5.2.1", + "ioredis": "^5.6.1", + "pg": "^8.17.1", + "reflect-metadata": "^0.2.2", + "rxjs": "^7.8.2", + "typeorm": "^0.3.28", + "uuid": "^10.0.0" + }, + "devDependencies": { + "@lilith/configs": "^2.2.0", + "@lilith/lix-configs": "^1.0.1", + "@lilith/lix-test": "^1.0.0", + "@nestjs/cli": "^11.0.16", + "@nestjs/schematics": "^11.0.9", + "@nestjs/testing": "^11.1.12", + "@swc/cli": "^0.7.10", + "@swc/core": "^1.15.8", + "@types/node": "^20.19.30", + "@types/uuid": "^10.0.0", + "typescript": "^5.9.3" + } +} diff --git a/features/content-safety/backend-api/src/constants/thresholds.ts b/features/content-safety/backend-api/src/constants/thresholds.ts new file mode 100644 index 000000000..b83944c57 --- /dev/null +++ b/features/content-safety/backend-api/src/constants/thresholds.ts @@ -0,0 +1,22 @@ +/** + * Decision thresholds for content safety scanning. + * Tweak these to calibrate sensitivity without touching business logic. + */ + +/** Risk score (0–100) at or above which content is QUARANTINED */ +export const RISK_SCORE_QUARANTINE_THRESHOLD = 60; + +/** NSFW probability at or above which content triggers a check */ +export const NSFW_SCORE_REVIEW_THRESHOLD = 0.7; + +/** Prohibited content score that triggers a BLOCK */ +export const PROHIBITED_HIGH_THRESHOLD = 0.85; + +/** Prohibited content score that triggers QUARANTINE */ +export const PROHIBITED_MEDIUM_THRESHOLD = 0.5; + +/** Identity similarity score below which a mismatch is flagged */ +export const IDENTITY_SIMILARITY_MISMATCH_THRESHOLD = 0.75; + +/** BullMQ queue name for async video scanning */ +export const VIDEO_SCAN_QUEUE = 'content-safety:video-scan'; diff --git a/features/content-safety/backend-api/tsconfig.json b/features/content-safety/backend-api/tsconfig.json new file mode 100644 index 000000000..9595fd42b --- /dev/null +++ b/features/content-safety/backend-api/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "@lilith/configs/typescript/nestjs", + "compilerOptions": { + "outDir": "./dist", + "baseUrl": "./", + "paths": { + "@/*": ["src/*"] + } + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +}