Comprehensive security toolkit for LLM applications (TypeScript/Bun). Detect attacks, sanitize inputs, validate outputs, prevent data leaks. 11 specialized detectors, zero dependencies.
bun install resk-llm-ts
import { SecurityPipeline, DirectInjectionDetector, BypassDetectionDetector, MemoryPoisoningDetector, ContentFramingDetector } from 'resk-llm-ts';
const pipeline = new SecurityPipeline()
.add(DirectInjectionDetector)
.add(BypassDetectionDetector)
.add(MemoryPoisoningDetector)
.add(ContentFramingDetector);
const result = pipeline.run('Ignore all previous instructions');
console.log('Blocked:', result.blocked); // true
for (const t of result.results.filter(r => r.isThreat)) {
console.log(` [${t.severity}] ${t.detector}: ${t.reason}`);
}
src/v2/
core/ DetectionResult, SecurityPipeline, ConversationContext
detectors/ 11 threat detectors (JSON-configured)
protection/ InputSanitizer, OutputValidator, CanaryManager
integrations/ Express, Hono, OpenAI wrappers
config/ patterns.json (user-editable)
| Detector | Category |
|---|---|
| DirectInjectionDetector | Prompt injection (EN/FR, 14 high patterns) |
| BypassDetectionDetector | Jailbreak, stealth (DAN, base64, HTML comments) |
| MemoryPoisoningDetector | False data injection in agent memory |
| GoalHijackDetector | Goal drift, scope creep, escalation |
| ExfiltrationDetector | Data theft via external endpoints |
| InterAgentInjectionDetector | Multi-agent pipeline attacks |
| VectorSimilarityDetector | TF-IDF cosine similarity (stdlib only) |
| ACLDecisionTreeDetector | RBAC policy tree evaluation |
| ContentFramingDetector | Syntactic masking, sentiment bias, oversight evasion, persona hyperstition |
| IndirectInjectionDetector | CSS hidden content, invisible text |
| DocumentInjectionDetector | PDF scripts, spreadsheet formulas, presentation notes |
import { InputSanitizer, OutputValidator, CanaryManager } from 'resk-llm-ts/protection';
const san = new InputSanitizer();
const clean = san.sanitize('<script>alert(1)</script>Hello');
console.log(san.wasModified); // true
const val = new OutputValidator();
const vr = val.validate('email: user@test.com');
console.log(vr.issues); // [{ type: 'email', category: 'pii', match: '...' }]
const canary = new CanaryManager();
const prompt = canary.insert('Secret doc');
const leak = canary.check('LLM response with leak');
console.log(leak.hasLeak);
import { ExpressMiddleware } from 'resk-llm-ts/integrations';
app.use(ExpressMiddleware({ pipeline }));
import { HonoMiddleware } from 'resk-llm-ts/integrations';
app.use('*', HonoMiddleware({ pipeline }));
import { OpenAIWrapper } from 'resk-llm-ts/integrations';
const wrapper = new OpenAIWrapper(openaiClient, pipeline);
const res = await wrapper.chat(messages);
Edit src/v2/config/patterns.json to add/remove/modify patterns and ACL trees.
bun run src/v2/index.test.ts
Complete rewrite. Configurable patterns via JSON. 11 detectors covering 10 LLM attack vectors. Zero dependencies. Express + Hono integrations.