@stackone/defender 0.4.1 → 0.4.2
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 +21 -7
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,11 @@ import { createPromptDefense } from '@stackone/defender';
|
|
|
18
18
|
|
|
19
19
|
// Create defense with Tier 1 (patterns) + Tier 2 (ML classifier)
|
|
20
20
|
// blockHighRisk: true enables the allowed/blocked decision
|
|
21
|
-
const defense = createPromptDefense({
|
|
21
|
+
const defense = createPromptDefense({
|
|
22
|
+
enableTier2: true,
|
|
23
|
+
blockHighRisk: true,
|
|
24
|
+
useDefaultToolRules: true, // Enable built-in per-tool base risk and field-handling rules (risky-field overrides always apply)
|
|
25
|
+
});
|
|
22
26
|
|
|
23
27
|
// Defend a tool result — ONNX model (~22MB) auto-loads on first call
|
|
24
28
|
const result = await defense.defendToolResult(toolOutput, 'gmail_get_message');
|
|
@@ -71,6 +75,8 @@ Use `allowed` for blocking decisions:
|
|
|
71
75
|
|
|
72
76
|
`riskLevel` is diagnostic metadata. It starts at the tool's base risk level and can only be escalated by detections — never reduced. Use it for logging and monitoring, not for allow/block logic.
|
|
73
77
|
|
|
78
|
+
The following base risk levels apply when `useDefaultToolRules: true` is set. Without it, tools use `defaultRiskLevel` (defaults to `medium`).
|
|
79
|
+
|
|
74
80
|
| Tool Pattern | Base Risk | Why |
|
|
75
81
|
|--------------|-----------|-----|
|
|
76
82
|
| `gmail_*`, `email_*` | `high` | Emails are the #1 injection vector |
|
|
@@ -98,9 +104,10 @@ Create a defense instance.
|
|
|
98
104
|
|
|
99
105
|
```typescript
|
|
100
106
|
const defense = createPromptDefense({
|
|
101
|
-
enableTier1: true,
|
|
102
|
-
enableTier2: true,
|
|
103
|
-
blockHighRisk: true,
|
|
107
|
+
enableTier1: true, // Pattern detection (default: true)
|
|
108
|
+
enableTier2: true, // ML classification (default: false)
|
|
109
|
+
blockHighRisk: true, // Block high/critical content (default: false)
|
|
110
|
+
useDefaultToolRules: true, // Enable built-in per-tool base risk and field-handling rules (default: false)
|
|
104
111
|
defaultRiskLevel: 'medium',
|
|
105
112
|
});
|
|
106
113
|
```
|
|
@@ -179,7 +186,11 @@ await mlpDefense.warmupTier2();
|
|
|
179
186
|
import { generateText, tool } from 'ai';
|
|
180
187
|
import { createPromptDefense } from '@stackone/defender';
|
|
181
188
|
|
|
182
|
-
const defense = createPromptDefense({
|
|
189
|
+
const defense = createPromptDefense({
|
|
190
|
+
enableTier2: true,
|
|
191
|
+
blockHighRisk: true,
|
|
192
|
+
useDefaultToolRules: true,
|
|
193
|
+
});
|
|
183
194
|
await defense.warmupTier2(); // optional, avoids first-call latency
|
|
184
195
|
|
|
185
196
|
const result = await generateText({
|
|
@@ -204,7 +215,9 @@ const result = await generateText({
|
|
|
204
215
|
|
|
205
216
|
## Tool-Specific Rules
|
|
206
217
|
|
|
207
|
-
|
|
218
|
+
> **Note:** `useDefaultToolRules: true` enables built-in per-tool **risk rules** (base risk, skip fields, max lengths, thresholds). Risky-field detection (which fields get sanitized) uses tool-specific overrides regardless of this setting.
|
|
219
|
+
|
|
220
|
+
Built-in per-tool rules define the base risk level and field-handling parameters for each tool provider. See the [base risk table](#understanding-allowed-vs-risklevel) for risk levels.
|
|
208
221
|
|
|
209
222
|
| Tool Pattern | Risky Fields | Notes |
|
|
210
223
|
|---|---|---|
|
|
@@ -212,7 +225,8 @@ Built-in rules define which fields to sanitize and what base risk level to use f
|
|
|
212
225
|
| `documents_*` | name, description, content, title | User-generated content |
|
|
213
226
|
| `github_*` | name, title, body, description | PRs, issues, comments |
|
|
214
227
|
| `hris_*` | name, notes, bio, description | Employee free-text fields |
|
|
215
|
-
| `ats_
|
|
228
|
+
| `ats_*` | name, notes, description, summary | Candidate data |
|
|
229
|
+
| `crm_*` | name, description, notes, content | Customer data |
|
|
216
230
|
|
|
217
231
|
Tools not matching any pattern use `medium` base risk with default risky field detection.
|
|
218
232
|
|