@adonis-agora/agent 0.34.1 → 0.36.0
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/CHANGELOG.md +24 -0
- package/README.md +34 -0
- package/dist/assets/spa/assets/index-7XqfoeQH.js +9 -0
- package/dist/assets/spa/index.html +1 -1
- package/dist/providers/agent_provider.d.ts.map +1 -1
- package/dist/providers/agent_provider.js +4 -0
- package/dist/providers/agent_provider.js.map +1 -1
- package/dist/src/agent-deps-factory.d.ts +5 -0
- package/dist/src/agent-deps-factory.d.ts.map +1 -1
- package/dist/src/agent-deps-factory.js +6 -0
- package/dist/src/agent-deps-factory.js.map +1 -1
- package/dist/src/agent-deps.d.ts +5 -0
- package/dist/src/agent-deps.d.ts.map +1 -1
- package/dist/src/agent-deps.js.map +1 -1
- package/dist/src/define_config.d.ts +12 -0
- package/dist/src/define_config.d.ts.map +1 -1
- package/dist/src/define_config.js.map +1 -1
- package/dist/src/guardrails/agent.d.ts +211 -0
- package/dist/src/guardrails/agent.d.ts.map +1 -0
- package/dist/src/guardrails/agent.js +433 -0
- package/dist/src/guardrails/agent.js.map +1 -0
- package/dist/src/guardrails/detectors/custom.d.ts +9 -0
- package/dist/src/guardrails/detectors/custom.d.ts.map +1 -0
- package/dist/src/guardrails/detectors/custom.js +81 -0
- package/dist/src/guardrails/detectors/custom.js.map +1 -0
- package/dist/src/guardrails/detectors/injection.d.ts +23 -0
- package/dist/src/guardrails/detectors/injection.d.ts.map +1 -0
- package/dist/src/guardrails/detectors/injection.js +208 -0
- package/dist/src/guardrails/detectors/injection.js.map +1 -0
- package/dist/src/guardrails/detectors/pii.d.ts +23 -0
- package/dist/src/guardrails/detectors/pii.d.ts.map +1 -0
- package/dist/src/guardrails/detectors/pii.js +295 -0
- package/dist/src/guardrails/detectors/pii.js.map +1 -0
- package/dist/src/guardrails/detectors/secrets.d.ts +5 -0
- package/dist/src/guardrails/detectors/secrets.d.ts.map +1 -0
- package/dist/src/guardrails/detectors/secrets.js +110 -0
- package/dist/src/guardrails/detectors/secrets.js.map +1 -0
- package/dist/src/guardrails/detectors/tool-poisoning.d.ts +16 -0
- package/dist/src/guardrails/detectors/tool-poisoning.d.ts.map +1 -0
- package/dist/src/guardrails/detectors/tool-poisoning.js +116 -0
- package/dist/src/guardrails/detectors/tool-poisoning.js.map +1 -0
- package/dist/src/guardrails/engine.d.ts +90 -0
- package/dist/src/guardrails/engine.d.ts.map +1 -0
- package/dist/src/guardrails/engine.js +324 -0
- package/dist/src/guardrails/engine.js.map +1 -0
- package/dist/src/guardrails/glob.d.ts +4 -0
- package/dist/src/guardrails/glob.d.ts.map +1 -0
- package/dist/src/guardrails/glob.js +20 -0
- package/dist/src/guardrails/glob.js.map +1 -0
- package/dist/src/guardrails/index.d.ts +20 -0
- package/dist/src/guardrails/index.d.ts.map +1 -0
- package/dist/src/guardrails/index.js +20 -0
- package/dist/src/guardrails/index.js.map +1 -0
- package/dist/src/guardrails/segments.d.ts +14 -0
- package/dist/src/guardrails/segments.d.ts.map +1 -0
- package/dist/src/guardrails/segments.js +32 -0
- package/dist/src/guardrails/segments.js.map +1 -0
- package/dist/src/guardrails/types.d.ts +161 -0
- package/dist/src/guardrails/types.d.ts.map +1 -0
- package/dist/src/guardrails/types.js +49 -0
- package/dist/src/guardrails/types.js.map +1 -0
- package/dist/src/guardrails/vault.d.ts +44 -0
- package/dist/src/guardrails/vault.d.ts.map +1 -0
- package/dist/src/guardrails/vault.js +103 -0
- package/dist/src/guardrails/vault.js.map +1 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/mcp-client/index.d.ts +1 -1
- package/dist/src/mcp-client/index.d.ts.map +1 -1
- package/dist/src/mcp-client/index.js.map +1 -1
- package/dist/src/mcp-client/options.d.ts +32 -0
- package/dist/src/mcp-client/options.d.ts.map +1 -1
- package/dist/src/mcp-client/tool-source.d.ts +2 -0
- package/dist/src/mcp-client/tool-source.d.ts.map +1 -1
- package/dist/src/mcp-client/tool-source.js +27 -1
- package/dist/src/mcp-client/tool-source.js.map +1 -1
- package/dist/src/rag/http-reranker.d.ts +46 -0
- package/dist/src/rag/http-reranker.d.ts.map +1 -0
- package/dist/src/rag/http-reranker.js +83 -0
- package/dist/src/rag/http-reranker.js.map +1 -0
- package/dist/src/rag/hybrid-retriever.d.ts +6 -1
- package/dist/src/rag/hybrid-retriever.d.ts.map +1 -1
- package/dist/src/rag/hybrid-retriever.js +27 -3
- package/dist/src/rag/hybrid-retriever.js.map +1 -1
- package/dist/src/rag/index.d.ts +6 -2
- package/dist/src/rag/index.d.ts.map +1 -1
- package/dist/src/rag/index.js +6 -2
- package/dist/src/rag/index.js.map +1 -1
- package/dist/src/rag/lexical-query.d.ts +28 -0
- package/dist/src/rag/lexical-query.d.ts.map +1 -0
- package/dist/src/rag/lexical-query.js +90 -0
- package/dist/src/rag/lexical-query.js.map +1 -0
- package/dist/src/rag/lexical-retriever.d.ts +23 -0
- package/dist/src/rag/lexical-retriever.d.ts.map +1 -0
- package/dist/src/rag/lexical-retriever.js +28 -0
- package/dist/src/rag/lexical-retriever.js.map +1 -0
- package/dist/src/rag/openai-embeddings.d.ts +62 -0
- package/dist/src/rag/openai-embeddings.d.ts.map +1 -0
- package/dist/src/rag/openai-embeddings.js +106 -0
- package/dist/src/rag/openai-embeddings.js.map +1 -0
- package/dist/src/rag/pg-vector-store.d.ts +133 -6
- package/dist/src/rag/pg-vector-store.d.ts.map +1 -1
- package/dist/src/rag/pg-vector-store.js +272 -31
- package/dist/src/rag/pg-vector-store.js.map +1 -1
- package/dist/src/rag/vector-store.d.ts +15 -0
- package/dist/src/rag/vector-store.d.ts.map +1 -1
- package/dist/src/rag/vector-store.js +4 -0
- package/dist/src/rag/vector-store.js.map +1 -1
- package/dist/src/stores/factory.d.ts +25 -3
- package/dist/src/stores/factory.d.ts.map +1 -1
- package/dist/src/stores/factory.js +21 -3
- package/dist/src/stores/factory.js.map +1 -1
- package/dist/src/testing/fake-embedding-provider.d.ts +12 -0
- package/dist/src/testing/fake-embedding-provider.d.ts.map +1 -1
- package/dist/src/testing/fake-embedding-provider.js +35 -0
- package/dist/src/testing/fake-embedding-provider.js.map +1 -1
- package/dist/src/testing/index.d.ts +1 -1
- package/dist/src/testing/index.d.ts.map +1 -1
- package/dist/src/testing/index.js +1 -1
- package/dist/src/testing/index.js.map +1 -1
- package/package.json +9 -3
- package/dist/assets/spa/assets/index-DjIMQOxi.js +0 -9
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
const W = String.raw `[\s\S]{0,40}?`;
|
|
2
|
+
export const INJECTION_SIGNALS = [
|
|
3
|
+
// Instruction override.
|
|
4
|
+
{
|
|
5
|
+
id: 'ignore_previous',
|
|
6
|
+
re: new RegExp(String.raw `\b(?:ignore|disregard|forget|override|bypass|skip)\b${W}\b(?:all\s+|any\s+|the\s+|your\s+|my\s+)?(?:previous|prior|above|earlier|preceding|original|system|initial)\b${W}\b(?:instructions?|prompts?|rules?|directions?|guidelines?|messages?|context)\b`, 'gi'),
|
|
7
|
+
weight: 0.75,
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
id: 'ignore_previous_pt',
|
|
11
|
+
re: new RegExp(String.raw `\b(?:ignore|ignora|desconsidere|desconsidera|esque[çc]a|esquece|descarte)\b${W}\b(?:as\s+|todas\s+as\s+|suas\s+|tuas\s+)?(?:instru[çc][õo]es|regras|orienta[çc][õo]es|mensagens|prompts?)\b${W}\b(?:anteriores|acima|pr[ée]vias|do\s+sistema|originais)\b`, 'gi'),
|
|
12
|
+
weight: 0.75,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: 'ignore_previous_es',
|
|
16
|
+
re: new RegExp(String.raw `\b(?:ignora|ignore|olvida|olvide|descarta)\b${W}\b(?:las\s+|todas\s+las\s+|tus\s+)?(?:instrucciones|reglas|indicaciones)\b${W}\b(?:anteriores|previas|del\s+sistema)\b`, 'gi'),
|
|
17
|
+
weight: 0.75,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: 'new_instructions',
|
|
21
|
+
re: /\b(?:new|updated|real|actual|true)\s+(?:system\s+)?instructions?\s*(?::|follow|are)|\bnovas\s+instru[çc][õo]es\s*:|\bnuevas\s+instrucciones\s*:/gi,
|
|
22
|
+
weight: 0.45,
|
|
23
|
+
},
|
|
24
|
+
// Role hijack / persona jailbreaks.
|
|
25
|
+
{
|
|
26
|
+
id: 'role_hijack',
|
|
27
|
+
re: /\b(?:you\s+are\s+now|from\s+now\s+on\s+you\s+(?:are|will)|act\s+as\s+(?:an?\s+)?(?:unrestricted|unfiltered|evil|jailbroken)|pretend\s+(?:to\s+be|you\s+are)\s+(?:an?\s+)?(?:unrestricted|unfiltered|different\s+ai)|a\s+partir\s+de\s+agora\s+voc[êe]\s+(?:[ée]|ser[áa])|voc[êe]\s+agora\s+[ée]|ahora\s+eres)\b/gi,
|
|
28
|
+
weight: 0.45,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'jailbreak_persona',
|
|
32
|
+
re: /\b(?:DAN|do\s+anything\s+now|developer\s+mode|god\s+mode|jailbreak(?:ed)?|STAN|DUDE\s+mode|AIM\s+mode|no\s+(?:restrictions|filters|guidelines|limits)\s+mode|modo\s+desenvolvedor|sem\s+restri[çc][õo]es)\b/g,
|
|
33
|
+
weight: 0.55,
|
|
34
|
+
},
|
|
35
|
+
// Prompt / secret extraction.
|
|
36
|
+
{
|
|
37
|
+
id: 'prompt_leak',
|
|
38
|
+
re: /\b(?:reveal|print|show|repeat|output|display|leak|tell\s+me|write\s+out)\b[\s\S]{0,30}?\b(?:your|the)\s+(?:system\s+prompt|initial\s+(?:prompt|instructions)|hidden\s+(?:prompt|instructions)|instructions\s+above|developer\s+message)\b|\b(?:mostre|revele|repita|imprima)\b[\s\S]{0,30}?\b(?:seu|o)\s+prompt\s+(?:do\s+sistema|inicial)\b/gi,
|
|
39
|
+
weight: 0.6,
|
|
40
|
+
},
|
|
41
|
+
// Role / delimiter spoofing: chat-template tokens and fake headers.
|
|
42
|
+
{
|
|
43
|
+
id: 'role_tokens',
|
|
44
|
+
re: /<\|(?:im_start|im_end|system|endoftext|start_header_id|end_header_id|eot_id)\|>|\[\/?INST\]|<<\/?SYS>>|<\/?(?:system|assistant|developer)>|^\s*#{2,}\s*(?:system|assistant|developer)\s*(?:prompt|message)?\s*:?\s*$/gim,
|
|
45
|
+
weight: 0.55,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'fake_system',
|
|
49
|
+
re: /^\s*(?:system|assistant|developer)\s*(?:message|prompt|note|override)?\s*:\s*\S/gim,
|
|
50
|
+
weight: 0.3,
|
|
51
|
+
},
|
|
52
|
+
// Indirect injection aimed at the agent reading the content.
|
|
53
|
+
{
|
|
54
|
+
id: 'addressed_to_ai',
|
|
55
|
+
re: /\b(?:(?:note|message|instructions?)\s+(?:to|for)\s+(?:the\s+)?(?:ai|assistant|llm|agent|model|chatbot)|(?:ai|assistant|llm|agent)s?\s*(?:reading|processing|summari[sz]ing)\s+this|if\s+you\s+are\s+an?\s+(?:ai|assistant|llm|language\s+model|agent)|aten[çc][ãa]o\s*,?\s*(?:ia|assistente|agente)|se\s+voc[êe]\s+[ée]\s+(?:uma\s+)?(?:ia|intelig[êe]ncia\s+artificial|assistente))\b/gi,
|
|
56
|
+
weight: 0.55,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: 'tool_directive',
|
|
60
|
+
re: /\b(?:call|invoke|use|run|execute|chame|use|execute)\s+(?:the\s+|a\s+|o\s+|a\s+ferramenta\s+)?[`'"]?[\w-]+(?:__[\w-]+)[`'"]?\s*(?:tool|function|ferramenta)?|\b(?:send|forward|email|post|upload|exfiltrate|envie|encaminhe)\b[\s\S]{0,40}?\b(?:(?:all|every|the)\s+)?(?:(?:user'?s?|their|this|todos\s+os|os)\s+)?(?:emails?|files?|documents?|credentials?|passwords?|secrets?|tokens?|keys?|conversation|chat\s+history|dados|arquivos|senhas)\b[\s\S]{0,40}?\b(?:to|para)\s+\S+@\S+|\bto\s+https?:\/\//gi,
|
|
61
|
+
weight: 0.45,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'secrecy',
|
|
65
|
+
re: /\b(?:do\s+not|don'?t|never)\s+(?:tell|inform|mention|reveal|show|alert|notify)\s+(?:this\s+to\s+)?(?:the\s+)?user\b|\bwithout\s+(?:telling|informing|notifying)\s+the\s+user\b|\bn[ãa]o\s+(?:conte|informe|mencione|avise)\s+(?:ao|o)\s+usu[áa]rio\b/gi,
|
|
66
|
+
weight: 0.5,
|
|
67
|
+
},
|
|
68
|
+
// Exfiltration through rendered markdown/HTML.
|
|
69
|
+
{
|
|
70
|
+
id: 'exfil_markdown',
|
|
71
|
+
re: /!\[[^\]]*\]\(\s*https?:\/\/[^)\s]+\?[^)\s]*=[^)\s]*(?:\{|%7B|\$|<)?[^)]*\)|<img\b[^>]*\bsrc\s*=\s*["']?https?:\/\/[^"'>\s]+\?[^"'>\s]*=/gi,
|
|
72
|
+
weight: 0.4,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'html_comment_instructions',
|
|
76
|
+
re: /<!--[\s\S]{0,500}?\b(?:ignore|instruction|assistant|ai|agent|system|prompt|instru[çc][ãa]o|assistente)\b[\s\S]{0,500}?-->/gi,
|
|
77
|
+
weight: 0.45,
|
|
78
|
+
},
|
|
79
|
+
// Encoded payloads that decode to instructions are checked separately (see scoreEncoded).
|
|
80
|
+
];
|
|
81
|
+
/** Characters used to hide instructions from people while models still read them. */
|
|
82
|
+
const TAG_CHARS = /[\u{E0000}-\u{E007F}]+/gu;
|
|
83
|
+
const BIDI = /[\u202A-\u202E\u2066-\u2069]/g;
|
|
84
|
+
const ZERO_WIDTH_RUN = /[\u200B-\u200D\u2060\uFEFF]{3,}/g;
|
|
85
|
+
/**
|
|
86
|
+
* Base64 to text, byte per character. Only printable ASCII is ever acted upon, so no UTF-8 decoding
|
|
87
|
+
* is needed — and `atob` keeps this free of Node's `Buffer`.
|
|
88
|
+
*/
|
|
89
|
+
function decodeBase64Ascii(b64) {
|
|
90
|
+
try {
|
|
91
|
+
return atob(b64);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Decodes Unicode tag characters ("ASCII smuggling") back to the ASCII they encode. */
|
|
98
|
+
export function decodeTagChars(s) {
|
|
99
|
+
let out = '';
|
|
100
|
+
for (const ch of s) {
|
|
101
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
102
|
+
if (cp >= 0xe0020 && cp <= 0xe007e)
|
|
103
|
+
out += String.fromCharCode(cp - 0xe0000);
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
function matchSignals(text, offset, into, weights) {
|
|
108
|
+
for (const s of INJECTION_SIGNALS) {
|
|
109
|
+
s.re.lastIndex = 0;
|
|
110
|
+
for (let m = s.re.exec(text); m; m = s.re.exec(text)) {
|
|
111
|
+
if (m[0].length === 0) {
|
|
112
|
+
s.re.lastIndex++;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
weights.set(s.id, Math.max(weights.get(s.id) ?? 0, s.weight));
|
|
116
|
+
const list = into.get(s.id) ?? [];
|
|
117
|
+
list.push({
|
|
118
|
+
detector: 'injection',
|
|
119
|
+
category: `injection.${s.id}`,
|
|
120
|
+
start: offset < 0 ? m.index : offset,
|
|
121
|
+
end: offset < 0 ? m.index + m[0].length : offset,
|
|
122
|
+
score: s.weight,
|
|
123
|
+
value: m[0],
|
|
124
|
+
spanned: offset < 0,
|
|
125
|
+
});
|
|
126
|
+
into.set(s.id, list);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Scores a text; findings are returned only when the score reaches `threshold`. */
|
|
131
|
+
export function scoreInjection(text, threshold = 0.5) {
|
|
132
|
+
const byId = new Map();
|
|
133
|
+
const weights = new Map();
|
|
134
|
+
matchSignals(text, -1, byId, weights);
|
|
135
|
+
// Hidden Unicode: suspicious on its own; the decoded text is scanned too.
|
|
136
|
+
TAG_CHARS.lastIndex = 0;
|
|
137
|
+
for (let m = TAG_CHARS.exec(text); m; m = TAG_CHARS.exec(text)) {
|
|
138
|
+
weights.set('hidden_unicode', 0.8);
|
|
139
|
+
const list = byId.get('hidden_unicode') ?? [];
|
|
140
|
+
list.push({
|
|
141
|
+
detector: 'injection',
|
|
142
|
+
category: 'injection.hidden_unicode',
|
|
143
|
+
start: m.index,
|
|
144
|
+
end: m.index + m[0].length,
|
|
145
|
+
score: 0.8,
|
|
146
|
+
value: m[0],
|
|
147
|
+
spanned: true,
|
|
148
|
+
});
|
|
149
|
+
byId.set('hidden_unicode', list);
|
|
150
|
+
const decoded = decodeTagChars(m[0]);
|
|
151
|
+
if (decoded)
|
|
152
|
+
matchSignals(decoded, m.index, byId, weights);
|
|
153
|
+
}
|
|
154
|
+
for (const re of [BIDI, ZERO_WIDTH_RUN]) {
|
|
155
|
+
re.lastIndex = 0;
|
|
156
|
+
for (let m = re.exec(text); m; m = re.exec(text)) {
|
|
157
|
+
weights.set('invisible_chars', Math.max(weights.get('invisible_chars') ?? 0, 0.3));
|
|
158
|
+
const list = byId.get('invisible_chars') ?? [];
|
|
159
|
+
list.push({
|
|
160
|
+
detector: 'injection',
|
|
161
|
+
category: 'injection.invisible_chars',
|
|
162
|
+
start: m.index,
|
|
163
|
+
end: m.index + m[0].length,
|
|
164
|
+
score: 0.3,
|
|
165
|
+
value: m[0],
|
|
166
|
+
spanned: true,
|
|
167
|
+
});
|
|
168
|
+
byId.set('invisible_chars', list);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Base64 blobs that decode to instructions.
|
|
172
|
+
const B64 = /(?<![A-Za-z0-9+/=])[A-Za-z0-9+/]{40,}={0,2}(?![A-Za-z0-9+/=])/g;
|
|
173
|
+
for (let m = B64.exec(text); m; m = B64.exec(text)) {
|
|
174
|
+
const decoded = decodeBase64Ascii(m[0]);
|
|
175
|
+
if (decoded === undefined)
|
|
176
|
+
continue;
|
|
177
|
+
if (!/^[\x20-\x7E\s]+$/.test(decoded))
|
|
178
|
+
continue;
|
|
179
|
+
const inner = new Map();
|
|
180
|
+
const innerWeights = new Map();
|
|
181
|
+
matchSignals(decoded, m.index, inner, innerWeights);
|
|
182
|
+
if (innerWeights.size > 0) {
|
|
183
|
+
weights.set('encoded_instructions', 0.6);
|
|
184
|
+
byId.set('encoded_instructions', [
|
|
185
|
+
{
|
|
186
|
+
detector: 'injection',
|
|
187
|
+
category: 'injection.encoded_instructions',
|
|
188
|
+
start: m.index,
|
|
189
|
+
end: m.index + m[0].length,
|
|
190
|
+
score: 0.6,
|
|
191
|
+
value: m[0],
|
|
192
|
+
spanned: true,
|
|
193
|
+
},
|
|
194
|
+
]);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
let keep = 1;
|
|
198
|
+
for (const w of weights.values())
|
|
199
|
+
keep *= 1 - w;
|
|
200
|
+
const score = Math.round((1 - keep) * 1000) / 1000;
|
|
201
|
+
if (score < threshold)
|
|
202
|
+
return { score, findings: [] };
|
|
203
|
+
const findings = [...byId.values()]
|
|
204
|
+
.flat()
|
|
205
|
+
.map((f) => ({ ...f, score: Math.max(f.score, score) }));
|
|
206
|
+
return { score, findings };
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=injection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection.js","sourceRoot":"","sources":["../../../../src/guardrails/detectors/injection.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAA,eAAe,CAAC;AAEpC,MAAM,CAAC,MAAM,iBAAiB,GAAa;IACzC,wBAAwB;IACxB;QACE,EAAE,EAAE,iBAAiB;QACrB,EAAE,EAAE,IAAI,MAAM,CACZ,MAAM,CAAC,GAAG,CAAA,uDAAuD,CAAC,gHAAgH,CAAC,iFAA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AAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;YACzC,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE;gBAC/B;oBACE,QAAQ,EAAE,WAAW;oBACrB,QAAQ,EAAE,gCAAgC;oBAC1C,KAAK,EAAE,CAAC,CAAC,KAAK;oBACd,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;oBAC1B,KAAK,EAAE,GAAG;oBACV,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;oBACX,OAAO,EAAE,IAAI;iBACd;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,EAAE;QAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACnD,IAAI,KAAK,GAAG,SAAS;QAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IACtD,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;SAChC,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Finding, PiiType } from '../types.js';
|
|
2
|
+
/** Dotted-quad IPv4 with every octet in 0-255 and no leading zeros. */
|
|
3
|
+
export declare function isIPv4(raw: string): boolean;
|
|
4
|
+
/** Luhn (mod 10) checksum over a digit string. */
|
|
5
|
+
export declare function luhnValid(digits: string): boolean;
|
|
6
|
+
/** Card brands by IIN prefix (digits only). Unknown prefixes are not treated as cards. */
|
|
7
|
+
export declare function cardBrand(digits: string): string | undefined;
|
|
8
|
+
/** CPF (Brazilian individual taxpayer id): 11 digits, two mod-11 check digits. */
|
|
9
|
+
export declare function cpfValid(raw: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* CNPJ (Brazilian company id), numeric or the alphanumeric format in use since July 2026: 12
|
|
12
|
+
* characters [0-9A-Z] + 2 check digits, each character valued at its ASCII code minus 48.
|
|
13
|
+
*/
|
|
14
|
+
export declare function cnpjValid(raw: string): boolean;
|
|
15
|
+
/** US Social Security Number structure (no 000/666/9xx area, no 00 group, no 0000 serial). */
|
|
16
|
+
export declare function ssnValid(raw: string): boolean;
|
|
17
|
+
/** IBAN: known country length and ISO 7064 mod 97-10 checksum. */
|
|
18
|
+
export declare function ibanValid(raw: string): boolean;
|
|
19
|
+
/** Phone numbers: international (+CC), Brazilian and North American formats with separators. */
|
|
20
|
+
export declare function phoneValid(raw: string): boolean;
|
|
21
|
+
/** PII with format + checksum validation. Overlaps are resolved by the caller (longest, earliest). */
|
|
22
|
+
export declare function detectPii(text: string, types?: readonly PiiType[]): Finding[];
|
|
23
|
+
//# sourceMappingURL=pii.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii.d.ts","sourceRoot":"","sources":["../../../../src/guardrails/detectors/pii.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGpD,uEAAuE;AACvE,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAK3C;AAED,kDAAkD;AAClD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAcjD;AAED,0FAA0F;AAC1F,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkC5D;AAED,kFAAkF;AAClF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAU7C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAa9C;AAED,8FAA8F;AAC9F,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAY7C;AAsED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAa9C;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAS/C;AAkED,sGAAsG;AACtG,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,SAAS,OAAO,EAAc,GAAG,OAAO,EAAE,CAqBxF"}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { PII_TYPES } from '../types.js';
|
|
2
|
+
/** Dotted-quad IPv4 with every octet in 0-255 and no leading zeros. */
|
|
3
|
+
export function isIPv4(raw) {
|
|
4
|
+
const parts = raw.split('.');
|
|
5
|
+
return (parts.length === 4 && parts.every((p) => /^(?:0|[1-9]\d{0,2})$/.test(p) && Number(p) <= 255));
|
|
6
|
+
}
|
|
7
|
+
/** Luhn (mod 10) checksum over a digit string. */
|
|
8
|
+
export function luhnValid(digits) {
|
|
9
|
+
if (!/^\d+$/.test(digits))
|
|
10
|
+
return false;
|
|
11
|
+
let sum = 0;
|
|
12
|
+
let double = false;
|
|
13
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
14
|
+
let d = digits.charCodeAt(i) - 48;
|
|
15
|
+
if (double) {
|
|
16
|
+
d *= 2;
|
|
17
|
+
if (d > 9)
|
|
18
|
+
d -= 9;
|
|
19
|
+
}
|
|
20
|
+
sum += d;
|
|
21
|
+
double = !double;
|
|
22
|
+
}
|
|
23
|
+
return sum % 10 === 0;
|
|
24
|
+
}
|
|
25
|
+
/** Card brands by IIN prefix (digits only). Unknown prefixes are not treated as cards. */
|
|
26
|
+
export function cardBrand(digits) {
|
|
27
|
+
const p2 = Number(digits.slice(0, 2));
|
|
28
|
+
const p3 = Number(digits.slice(0, 3));
|
|
29
|
+
const p4 = Number(digits.slice(0, 4));
|
|
30
|
+
const p6 = Number(digits.slice(0, 6));
|
|
31
|
+
const len = digits.length;
|
|
32
|
+
// Brazilian brands first: their ranges overlap Visa/Discover/Mastercard prefixes.
|
|
33
|
+
if ([
|
|
34
|
+
401178, 401179, 431274, 438935, 451416, 457393, 457631, 457632, 504175, 627780, 636297,
|
|
35
|
+
636368,
|
|
36
|
+
].includes(p6))
|
|
37
|
+
return 'elo';
|
|
38
|
+
if ((p6 >= 506699 && p6 <= 506778) ||
|
|
39
|
+
(p6 >= 509000 && p6 <= 509999) ||
|
|
40
|
+
(p6 >= 650031 && p6 <= 650051))
|
|
41
|
+
return 'elo';
|
|
42
|
+
if (p6 === 606282 || p4 === 3841)
|
|
43
|
+
return 'hipercard';
|
|
44
|
+
if (digits.startsWith('4') && (len === 13 || len === 16 || len === 19))
|
|
45
|
+
return 'visa';
|
|
46
|
+
if (((p2 >= 51 && p2 <= 55) || (p4 >= 2221 && p4 <= 2720)) && len === 16)
|
|
47
|
+
return 'mastercard';
|
|
48
|
+
if ((p2 === 34 || p2 === 37) && len === 15)
|
|
49
|
+
return 'amex';
|
|
50
|
+
if ((p4 === 6011 || p2 === 65 || (p3 >= 644 && p3 <= 649)) && len >= 16)
|
|
51
|
+
return 'discover';
|
|
52
|
+
if ((p2 === 36 || p2 === 38 || (p3 >= 300 && p3 <= 305)) && len >= 14)
|
|
53
|
+
return 'diners';
|
|
54
|
+
if (p4 >= 3528 && p4 <= 3589 && len >= 16)
|
|
55
|
+
return 'jcb';
|
|
56
|
+
if ((p2 === 62 || p2 === 81) && len >= 16)
|
|
57
|
+
return 'unionpay';
|
|
58
|
+
if ((p4 === 5018 || p4 === 5020 || p4 === 5038 || p4 === 6304 || p4 === 6759 || p4 === 6761) &&
|
|
59
|
+
len >= 12)
|
|
60
|
+
return 'maestro';
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
/** CPF (Brazilian individual taxpayer id): 11 digits, two mod-11 check digits. */
|
|
64
|
+
export function cpfValid(raw) {
|
|
65
|
+
const d = raw.replace(/\D/g, '');
|
|
66
|
+
if (d.length !== 11 || /^(\d)\1{10}$/.test(d))
|
|
67
|
+
return false;
|
|
68
|
+
const check = (len) => {
|
|
69
|
+
let sum = 0;
|
|
70
|
+
for (let i = 0; i < len; i++)
|
|
71
|
+
sum += (d.charCodeAt(i) - 48) * (len + 1 - i);
|
|
72
|
+
const r = (sum * 10) % 11;
|
|
73
|
+
return r === 10 ? 0 : r;
|
|
74
|
+
};
|
|
75
|
+
return check(9) === d.charCodeAt(9) - 48 && check(10) === d.charCodeAt(10) - 48;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* CNPJ (Brazilian company id), numeric or the alphanumeric format in use since July 2026: 12
|
|
79
|
+
* characters [0-9A-Z] + 2 check digits, each character valued at its ASCII code minus 48.
|
|
80
|
+
*/
|
|
81
|
+
export function cnpjValid(raw) {
|
|
82
|
+
const c = raw.replace(/[.\-/\s]/g, '').toUpperCase();
|
|
83
|
+
if (!/^[0-9A-Z]{12}\d{2}$/.test(c) || /^(\d)\1{13}$/.test(c))
|
|
84
|
+
return false;
|
|
85
|
+
const value = (i) => c.charCodeAt(i) - 48;
|
|
86
|
+
const check = (len) => {
|
|
87
|
+
const weights = len === 12 ? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2] : [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
88
|
+
let sum = 0;
|
|
89
|
+
for (let i = 0; i < len; i++)
|
|
90
|
+
sum += value(i) * (weights[i] ?? 0);
|
|
91
|
+
const r = sum % 11;
|
|
92
|
+
return r < 2 ? 0 : 11 - r;
|
|
93
|
+
};
|
|
94
|
+
return check(12) === value(12) && check(13) === value(13);
|
|
95
|
+
}
|
|
96
|
+
/** US Social Security Number structure (no 000/666/9xx area, no 00 group, no 0000 serial). */
|
|
97
|
+
export function ssnValid(raw) {
|
|
98
|
+
const m = /^(\d{3})[- ](\d{2})[- ](\d{4})$/.exec(raw);
|
|
99
|
+
if (!m)
|
|
100
|
+
return false;
|
|
101
|
+
const area = m[1] ?? '';
|
|
102
|
+
const group = m[2] ?? '';
|
|
103
|
+
const serial = m[3] ?? '';
|
|
104
|
+
if (area === '000' || area === '666' || area.startsWith('9'))
|
|
105
|
+
return false;
|
|
106
|
+
if (group === '00' || serial === '0000')
|
|
107
|
+
return false;
|
|
108
|
+
// Well-known advertising / sample numbers.
|
|
109
|
+
if (['078-05-1120', '219-09-9999', '123-45-6789'].includes(`${area}-${group}-${serial}`))
|
|
110
|
+
return false;
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
/** IBAN lengths by country (ISO 13616 registry, main countries). */
|
|
114
|
+
const IBAN_LENGTHS = {
|
|
115
|
+
AD: 24,
|
|
116
|
+
AE: 23,
|
|
117
|
+
AT: 20,
|
|
118
|
+
BE: 16,
|
|
119
|
+
BG: 22,
|
|
120
|
+
BH: 22,
|
|
121
|
+
BR: 29,
|
|
122
|
+
CH: 21,
|
|
123
|
+
CR: 22,
|
|
124
|
+
CY: 28,
|
|
125
|
+
CZ: 24,
|
|
126
|
+
DE: 22,
|
|
127
|
+
DK: 18,
|
|
128
|
+
DO: 28,
|
|
129
|
+
EE: 20,
|
|
130
|
+
ES: 24,
|
|
131
|
+
FI: 18,
|
|
132
|
+
FO: 18,
|
|
133
|
+
FR: 27,
|
|
134
|
+
GB: 22,
|
|
135
|
+
GI: 23,
|
|
136
|
+
GL: 18,
|
|
137
|
+
GR: 27,
|
|
138
|
+
GT: 28,
|
|
139
|
+
HR: 21,
|
|
140
|
+
HU: 28,
|
|
141
|
+
IE: 22,
|
|
142
|
+
IL: 23,
|
|
143
|
+
IS: 26,
|
|
144
|
+
IT: 27,
|
|
145
|
+
JO: 30,
|
|
146
|
+
KW: 30,
|
|
147
|
+
KZ: 20,
|
|
148
|
+
LB: 28,
|
|
149
|
+
LI: 21,
|
|
150
|
+
LT: 20,
|
|
151
|
+
LU: 20,
|
|
152
|
+
LV: 21,
|
|
153
|
+
MC: 27,
|
|
154
|
+
MD: 24,
|
|
155
|
+
ME: 22,
|
|
156
|
+
MK: 19,
|
|
157
|
+
MR: 27,
|
|
158
|
+
MT: 31,
|
|
159
|
+
MU: 30,
|
|
160
|
+
NL: 18,
|
|
161
|
+
NO: 15,
|
|
162
|
+
PK: 24,
|
|
163
|
+
PL: 28,
|
|
164
|
+
PS: 29,
|
|
165
|
+
PT: 25,
|
|
166
|
+
QA: 29,
|
|
167
|
+
RO: 24,
|
|
168
|
+
RS: 22,
|
|
169
|
+
SA: 24,
|
|
170
|
+
SE: 24,
|
|
171
|
+
SI: 19,
|
|
172
|
+
SK: 24,
|
|
173
|
+
SM: 27,
|
|
174
|
+
TN: 24,
|
|
175
|
+
TR: 26,
|
|
176
|
+
UA: 29,
|
|
177
|
+
VG: 24,
|
|
178
|
+
XK: 20,
|
|
179
|
+
};
|
|
180
|
+
/** IBAN: known country length and ISO 7064 mod 97-10 checksum. */
|
|
181
|
+
export function ibanValid(raw) {
|
|
182
|
+
const s = raw.replace(/\s/g, '').toUpperCase();
|
|
183
|
+
if (!/^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/.test(s))
|
|
184
|
+
return false;
|
|
185
|
+
const expected = IBAN_LENGTHS[s.slice(0, 2)];
|
|
186
|
+
if (expected !== undefined && s.length !== expected)
|
|
187
|
+
return false;
|
|
188
|
+
if (expected === undefined)
|
|
189
|
+
return false;
|
|
190
|
+
const rearranged = s.slice(4) + s.slice(0, 4);
|
|
191
|
+
let rem = 0;
|
|
192
|
+
for (const ch of rearranged) {
|
|
193
|
+
const v = ch >= 'A' ? String(ch.charCodeAt(0) - 55) : ch;
|
|
194
|
+
for (const digit of v)
|
|
195
|
+
rem = (rem * 10 + (digit.charCodeAt(0) - 48)) % 97;
|
|
196
|
+
}
|
|
197
|
+
return rem === 1;
|
|
198
|
+
}
|
|
199
|
+
/** Phone numbers: international (+CC), Brazilian and North American formats with separators. */
|
|
200
|
+
export function phoneValid(raw) {
|
|
201
|
+
const digits = raw.replace(/\D/g, '');
|
|
202
|
+
if (raw.trim().startsWith('+'))
|
|
203
|
+
return digits.length >= 8 && digits.length <= 15;
|
|
204
|
+
if (digits.length < 10 || digits.length > 11)
|
|
205
|
+
return false;
|
|
206
|
+
// Brazil: (11) 91234-5678, 11 91234-5678, (11) 3123-4567
|
|
207
|
+
if (/^\(?\d{2}\)?[\s.-]?9?\d{4}[\s.-]\d{4}$/.test(raw.trim()))
|
|
208
|
+
return true;
|
|
209
|
+
// North America: (415) 555-0132, 415-555-0132, 415.555.0132
|
|
210
|
+
if (/^\(?\d{3}\)?[\s.-]?\d{3}[\s.-]\d{4}$/.test(raw.trim()))
|
|
211
|
+
return true;
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
// Boundaries are explicit look-arounds instead of \b so formatted numbers ("(11) 9…") are whole.
|
|
215
|
+
const PATTERNS = [
|
|
216
|
+
{
|
|
217
|
+
type: 'email',
|
|
218
|
+
re: /(?<![\w.+-])[A-Za-z0-9](?:[A-Za-z0-9._%+-]{0,63})@(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,62})\.)+[A-Za-z]{2,24}(?![\w-])/g,
|
|
219
|
+
score: 0.99,
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
type: 'iban',
|
|
223
|
+
re: /(?<![A-Za-z0-9])[A-Z]{2}\d{2}(?: ?[A-Z0-9]){11,30}(?![A-Za-z0-9])/g,
|
|
224
|
+
valid: ibanValid,
|
|
225
|
+
score: 0.99,
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
type: 'cnpj',
|
|
229
|
+
re: /(?<![\w./-])[0-9A-Z]{2}\.?[0-9A-Z]{3}\.?[0-9A-Z]{3}\/?[0-9A-Z]{4}-?\d{2}(?![\w/-])/g,
|
|
230
|
+
valid: (m) => cnpjValid(m) && (/^\d/.test(m.replace(/\D/g, '')) || /[./-]/.test(m)) && !/^[A-Z]+$/.test(m),
|
|
231
|
+
score: 0.98,
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
type: 'cpf',
|
|
235
|
+
re: /(?<![\w./-])\d{3}\.?\d{3}\.?\d{3}-?\d{2}(?![\w/-])/g,
|
|
236
|
+
valid: cpfValid,
|
|
237
|
+
score: 0.95,
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
type: 'credit_card',
|
|
241
|
+
re: /(?<![\d-])\d(?:[ -]?\d){11,18}(?![\d-])/g,
|
|
242
|
+
valid: (m) => {
|
|
243
|
+
const digits = m.replace(/\D/g, '');
|
|
244
|
+
// Mixed separators ("4111 1111-1111 1111") are unusual for cards; accept one kind.
|
|
245
|
+
if (/ /.test(m) && /-/.test(m))
|
|
246
|
+
return false;
|
|
247
|
+
return digits.length >= 13 && digits.length <= 19 && luhnValid(digits) && !!cardBrand(digits);
|
|
248
|
+
},
|
|
249
|
+
score: 0.97,
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
type: 'ssn',
|
|
253
|
+
re: /(?<![\d-])\d{3}[- ]\d{2}[- ]\d{4}(?![\d-])/g,
|
|
254
|
+
valid: ssnValid,
|
|
255
|
+
score: 0.85,
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
type: 'phone',
|
|
259
|
+
re: /(?<![\w+])(?:\+\d{1,3}[\s.-]?)?\(?\d{2,4}\)?[\s.-]?\d{3,5}[\s.-]\d{4}(?![\w])/g,
|
|
260
|
+
valid: phoneValid,
|
|
261
|
+
score: 0.75,
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
type: 'ip_address',
|
|
265
|
+
re: /(?<![\d.])(?:\d{1,3}\.){3}\d{1,3}(?![\d.])/g,
|
|
266
|
+
valid: (m) => isIPv4(m) && !m.startsWith('0.') && m !== '127.0.0.1',
|
|
267
|
+
score: 0.6,
|
|
268
|
+
},
|
|
269
|
+
];
|
|
270
|
+
/** PII with format + checksum validation. Overlaps are resolved by the caller (longest, earliest). */
|
|
271
|
+
export function detectPii(text, types = PII_TYPES) {
|
|
272
|
+
const want = new Set(types);
|
|
273
|
+
const out = [];
|
|
274
|
+
for (const p of PATTERNS) {
|
|
275
|
+
if (!want.has(p.type))
|
|
276
|
+
continue;
|
|
277
|
+
p.re.lastIndex = 0;
|
|
278
|
+
for (let m = p.re.exec(text); m; m = p.re.exec(text)) {
|
|
279
|
+
const value = m[0];
|
|
280
|
+
if (p.valid && !p.valid(value))
|
|
281
|
+
continue;
|
|
282
|
+
out.push({
|
|
283
|
+
detector: 'pii',
|
|
284
|
+
category: `pii.${p.type}`,
|
|
285
|
+
start: m.index,
|
|
286
|
+
end: m.index + value.length,
|
|
287
|
+
score: p.score,
|
|
288
|
+
value,
|
|
289
|
+
spanned: true,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return out;
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=pii.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii.js","sourceRoot":"","sources":["../../../../src/guardrails/detectors/pii.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,uEAAuE;AACvE,MAAM,UAAU,MAAM,CAAC,GAAW;IAChC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,CACL,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAC7F,CAAC;AACJ,CAA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I,CAAC;YAAE,SAAS;QAChC,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,CAAC,CAAC;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACrD,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACnB,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;gBAAE,SAAS;YACzC,GAAG,CAAC,IAAI,CAAC;gBACP,QAAQ,EAAE,KAAK;gBACf,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE;gBACzB,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM;gBAC3B,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,KAAK;gBACL,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Finding, SecretType } from '../types.js';
|
|
2
|
+
/** Shannon entropy in bits per character: tells random tokens from words ("password=changeme"). */
|
|
3
|
+
export declare function entropy(s: string): number;
|
|
4
|
+
export declare function detectSecrets(text: string, types?: readonly SecretType[]): Finding[];
|
|
5
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../../../src/guardrails/detectors/secrets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAYvD,mGAAmG;AACnG,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAUzC;AAiED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,SAAS,UAAU,EAAiB,GAC1C,OAAO,EAAE,CA4BX"}
|