@stackone/defender 0.3.1 → 0.4.1
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/LICENSE +190 -560
- package/README.md +8 -7
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +22 -21
- package/dist/index.d.mts +23 -22
- package/dist/index.mjs +2 -2
- package/dist/models/minilm-full-aug/config.json +26 -26
- package/dist/models/minilm-full-aug/model_quantized.onnx +0 -0
- package/dist/models/minilm-full-aug/tokenizer.json +30676 -30676
- package/dist/models/minilm-full-aug/tokenizer_config.json +14 -14
- package/package.json +10 -4
- /package/dist/{chunk-Cfxk5zVN.mjs → chunk-UvegZiLi.mjs} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -7,36 +7,28 @@ interface MLPWeights {
|
|
|
7
7
|
embedding_model_id?: string;
|
|
8
8
|
};
|
|
9
9
|
state_dict: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
"net.0.weight": number[][];
|
|
11
|
+
"net.0.bias": number[];
|
|
12
|
+
"net.3.weight": number[][];
|
|
13
|
+
"net.3.bias": number[];
|
|
14
|
+
"net.6.weight": number[][];
|
|
15
|
+
"net.6.bias": number[];
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/classifiers/weights.d.ts
|
|
20
20
|
declare const MLP_WEIGHTS: MLPWeights;
|
|
21
21
|
//#endregion
|
|
22
|
-
//#region src/classifiers/embedder.d.ts
|
|
23
|
-
interface EmbedderConfig {
|
|
24
|
-
modelId: string;
|
|
25
|
-
pooling: 'mean' | 'cls' | 'max';
|
|
26
|
-
normalize: boolean;
|
|
27
|
-
device?: 'cpu' | 'gpu' | 'auto';
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
22
|
//#region src/types.d.ts
|
|
31
|
-
type RiskLevel =
|
|
23
|
+
type RiskLevel = "low" | "medium" | "high" | "critical";
|
|
32
24
|
interface PatternMatch {
|
|
33
25
|
pattern: string;
|
|
34
26
|
matched: string;
|
|
35
27
|
position: number;
|
|
36
28
|
category: PatternCategory;
|
|
37
|
-
severity:
|
|
29
|
+
severity: "low" | "medium" | "high";
|
|
38
30
|
}
|
|
39
|
-
type PatternCategory =
|
|
31
|
+
type PatternCategory = "role_marker" | "instruction_override" | "role_assumption" | "security_bypass" | "command_execution" | "encoding_suspicious" | "structural";
|
|
40
32
|
interface Tier1Result {
|
|
41
33
|
matches: PatternMatch[];
|
|
42
34
|
structuralFlags: StructuralFlag[];
|
|
@@ -45,9 +37,9 @@ interface Tier1Result {
|
|
|
45
37
|
latencyMs: number;
|
|
46
38
|
}
|
|
47
39
|
interface StructuralFlag {
|
|
48
|
-
type:
|
|
40
|
+
type: "high_entropy" | "excessive_length" | "suspicious_formatting" | "nested_markers";
|
|
49
41
|
details: string;
|
|
50
|
-
severity:
|
|
42
|
+
severity: "low" | "medium" | "high";
|
|
51
43
|
}
|
|
52
44
|
interface RiskyFieldConfig {
|
|
53
45
|
fieldNames: string[];
|
|
@@ -83,7 +75,7 @@ interface PromptDefenseConfig {
|
|
|
83
75
|
};
|
|
84
76
|
tier2: {
|
|
85
77
|
enabled: boolean;
|
|
86
|
-
mode?:
|
|
78
|
+
mode?: "mlp" | "onnx";
|
|
87
79
|
highRiskThreshold: number;
|
|
88
80
|
mediumRiskThreshold: number;
|
|
89
81
|
skipBelowSize: number;
|
|
@@ -91,9 +83,17 @@ interface PromptDefenseConfig {
|
|
|
91
83
|
blockHighRisk: boolean;
|
|
92
84
|
}
|
|
93
85
|
//#endregion
|
|
86
|
+
//#region src/classifiers/embedder.d.ts
|
|
87
|
+
interface EmbedderConfig {
|
|
88
|
+
modelId: string;
|
|
89
|
+
pooling: "mean" | "cls" | "max";
|
|
90
|
+
normalize: boolean;
|
|
91
|
+
device?: "cpu" | "gpu" | "auto";
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
94
|
//#region src/classifiers/tier2-classifier.d.ts
|
|
95
95
|
interface Tier2ClassifierConfig {
|
|
96
|
-
mode:
|
|
96
|
+
mode: "mlp" | "onnx";
|
|
97
97
|
highRiskThreshold: number;
|
|
98
98
|
mediumRiskThreshold: number;
|
|
99
99
|
minTextLength: number;
|
|
@@ -122,6 +122,7 @@ interface PromptDefenseOptions {
|
|
|
122
122
|
tier2Weights?: MLPWeights;
|
|
123
123
|
blockHighRisk?: boolean;
|
|
124
124
|
defaultRiskLevel?: RiskLevel;
|
|
125
|
+
useDefaultToolRules?: boolean;
|
|
125
126
|
}
|
|
126
127
|
declare class PromptDefense {
|
|
127
128
|
private config;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as __name } from "./chunk-
|
|
1
|
+
import { t as __name } from "./chunk-UvegZiLi.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/classifiers/mlp.d.ts
|
|
4
4
|
interface MLPWeights {
|
|
@@ -8,36 +8,28 @@ interface MLPWeights {
|
|
|
8
8
|
embedding_model_id?: string;
|
|
9
9
|
};
|
|
10
10
|
state_dict: {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
"net.0.weight": number[][];
|
|
12
|
+
"net.0.bias": number[];
|
|
13
|
+
"net.3.weight": number[][];
|
|
14
|
+
"net.3.bias": number[];
|
|
15
|
+
"net.6.weight": number[][];
|
|
16
|
+
"net.6.bias": number[];
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/classifiers/weights.d.ts
|
|
21
21
|
declare const MLP_WEIGHTS: MLPWeights;
|
|
22
22
|
//#endregion
|
|
23
|
-
//#region src/classifiers/embedder.d.ts
|
|
24
|
-
interface EmbedderConfig {
|
|
25
|
-
modelId: string;
|
|
26
|
-
pooling: 'mean' | 'cls' | 'max';
|
|
27
|
-
normalize: boolean;
|
|
28
|
-
device?: 'cpu' | 'gpu' | 'auto';
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
23
|
//#region src/types.d.ts
|
|
32
|
-
type RiskLevel =
|
|
24
|
+
type RiskLevel = "low" | "medium" | "high" | "critical";
|
|
33
25
|
interface PatternMatch {
|
|
34
26
|
pattern: string;
|
|
35
27
|
matched: string;
|
|
36
28
|
position: number;
|
|
37
29
|
category: PatternCategory;
|
|
38
|
-
severity:
|
|
30
|
+
severity: "low" | "medium" | "high";
|
|
39
31
|
}
|
|
40
|
-
type PatternCategory =
|
|
32
|
+
type PatternCategory = "role_marker" | "instruction_override" | "role_assumption" | "security_bypass" | "command_execution" | "encoding_suspicious" | "structural";
|
|
41
33
|
interface Tier1Result {
|
|
42
34
|
matches: PatternMatch[];
|
|
43
35
|
structuralFlags: StructuralFlag[];
|
|
@@ -46,9 +38,9 @@ interface Tier1Result {
|
|
|
46
38
|
latencyMs: number;
|
|
47
39
|
}
|
|
48
40
|
interface StructuralFlag {
|
|
49
|
-
type:
|
|
41
|
+
type: "high_entropy" | "excessive_length" | "suspicious_formatting" | "nested_markers";
|
|
50
42
|
details: string;
|
|
51
|
-
severity:
|
|
43
|
+
severity: "low" | "medium" | "high";
|
|
52
44
|
}
|
|
53
45
|
interface RiskyFieldConfig {
|
|
54
46
|
fieldNames: string[];
|
|
@@ -84,7 +76,7 @@ interface PromptDefenseConfig {
|
|
|
84
76
|
};
|
|
85
77
|
tier2: {
|
|
86
78
|
enabled: boolean;
|
|
87
|
-
mode?:
|
|
79
|
+
mode?: "mlp" | "onnx";
|
|
88
80
|
highRiskThreshold: number;
|
|
89
81
|
mediumRiskThreshold: number;
|
|
90
82
|
skipBelowSize: number;
|
|
@@ -92,9 +84,17 @@ interface PromptDefenseConfig {
|
|
|
92
84
|
blockHighRisk: boolean;
|
|
93
85
|
}
|
|
94
86
|
//#endregion
|
|
87
|
+
//#region src/classifiers/embedder.d.ts
|
|
88
|
+
interface EmbedderConfig {
|
|
89
|
+
modelId: string;
|
|
90
|
+
pooling: "mean" | "cls" | "max";
|
|
91
|
+
normalize: boolean;
|
|
92
|
+
device?: "cpu" | "gpu" | "auto";
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
95
|
//#region src/classifiers/tier2-classifier.d.ts
|
|
96
96
|
interface Tier2ClassifierConfig {
|
|
97
|
-
mode:
|
|
97
|
+
mode: "mlp" | "onnx";
|
|
98
98
|
highRiskThreshold: number;
|
|
99
99
|
mediumRiskThreshold: number;
|
|
100
100
|
minTextLength: number;
|
|
@@ -123,6 +123,7 @@ interface PromptDefenseOptions {
|
|
|
123
123
|
tier2Weights?: MLPWeights;
|
|
124
124
|
blockHighRisk?: boolean;
|
|
125
125
|
defaultRiskLevel?: RiskLevel;
|
|
126
|
+
useDefaultToolRules?: boolean;
|
|
126
127
|
}
|
|
127
128
|
declare class PromptDefense {
|
|
128
129
|
private config;
|