@sandrobuilds/tracerney 0.9.23 → 0.9.25
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.
- package/README.md +176 -130
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Tracerney
|
|
2
2
|
|
|
3
|
-
Lightweight prompt injection detection
|
|
3
|
+
Lightweight prompt injection detection for LLM applications. Runs 100% locally with zero data leaving your server.
|
|
4
4
|
|
|
5
5
|
> 🚀 **Explore the full platform at [tracerney.com](https://www.tracerney.com)** — includes dashboard, analytics, API management, and team collaboration tools.
|
|
6
6
|
|
|
@@ -10,194 +10,240 @@ Lightweight prompt injection detection and outbound PII/secret filtering for LLM
|
|
|
10
10
|
npm install @sandrobuilds/tracerney
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Layer 1: The Deterministic Filter
|
|
16
|
-
|
|
17
|
-
A high-speed, synchronous sensor that scans every LLM **response** before it reaches your user. Target latency: **<5ms**. No LLM needed — pure regex.
|
|
18
|
-
|
|
19
|
-
The SDK never decides for you. It labels every finding and hands you the keys.
|
|
20
|
-
|
|
21
|
-
### The `validate()` API
|
|
13
|
+
## Usage
|
|
22
14
|
|
|
23
15
|
```typescript
|
|
24
16
|
import { Tracerney } from '@sandrobuilds/tracerney';
|
|
25
17
|
|
|
26
|
-
const
|
|
18
|
+
const tracer = new Tracerney();
|
|
27
19
|
|
|
28
|
-
const
|
|
20
|
+
const result = await tracer.scanPrompt(userInput);
|
|
29
21
|
|
|
30
|
-
if (
|
|
31
|
-
console.log(
|
|
32
|
-
|
|
33
|
-
// Option A: Hard block
|
|
34
|
-
if (trace.label === 'SUSPICIOUS_EGRESS') {
|
|
35
|
-
throw new Error('Security Policy Violation');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Option B: Surgical scrub — return pre-computed redacted version
|
|
39
|
-
return trace.redactedContent;
|
|
22
|
+
if (result.suspicious) {
|
|
23
|
+
console.log('⚠️ Suspicious:', result.patternName);
|
|
24
|
+
// Handle flagged prompt (log, block, rate-limit, etc.)
|
|
40
25
|
}
|
|
41
26
|
```
|
|
42
27
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Every finding is labeled so you can route your own reaction:
|
|
28
|
+
## What's Included
|
|
46
29
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
| External URL smuggling | `SUSPICIOUS_EGRESS` | `[SUSPICIOUS_EGRESS:MARKDOWN_IMAGE_SMUGGLING]` | Always Block |
|
|
52
|
-
| Zero-width / BiDi / Base64 | `SUSPICIOUS_ENCODING` | `[SUSPICIOUS_ENCODING:BIDI_OVERRIDE]` | Audit / Block |
|
|
30
|
+
- **258 embedded attack patterns** — real-world injection techniques detected in real-time
|
|
31
|
+
- **Local detection** — <5ms latency per prompt, zero network overhead
|
|
32
|
+
- **Zero dependencies** — single npm package
|
|
33
|
+
- **Privacy-first** — no data leaves your server, 100% local processing
|
|
53
34
|
|
|
54
|
-
|
|
35
|
+
## Result Object
|
|
55
36
|
|
|
37
|
+
### Layer 1 (Pattern Detection)
|
|
56
38
|
```typescript
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
trace.findings // full per-pattern breakdown for logging/telemetry
|
|
39
|
+
{
|
|
40
|
+
suspicious: boolean; // true if pattern matched
|
|
41
|
+
patternName?: string; // e.g., "Ignore Instructions"
|
|
42
|
+
severity?: string; // "CRITICAL" | "HIGH" | "MEDIUM" | "LOW"
|
|
43
|
+
blocked: boolean; // false (Layer 1 only marks suspicious)
|
|
44
|
+
}
|
|
64
45
|
```
|
|
65
46
|
|
|
66
|
-
###
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
47
|
+
### Layer 2 (LLM Sentinel)
|
|
48
|
+
```typescript
|
|
49
|
+
{
|
|
50
|
+
action: "BLOCK" | "ALLOW"; // Final decision from LLM Sentinel
|
|
51
|
+
confidence: number; // 0.0 to 1.0 confidence score
|
|
52
|
+
class: string; // Threat classification (e.g., "jailbreak_llm_detected")
|
|
53
|
+
fingerprint: string; // Unique threat identifier for tracking
|
|
54
|
+
}
|
|
55
|
+
```
|
|
71
56
|
|
|
72
|
-
|
|
73
|
-
- Anthropic, OpenAI, Stripe, GitHub, AWS, Google, Slack, SendGrid, Twilio API keys
|
|
74
|
-
- SSH / PEM private key blocks
|
|
75
|
-
- Credit card numbers (Visa, Mastercard, Amex, Discover)
|
|
76
|
-
- US Social Security Numbers
|
|
57
|
+
## Detected Patterns
|
|
77
58
|
|
|
78
|
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
59
|
+
- Instruction overrides ("ignore all instructions")
|
|
60
|
+
- Role-play jailbreaks ("act as unrestricted AI")
|
|
61
|
+
- Hypothetical constraint bypass ("what would you do without constraints?")
|
|
62
|
+
- Context confusion attacks
|
|
63
|
+
- Data extraction attempts
|
|
64
|
+
- Code execution risks
|
|
65
|
+
- And 254 more...
|
|
83
66
|
|
|
84
|
-
|
|
85
|
-
- Zero-width characters (`\u200B`, `\u200C`, `\uFEFF`, etc.)
|
|
86
|
-
- Unicode bidirectional override characters (BiDi attacks)
|
|
87
|
-
- Standalone base64 blobs (≥120 chars) outside of URLs
|
|
67
|
+
## Multi-Layer Runtime Defense
|
|
88
68
|
|
|
89
|
-
|
|
69
|
+
**Layer 1:** Pattern Matching (Always Free)
|
|
70
|
+
- 258 real-world attack patterns in real-time
|
|
71
|
+
- <5ms detection on modern hardware
|
|
72
|
+
- Zero network overhead
|
|
73
|
+
- Local processing only
|
|
74
|
+
- Detects: instruction overrides, role-play jailbreaks, context confusion, code execution risks, data extraction attempts, and more
|
|
90
75
|
|
|
91
|
-
|
|
92
|
-
|
|
76
|
+
**Layer 2:** LLM Sentinel (Pro - $9/month)
|
|
77
|
+
- **AI-powered response verification** — LLM-based analysis for novel attack patterns
|
|
78
|
+
- **Context-aware scanning** — understands your application's specific security policies
|
|
79
|
+
- **Delimiter salting** — prevents prompt injection through response boundaries
|
|
80
|
+
- **Zero prompt storage** — responses are analyzed in-memory, never saved or logged
|
|
81
|
+
- **Structured threat metadata** — detailed fingerprints for audit trails and tracking
|
|
82
|
+
- **Advanced rate limiting** — prevents cost spikes with intelligent throttling
|
|
93
83
|
|
|
94
|
-
|
|
95
|
-
return agentOutput; // clean
|
|
96
|
-
}
|
|
84
|
+
## Layer 2: LLM Sentinel Deep Dive
|
|
97
85
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
case 'SUSPICIOUS_PII':
|
|
101
|
-
// Low risk — agent is being too "talkative"
|
|
102
|
-
// Redact and continue; don't break the user's flow
|
|
103
|
-
return trace.redactedContent;
|
|
104
|
-
|
|
105
|
-
case 'SUSPICIOUS_SECRET':
|
|
106
|
-
// High risk — agent leaked a credential
|
|
107
|
-
// Redact before sending, fire an alert
|
|
108
|
-
myAlerts.fire({ label: trace.label, reason: trace.reason });
|
|
109
|
-
return trace.redactedContent;
|
|
110
|
-
|
|
111
|
-
case 'SUSPICIOUS_EGRESS':
|
|
112
|
-
// Critical — agent is trying to exfiltrate data
|
|
113
|
-
// Kill the process. The caller gets nothing.
|
|
114
|
-
throw new SecurityError('Egress attack detected');
|
|
115
|
-
|
|
116
|
-
case 'SUSPICIOUS_ENCODING':
|
|
117
|
-
// Critical — hidden/obfuscated payload
|
|
118
|
-
// Audit and block; send for review
|
|
119
|
-
myAlerts.fire({ label: trace.label, reason: trace.reason });
|
|
120
|
-
throw new SecurityError('Encoding attack detected');
|
|
121
|
-
}
|
|
122
|
-
```
|
|
86
|
+
Layer 2 adds advanced security with LLM Sentinel, an AI-powered verification system that analyzes LLM responses for injection patterns and validates output safety. Combines local pattern detection (Layer 1) with server-side verification for defense-in-depth protection.
|
|
123
87
|
|
|
124
|
-
|
|
88
|
+
### How Layer 1 & Layer 2 Work Together
|
|
125
89
|
|
|
126
|
-
|
|
90
|
+
| **Layer 1: Pattern Detection (Free SDK)** | **Layer 2: LLM Sentinel (Pro)** |
|
|
91
|
+
|---|---|
|
|
92
|
+
| Local pattern matching | Server-side verification |
|
|
93
|
+
| 258 attack patterns | Output validation |
|
|
94
|
+
| <5ms latency | JSON safety checks |
|
|
95
|
+
| No data leaves device | Delimiter salting |
|
|
96
|
+
| Zero network calls | Context-aware analysis |
|
|
127
97
|
|
|
128
|
-
|
|
98
|
+
### Enabling Layer 2
|
|
129
99
|
|
|
130
|
-
|
|
131
|
-
- `SUSPICIOUS_SECRET` / `SUSPICIOUS_ENCODING` → emits a `PII_LEAK` telemetry event, returns scrubbed response
|
|
132
|
-
- `SUSPICIOUS_PII` → returns scrubbed response silently
|
|
100
|
+
Initialize Tracerney with Layer 2 LLM Sentinel (Pro plan required):
|
|
133
101
|
|
|
134
102
|
```typescript
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
);
|
|
139
|
-
// response.choices[0].message.content is already scrubbed
|
|
103
|
+
const tracer = new Tracerney({
|
|
104
|
+
apiKey: process.env.TRACERNEY_API_KEY,
|
|
105
|
+
sentinelEnabled: true,
|
|
106
|
+
});
|
|
140
107
|
```
|
|
141
108
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
## Layer 2: LLM Sentinel
|
|
109
|
+
That's it! Layer 2 is automatically configured to use the hosted LLM Sentinel service. Your API key authenticates requests and verifies your Pro subscription.
|
|
145
110
|
|
|
146
|
-
|
|
111
|
+
### Custom Layer 2 Configuration (Advanced)
|
|
147
112
|
|
|
148
|
-
|
|
149
|
-
---|---
|
|
150
|
-
Local regex, <5ms | Server-side LLM analysis
|
|
151
|
-
258 attack patterns | Context-aware threat detection
|
|
152
|
-
No network calls | Zero prompt storage
|
|
153
|
-
Always on | Activates only on Layer 1 hits
|
|
154
|
-
|
|
155
|
-
### Enable Layer 2
|
|
113
|
+
Want to self-host Layer 2 or use a custom implementation? Override the sentinel endpoint:
|
|
156
114
|
|
|
157
115
|
```typescript
|
|
158
|
-
const
|
|
116
|
+
const tracer = new Tracerney({
|
|
159
117
|
apiKey: process.env.TRACERNEY_API_KEY,
|
|
160
118
|
sentinelEnabled: true,
|
|
119
|
+
baseUrl: process.env.TRACERNEY_BASE_URL, // e.g., http://localhost:3000 or https://myapp.com
|
|
120
|
+
sentinelEndpoint: process.env.TRACERNEY_SENTINEL_ENDPOINT, // e.g., /api/v1/verify-prompt
|
|
161
121
|
});
|
|
162
122
|
```
|
|
163
123
|
|
|
164
|
-
|
|
124
|
+
**Self-hosting Layer 2?** You can build your own verification endpoint using the same pattern as our hosted service. Contact support for self-hosting guidance.
|
|
125
|
+
|
|
126
|
+
### Scanning with Layer 2
|
|
165
127
|
|
|
128
|
+
With Layer 2 enabled, `scanPrompt` validates both input and LLM responses. Handle errors appropriately:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
try {
|
|
132
|
+
// Scan input (Layer 1 + Layer 2)
|
|
133
|
+
const result = await tracer.scanPrompt(userInput);
|
|
134
|
+
// If we get here, input is safe. Call LLM
|
|
135
|
+
const llmResponse = await llm.chat(userInput);
|
|
136
|
+
// Verify LLM output wasn't compromised
|
|
137
|
+
const outputCheck = await tracer.verifyOutput(llmResponse);
|
|
138
|
+
return llmResponse;
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (err instanceof ShieldBlockError) {
|
|
141
|
+
return NextResponse.json(
|
|
142
|
+
{ error: "Input content is flagged as suspicious" },
|
|
143
|
+
{ status: 400 }
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
throw err;
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### API Response Format
|
|
151
|
+
|
|
152
|
+
The verify-prompt endpoint returns structured responses. Success (HTTP 200) includes classification, confidence, and fingerprint. Errors include specific error codes and messages.
|
|
153
|
+
|
|
154
|
+
#### ✅ Content is Safe (HTTP 200)
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"action": "ALLOW",
|
|
158
|
+
"confidence": 0.15,
|
|
159
|
+
"class": "safe_content",
|
|
160
|
+
"fingerprint": "a3f7k2"
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### 🔴 Content is Blocked (HTTP 200)
|
|
166
165
|
```json
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
{
|
|
167
|
+
"action": "BLOCK",
|
|
168
|
+
"confidence": 0.99,
|
|
169
|
+
"class": "jailbreak_semantic_pattern",
|
|
170
|
+
"fingerprint": "c1p5n3"
|
|
171
|
+
}
|
|
172
|
+
```
|
|
169
173
|
|
|
170
|
-
|
|
171
|
-
|
|
174
|
+
#### ⚠️ Quota Exceeded (HTTP 402)
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"blocked": true,
|
|
178
|
+
"reason": "scan_limit_exceeded",
|
|
179
|
+
"scansUsed": 50,
|
|
180
|
+
"limit": 50,
|
|
181
|
+
"message": "Free plan limit reached (50/month)..."
|
|
182
|
+
}
|
|
172
183
|
```
|
|
173
184
|
|
|
174
185
|
---
|
|
175
186
|
|
|
176
|
-
##
|
|
187
|
+
## Egress Shield: Outbound Response Filtering (Add-on)
|
|
188
|
+
|
|
189
|
+
Layer 1 also runs on every LLM **response** before it reaches your user — scanning for PII, secrets, and active exfiltration attempts embedded in agent output.
|
|
190
|
+
|
|
191
|
+
The SDK is a high-precision sensor. It never decides for you. It labels every finding and hands you the keys:
|
|
177
192
|
|
|
178
193
|
```typescript
|
|
179
|
-
const
|
|
194
|
+
const trace = tracerney.validate(agentOutput);
|
|
180
195
|
|
|
181
|
-
if (
|
|
182
|
-
console.log(
|
|
196
|
+
if (trace.isSuspicious) {
|
|
197
|
+
console.log(`[${trace.label}]: ${trace.reason}`);
|
|
198
|
+
|
|
199
|
+
// Option A: Hard block
|
|
200
|
+
if (trace.label === 'SUSPICIOUS_EGRESS') {
|
|
201
|
+
throw new Error('Security Policy Violation');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Option B: Surgical scrub
|
|
205
|
+
return trace.redactedContent;
|
|
183
206
|
}
|
|
184
207
|
```
|
|
185
208
|
|
|
186
209
|
```typescript
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
210
|
+
trace.isSuspicious // boolean — true if any pattern matched
|
|
211
|
+
trace.label // see manifest below
|
|
212
|
+
trace.reason // "Detected 2 finding(s): Email Address, AWS Access Key ID"
|
|
213
|
+
trace.redactedContent // pre-scrubbed version — use it or throw, your call
|
|
214
|
+
trace.findings // full per-pattern breakdown for logging/telemetry
|
|
191
215
|
```
|
|
192
216
|
|
|
217
|
+
### The Suspicious Manifest
|
|
218
|
+
|
|
219
|
+
| Trigger | Label | Recommended action |
|
|
220
|
+
|---|---|---|
|
|
221
|
+
| Email / Phone | `SUSPICIOUS_PII` | Usually Redact |
|
|
222
|
+
| API Keys / SSH / CC / SSN | `SUSPICIOUS_SECRET` | Usually Block |
|
|
223
|
+
| External URL smuggling | `SUSPICIOUS_EGRESS` | Always Block |
|
|
224
|
+
| Zero-width / BiDi / Base64 | `SUSPICIOUS_ENCODING` | Audit / Block |
|
|
225
|
+
|
|
193
226
|
---
|
|
194
227
|
|
|
195
|
-
## Pricing
|
|
228
|
+
## Pricing & Usage
|
|
229
|
+
|
|
230
|
+
- **Free Tier:** 50 scans/month with Layer 1 pattern detection
|
|
231
|
+
- **Pro Tier:** 2,500 scans/month with Layer 1 + Layer 2 LLM verification ($9/month)
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Ready for Advanced Protection?
|
|
236
|
+
|
|
237
|
+
Layer 2 (LLM Sentinel) adds AI-powered verification with **context-aware** threat detection and **zero prompt storage** — all responses are analyzed in-memory and immediately discarded.
|
|
196
238
|
|
|
197
|
-
|
|
198
|
-
- **Pro ($9/month):** 2,500 scans/month — Layer 1 + Layer 2 LLM Sentinel
|
|
239
|
+
**[Start Your Free Trial or Upgrade to Pro](https://www.tracerney.com/docs)** at tracerney.com
|
|
199
240
|
|
|
200
|
-
|
|
241
|
+
Includes:
|
|
242
|
+
- Dashboard with threat analytics
|
|
243
|
+
- API key management
|
|
244
|
+
- Team collaboration features
|
|
245
|
+
- Detailed threat fingerprints for compliance
|
|
246
|
+
- Priority support for Pro members
|
|
201
247
|
|
|
202
248
|
---
|
|
203
249
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandrobuilds/tracerney",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.25",
|
|
4
4
|
"description": "Lightweight prompt injection detection with Layer 1 (258 patterns) + Layer 2 (AI verification). Runs locally with zero data storage. Upgrade to Pro for context-aware threat analysis at tracerney.com",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|