visus-mcp 0.1.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/.claude/settings.local.json +36 -0
- package/CLAUDE.md +324 -0
- package/README.md +290 -0
- package/SECURITY.md +360 -0
- package/STATUS.md +482 -0
- package/TROUBLESHOOT-BUILD-20260319-1450.md +546 -0
- package/TROUBLESHOOT-FETCH-20260320-1150.md +168 -0
- package/TROUBLESHOOT-SSL-20260320-1138.md +171 -0
- package/TROUBLESHOOT-STRUCTURED-20260320-1200.md +246 -0
- package/TROUBLESHOOT-TEST-20260320-0942.md +281 -0
- package/VISUS-CLAUDE-CODE-PROMPT.md +324 -0
- package/VISUS-PROJECT-PLAN.md +198 -0
- package/dist/browser/__mocks__/playwright-renderer.d.ts +25 -0
- package/dist/browser/__mocks__/playwright-renderer.d.ts.map +1 -0
- package/dist/browser/__mocks__/playwright-renderer.js +119 -0
- package/dist/browser/__mocks__/playwright-renderer.js.map +1 -0
- package/dist/browser/playwright-renderer.d.ts +36 -0
- package/dist/browser/playwright-renderer.d.ts.map +1 -0
- package/dist/browser/playwright-renderer.js +115 -0
- package/dist/browser/playwright-renderer.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +129 -0
- package/dist/index.js.map +1 -0
- package/dist/sanitizer/index.d.ts +55 -0
- package/dist/sanitizer/index.d.ts.map +1 -0
- package/dist/sanitizer/index.js +89 -0
- package/dist/sanitizer/index.js.map +1 -0
- package/dist/sanitizer/injection-detector.d.ts +34 -0
- package/dist/sanitizer/injection-detector.d.ts.map +1 -0
- package/dist/sanitizer/injection-detector.js +89 -0
- package/dist/sanitizer/injection-detector.js.map +1 -0
- package/dist/sanitizer/patterns.d.ts +30 -0
- package/dist/sanitizer/patterns.d.ts.map +1 -0
- package/dist/sanitizer/patterns.js +372 -0
- package/dist/sanitizer/patterns.js.map +1 -0
- package/dist/sanitizer/pii-redactor.d.ts +29 -0
- package/dist/sanitizer/pii-redactor.d.ts.map +1 -0
- package/dist/sanitizer/pii-redactor.js +189 -0
- package/dist/sanitizer/pii-redactor.js.map +1 -0
- package/dist/tools/fetch-structured.d.ts +46 -0
- package/dist/tools/fetch-structured.d.ts.map +1 -0
- package/dist/tools/fetch-structured.js +186 -0
- package/dist/tools/fetch-structured.js.map +1 -0
- package/dist/tools/fetch.d.ts +44 -0
- package/dist/tools/fetch.d.ts.map +1 -0
- package/dist/tools/fetch.js +97 -0
- package/dist/tools/fetch.js.map +1 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/jest.config.js +30 -0
- package/jest.setup.js +9 -0
- package/package.json +52 -0
- package/src/browser/__mocks__/playwright-renderer.ts +140 -0
- package/src/browser/playwright-renderer.ts +142 -0
- package/src/index.ts +169 -0
- package/src/sanitizer/index.ts +127 -0
- package/src/sanitizer/injection-detector.ts +121 -0
- package/src/sanitizer/patterns.ts +424 -0
- package/src/sanitizer/pii-redactor.ts +226 -0
- package/src/tools/fetch-structured.ts +218 -0
- package/src/tools/fetch.ts +108 -0
- package/src/types.ts +101 -0
- package/test-output.txt +4 -0
- package/tests/fetch-tool.test.ts +329 -0
- package/tests/injection-corpus.ts +338 -0
- package/tests/sanitizer.test.ts +306 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizer Orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for content sanitization. Coordinates injection detection
|
|
5
|
+
* and PII redaction pipelines.
|
|
6
|
+
*
|
|
7
|
+
* CRITICAL: This is the core security mechanism. Every web page MUST pass
|
|
8
|
+
* through this sanitizer before reaching the LLM. This cannot be bypassed.
|
|
9
|
+
*/
|
|
10
|
+
export interface SanitizationResult {
|
|
11
|
+
content: string;
|
|
12
|
+
sanitization: {
|
|
13
|
+
patterns_detected: string[];
|
|
14
|
+
pii_types_redacted: string[];
|
|
15
|
+
content_modified: boolean;
|
|
16
|
+
};
|
|
17
|
+
metadata: {
|
|
18
|
+
original_length: number;
|
|
19
|
+
sanitized_length: number;
|
|
20
|
+
severity_score: number;
|
|
21
|
+
has_critical_threats: boolean;
|
|
22
|
+
detections_by_severity: {
|
|
23
|
+
critical: number;
|
|
24
|
+
high: number;
|
|
25
|
+
medium: number;
|
|
26
|
+
low: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sanitize content through the full pipeline
|
|
32
|
+
*
|
|
33
|
+
* Pipeline:
|
|
34
|
+
* 1. Injection detection and neutralization (43 patterns)
|
|
35
|
+
* 2. PII redaction (email, phone, SSN, CC, IP)
|
|
36
|
+
* 3. Metadata collection and logging
|
|
37
|
+
*
|
|
38
|
+
* @param content Raw content from web page
|
|
39
|
+
* @returns Sanitized content with detection metadata
|
|
40
|
+
*/
|
|
41
|
+
export declare function sanitize(content: string): SanitizationResult;
|
|
42
|
+
/**
|
|
43
|
+
* Quick check: does content need sanitization?
|
|
44
|
+
* (Used for optimization - skip pipeline if content is clean)
|
|
45
|
+
*
|
|
46
|
+
* Note: Still run full pipeline for safety, but this can be used for metrics
|
|
47
|
+
*/
|
|
48
|
+
export declare function needsSanitization(_content: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Export sub-components for testing
|
|
51
|
+
*/
|
|
52
|
+
export { detectAndNeutralize } from './injection-detector.js';
|
|
53
|
+
export { redactPII, containsPII, detectPIITypes } from './pii-redactor.js';
|
|
54
|
+
export { INJECTION_PATTERNS, getAllPatternNames } from './patterns.js';
|
|
55
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sanitizer/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE;QACZ,iBAAiB,EAAE,MAAM,EAAE,CAAC;QAC5B,kBAAkB,EAAE,MAAM,EAAE,CAAC;QAC7B,gBAAgB,EAAE,OAAO,CAAC;KAC3B,CAAC;IACF,QAAQ,EAAE;QACR,eAAe,EAAE,MAAM,CAAC;QACxB,gBAAgB,EAAE,MAAM,CAAC;QACzB,cAAc,EAAE,MAAM,CAAC;QACvB,oBAAoB,EAAE,OAAO,CAAC;QAC9B,sBAAsB,EAAE;YACtB,QAAQ,EAAE,MAAM,CAAC;YACjB,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,MAAM,CAAC;YACf,GAAG,EAAE,MAAM,CAAC;SACb,CAAC;KACH,CAAC;CACH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAwC5D;AAyBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAG3D;AAED;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizer Orchestrator
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for content sanitization. Coordinates injection detection
|
|
5
|
+
* and PII redaction pipelines.
|
|
6
|
+
*
|
|
7
|
+
* CRITICAL: This is the core security mechanism. Every web page MUST pass
|
|
8
|
+
* through this sanitizer before reaching the LLM. This cannot be bypassed.
|
|
9
|
+
*/
|
|
10
|
+
import { detectAndNeutralize, getSeverityScore, hasCriticalThreats } from './injection-detector.js';
|
|
11
|
+
import { redactPII } from './pii-redactor.js';
|
|
12
|
+
/**
|
|
13
|
+
* Sanitize content through the full pipeline
|
|
14
|
+
*
|
|
15
|
+
* Pipeline:
|
|
16
|
+
* 1. Injection detection and neutralization (43 patterns)
|
|
17
|
+
* 2. PII redaction (email, phone, SSN, CC, IP)
|
|
18
|
+
* 3. Metadata collection and logging
|
|
19
|
+
*
|
|
20
|
+
* @param content Raw content from web page
|
|
21
|
+
* @returns Sanitized content with detection metadata
|
|
22
|
+
*/
|
|
23
|
+
export function sanitize(content) {
|
|
24
|
+
const originalLength = content.length;
|
|
25
|
+
// Step 1: Detect and neutralize injection patterns
|
|
26
|
+
const injectionResult = detectAndNeutralize(content);
|
|
27
|
+
// Step 2: Redact PII from the already-sanitized content
|
|
28
|
+
const piiResult = redactPII(injectionResult.content);
|
|
29
|
+
// Step 3: Combine results
|
|
30
|
+
const finalContent = piiResult.content;
|
|
31
|
+
const contentModified = injectionResult.content_modified || piiResult.content_modified;
|
|
32
|
+
const severityScore = getSeverityScore(injectionResult.metadata.detections_by_severity);
|
|
33
|
+
const criticalThreats = hasCriticalThreats(injectionResult.metadata.detections_by_severity);
|
|
34
|
+
// Log to stderr for monitoring (not stdout - MCP protocol)
|
|
35
|
+
logSanitization({
|
|
36
|
+
patterns_detected: injectionResult.patterns_detected,
|
|
37
|
+
pii_types_redacted: piiResult.pii_types_redacted,
|
|
38
|
+
severity_score: severityScore,
|
|
39
|
+
has_critical_threats: criticalThreats,
|
|
40
|
+
content_modified: contentModified
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
content: finalContent,
|
|
44
|
+
sanitization: {
|
|
45
|
+
patterns_detected: injectionResult.patterns_detected,
|
|
46
|
+
pii_types_redacted: piiResult.pii_types_redacted,
|
|
47
|
+
content_modified: contentModified
|
|
48
|
+
},
|
|
49
|
+
metadata: {
|
|
50
|
+
original_length: originalLength,
|
|
51
|
+
sanitized_length: finalContent.length,
|
|
52
|
+
severity_score: severityScore,
|
|
53
|
+
has_critical_threats: criticalThreats,
|
|
54
|
+
detections_by_severity: injectionResult.metadata.detections_by_severity
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Log sanitization events to stderr for monitoring
|
|
60
|
+
* (structured JSON logging per Lateos conventions)
|
|
61
|
+
*/
|
|
62
|
+
function logSanitization(event) {
|
|
63
|
+
const logEntry = {
|
|
64
|
+
timestamp: new Date().toISOString(),
|
|
65
|
+
event: 'sanitization',
|
|
66
|
+
...event
|
|
67
|
+
};
|
|
68
|
+
// Only log if there were detections (reduce noise)
|
|
69
|
+
if (event.content_modified) {
|
|
70
|
+
console.error(JSON.stringify(logEntry));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Quick check: does content need sanitization?
|
|
75
|
+
* (Used for optimization - skip pipeline if content is clean)
|
|
76
|
+
*
|
|
77
|
+
* Note: Still run full pipeline for safety, but this can be used for metrics
|
|
78
|
+
*/
|
|
79
|
+
export function needsSanitization(_content) {
|
|
80
|
+
// Always sanitize - this is just a helper for metrics
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Export sub-components for testing
|
|
85
|
+
*/
|
|
86
|
+
export { detectAndNeutralize } from './injection-detector.js';
|
|
87
|
+
export { redactPII, containsPII, detectPIITypes } from './pii-redactor.js';
|
|
88
|
+
export { INJECTION_PATTERNS, getAllPatternNames } from './patterns.js';
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sanitizer/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAuB9C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,MAAM,cAAc,GA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rB,GAAG,KAAK;KACT,CAAC;IAEF,mDAAmD;IACnD,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC3B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,sDAAsD;IACtD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injection Detection Engine
|
|
3
|
+
*
|
|
4
|
+
* Scans content against all 43 injection patterns and neutralizes threats
|
|
5
|
+
* based on pattern action directives (strip, redact, escape).
|
|
6
|
+
*/
|
|
7
|
+
export interface DetectionResult {
|
|
8
|
+
content: string;
|
|
9
|
+
patterns_detected: string[];
|
|
10
|
+
content_modified: boolean;
|
|
11
|
+
metadata: {
|
|
12
|
+
original_length: number;
|
|
13
|
+
sanitized_length: number;
|
|
14
|
+
detections_by_severity: {
|
|
15
|
+
critical: number;
|
|
16
|
+
high: number;
|
|
17
|
+
medium: number;
|
|
18
|
+
low: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Detect and neutralize injection patterns in content
|
|
24
|
+
*/
|
|
25
|
+
export declare function detectAndNeutralize(content: string): DetectionResult;
|
|
26
|
+
/**
|
|
27
|
+
* Get severity score for logging/monitoring
|
|
28
|
+
*/
|
|
29
|
+
export declare function getSeverityScore(detectionsBySeverity: DetectionResult['metadata']['detections_by_severity']): number;
|
|
30
|
+
/**
|
|
31
|
+
* Check if content has critical threats
|
|
32
|
+
*/
|
|
33
|
+
export declare function hasCriticalThreats(detectionsBySeverity: DetectionResult['metadata']['detections_by_severity']): boolean;
|
|
34
|
+
//# sourceMappingURL=injection-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection-detector.d.ts","sourceRoot":"","sources":["../../src/sanitizer/injection-detector.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,QAAQ,EAAE;QACR,eAAe,EAAE,MAAM,CAAC;QACxB,gBAAgB,EAAE,MAAM,CAAC;QACzB,sBAAsB,EAAE;YACtB,QAAQ,EAAE,MAAM,CAAC;YACjB,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,MAAM,CAAC;YACf,GAAG,EAAE,MAAM,CAAC;SACb,CAAC;KACH,CAAC;CACH;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAmCpE;AAwCD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,oBAAoB,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC,wBAAwB,CAAC,GAAG,MAAM,CAOpH;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,oBAAoB,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAEvH"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injection Detection Engine
|
|
3
|
+
*
|
|
4
|
+
* Scans content against all 43 injection patterns and neutralizes threats
|
|
5
|
+
* based on pattern action directives (strip, redact, escape).
|
|
6
|
+
*/
|
|
7
|
+
import { INJECTION_PATTERNS } from './patterns.js';
|
|
8
|
+
/**
|
|
9
|
+
* Detect and neutralize injection patterns in content
|
|
10
|
+
*/
|
|
11
|
+
export function detectAndNeutralize(content) {
|
|
12
|
+
const originalLength = content.length;
|
|
13
|
+
const patternsDetected = new Set();
|
|
14
|
+
const detectionsBySeverity = {
|
|
15
|
+
critical: 0,
|
|
16
|
+
high: 0,
|
|
17
|
+
medium: 0,
|
|
18
|
+
low: 0
|
|
19
|
+
};
|
|
20
|
+
let sanitizedContent = content;
|
|
21
|
+
// Apply each pattern
|
|
22
|
+
for (const pattern of INJECTION_PATTERNS) {
|
|
23
|
+
const matches = sanitizedContent.match(pattern.regex);
|
|
24
|
+
if (matches && matches.length > 0) {
|
|
25
|
+
patternsDetected.add(pattern.name);
|
|
26
|
+
detectionsBySeverity[pattern.severity] += matches.length;
|
|
27
|
+
// Apply action
|
|
28
|
+
sanitizedContent = applyAction(sanitizedContent, pattern);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
content: sanitizedContent,
|
|
33
|
+
patterns_detected: Array.from(patternsDetected),
|
|
34
|
+
content_modified: sanitizedContent !== content,
|
|
35
|
+
metadata: {
|
|
36
|
+
original_length: originalLength,
|
|
37
|
+
sanitized_length: sanitizedContent.length,
|
|
38
|
+
detections_by_severity: detectionsBySeverity
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Apply the appropriate action for a pattern match
|
|
44
|
+
*/
|
|
45
|
+
function applyAction(content, pattern) {
|
|
46
|
+
switch (pattern.action) {
|
|
47
|
+
case 'strip':
|
|
48
|
+
// Remove matched content entirely
|
|
49
|
+
return content.replace(pattern.regex, '');
|
|
50
|
+
case 'redact':
|
|
51
|
+
// Replace with redaction marker
|
|
52
|
+
return content.replace(pattern.regex, `[REDACTED:${pattern.name.toUpperCase()}]`);
|
|
53
|
+
case 'escape':
|
|
54
|
+
// HTML escape matched content
|
|
55
|
+
return content.replace(pattern.regex, (match) => escapeHtml(match));
|
|
56
|
+
default:
|
|
57
|
+
return content;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* HTML escape special characters
|
|
62
|
+
*/
|
|
63
|
+
function escapeHtml(text) {
|
|
64
|
+
const htmlEntities = {
|
|
65
|
+
'&': '&',
|
|
66
|
+
'<': '<',
|
|
67
|
+
'>': '>',
|
|
68
|
+
'"': '"',
|
|
69
|
+
"'": ''',
|
|
70
|
+
'/': '/'
|
|
71
|
+
};
|
|
72
|
+
return text.replace(/[&<>"'/]/g, (char) => htmlEntities[char] || char);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get severity score for logging/monitoring
|
|
76
|
+
*/
|
|
77
|
+
export function getSeverityScore(detectionsBySeverity) {
|
|
78
|
+
return (detectionsBySeverity.critical * 100 +
|
|
79
|
+
detectionsBySeverity.high * 50 +
|
|
80
|
+
detectionsBySeverity.medium * 10 +
|
|
81
|
+
detectionsBySeverity.low * 1);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if content has critical threats
|
|
85
|
+
*/
|
|
86
|
+
export function hasCriticalThreats(detectionsBySeverity) {
|
|
87
|
+
return detectionsBySeverity.critical > 0;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=injection-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection-detector.js","sourceRoot":"","sources":["../../src/sanitizer/injection-detector.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAyB,MAAM,eAAe,CAAC;AAkB1E;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IACtC,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC3C,MAAM,oBAAoB,GAAG;QAC3B,QAAQ,EAAE,CAAC;QACX,IAAI,EAAE,CAAC;QACP,MAAM,EAAE,CAAC;QACT,GAAG,EAAE,CAAC;KACP,CAA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,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QAEtE;YACE,OAAO,OAAO,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,YAAY,GAA2B;QAC3C,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,MAAM;QACX,GAAG,EAAE,MAAM;QACX,GAAG,EAAE,QAAQ;QACb,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,QAAQ;KACd,CAAC;IAEF,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;AACzE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,oBAA2E;IAC1G,OAAO,CACL,oBAAoB,CAAC,QAAQ,GAAG,GAAG;QACnC,oBAAoB,CAAC,IAAI,GAAG,EAAE;QAC9B,oBAAoB,CAAC,MAAM,GAAG,EAAE;QAChC,oBAAoB,CAAC,GAAG,GAAG,CAAC,CAC7B,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,oBAA2E;IAC5G,OAAO,oBAAoB,CAAC,QAAQ,GAAG,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lateos Injection Pattern Library
|
|
3
|
+
*
|
|
4
|
+
* 43 validated injection pattern categories for detecting and neutralizing
|
|
5
|
+
* prompt injection attacks in web content before it reaches the LLM.
|
|
6
|
+
*
|
|
7
|
+
* Each pattern includes:
|
|
8
|
+
* - name: Pattern identifier
|
|
9
|
+
* - description: What this pattern detects
|
|
10
|
+
* - regex: Detection pattern (case-insensitive by default)
|
|
11
|
+
* - severity: risk level (critical, high, medium, low)
|
|
12
|
+
* - action: how to handle matches (strip, redact, escape)
|
|
13
|
+
*/
|
|
14
|
+
export interface InjectionPattern {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
regex: RegExp;
|
|
18
|
+
severity: 'critical' | 'high' | 'medium' | 'low';
|
|
19
|
+
action: 'strip' | 'redact' | 'escape';
|
|
20
|
+
}
|
|
21
|
+
export declare const INJECTION_PATTERNS: InjectionPattern[];
|
|
22
|
+
/**
|
|
23
|
+
* Get all pattern names for logging/testing
|
|
24
|
+
*/
|
|
25
|
+
export declare function getAllPatternNames(): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Get patterns by severity level
|
|
28
|
+
*/
|
|
29
|
+
export declare function getPatternsBySeverity(severity: 'critical' | 'high' | 'medium' | 'low'): InjectionPattern[];
|
|
30
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../src/sanitizer/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACjD,MAAM,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;CACvC;AAED,eAAO,MAAM,kBAAkB,EAAE,gBAAgB,EAmYhD,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,gBAAgB,EAAE,CAE1G"}
|