@bryan-thompson/inspector-assessment-client 1.35.2 → 1.35.3
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/lib/lib/assessment/coreTypes.d.ts +23 -0
- package/lib/lib/assessment/coreTypes.d.ts.map +1 -1
- package/lib/lib/assessment/extendedTypes.d.ts +45 -2
- package/lib/lib/assessment/extendedTypes.d.ts.map +1 -1
- package/lib/lib/assessment/jsonlEventSchemas.d.ts +4 -4
- package/lib/lib/assessment/resultTypes.d.ts +12 -1
- package/lib/lib/assessment/resultTypes.d.ts.map +1 -1
- package/lib/lib/aupPatterns.d.ts +50 -0
- package/lib/lib/aupPatterns.d.ts.map +1 -1
- package/lib/lib/aupPatterns.js +140 -0
- package/lib/lib/securityPatterns.d.ts.map +1 -1
- package/lib/lib/securityPatterns.js +92 -0
- package/lib/services/assessment/modules/DeveloperExperienceAssessor.d.ts +26 -1
- package/lib/services/assessment/modules/DeveloperExperienceAssessor.d.ts.map +1 -1
- package/lib/services/assessment/modules/DeveloperExperienceAssessor.js +160 -1
- package/lib/services/assessment/modules/ManifestValidationAssessor.d.ts +32 -0
- package/lib/services/assessment/modules/ManifestValidationAssessor.d.ts.map +1 -1
- package/lib/services/assessment/modules/ManifestValidationAssessor.js +218 -20
- package/lib/services/assessment/modules/securityTests/ConfidenceScorer.d.ts.map +1 -1
- package/lib/services/assessment/modules/securityTests/ConfidenceScorer.js +28 -0
- package/lib/services/assessment/modules/securityTests/SecurityPatternLibrary.d.ts +95 -0
- package/lib/services/assessment/modules/securityTests/SecurityPatternLibrary.d.ts.map +1 -1
- package/lib/services/assessment/modules/securityTests/SecurityPatternLibrary.js +174 -0
- package/lib/services/assessment/modules/securityTests/SecurityPayloadTester.d.ts.map +1 -1
- package/lib/services/assessment/modules/securityTests/SecurityPayloadTester.js +15 -0
- package/lib/services/assessment/modules/securityTests/SecurityResponseAnalyzer.d.ts +40 -0
- package/lib/services/assessment/modules/securityTests/SecurityResponseAnalyzer.d.ts.map +1 -1
- package/lib/services/assessment/modules/securityTests/SecurityResponseAnalyzer.js +143 -131
- package/package.json +1 -1
|
@@ -14,6 +14,67 @@ import { BaseAssessor } from "./BaseAssessor.js";
|
|
|
14
14
|
const REQUIRED_FIELDS = ["name", "version", "mcp_config"];
|
|
15
15
|
const RECOMMENDED_FIELDS = ["description", "author", "repository"];
|
|
16
16
|
const CURRENT_MANIFEST_VERSION = "0.3";
|
|
17
|
+
const SEMVER_PATTERN = /^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$/;
|
|
18
|
+
/**
|
|
19
|
+
* Calculate Levenshtein distance between two strings
|
|
20
|
+
* Uses space-optimized two-row algorithm for O(min(n,m)) memory
|
|
21
|
+
* Used for "did you mean?" suggestions on mismatched tool names (Issue #140)
|
|
22
|
+
* Exported for testing (Issue #141 - ISSUE-002)
|
|
23
|
+
*/
|
|
24
|
+
export function levenshteinDistance(a, b, maxDist) {
|
|
25
|
+
// Early termination optimizations
|
|
26
|
+
if (a === b)
|
|
27
|
+
return 0;
|
|
28
|
+
if (a.length === 0)
|
|
29
|
+
return b.length;
|
|
30
|
+
if (b.length === 0)
|
|
31
|
+
return a.length;
|
|
32
|
+
// If length difference exceeds max distance, no need to compute
|
|
33
|
+
if (maxDist && Math.abs(a.length - b.length) > maxDist) {
|
|
34
|
+
return maxDist + 1;
|
|
35
|
+
}
|
|
36
|
+
// Ensure a is the shorter string (optimize space)
|
|
37
|
+
if (a.length > b.length) {
|
|
38
|
+
[a, b] = [b, a];
|
|
39
|
+
}
|
|
40
|
+
// Two-row algorithm: only keep previous and current row
|
|
41
|
+
let prev = Array.from({ length: a.length + 1 }, (_, i) => i);
|
|
42
|
+
let curr = new Array(a.length + 1);
|
|
43
|
+
for (let i = 1; i <= b.length; i++) {
|
|
44
|
+
curr[0] = i;
|
|
45
|
+
for (let j = 1; j <= a.length; j++) {
|
|
46
|
+
if (b.charAt(i - 1) === a.charAt(j - 1)) {
|
|
47
|
+
curr[j] = prev[j - 1];
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
curr[j] = Math.min(prev[j - 1] + 1, // substitution
|
|
51
|
+
curr[j - 1] + 1, // insertion
|
|
52
|
+
prev[j] + 1);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Swap rows
|
|
56
|
+
[prev, curr] = [curr, prev];
|
|
57
|
+
}
|
|
58
|
+
return prev[a.length];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Find closest matching tool name from a set
|
|
62
|
+
* Returns match if distance <= threshold (default: 10 chars or 40% of length)
|
|
63
|
+
* Generous threshold to catch common renames like "data" -> "resources"
|
|
64
|
+
*/
|
|
65
|
+
function findClosestMatch(name, candidates, threshold) {
|
|
66
|
+
const maxDist = threshold ?? Math.max(10, Math.floor(name.length * 0.4));
|
|
67
|
+
let closest = null;
|
|
68
|
+
let minDist = Infinity;
|
|
69
|
+
for (const candidate of candidates) {
|
|
70
|
+
const dist = levenshteinDistance(name.toLowerCase(), candidate.toLowerCase(), maxDist);
|
|
71
|
+
if (dist < minDist && dist <= maxDist) {
|
|
72
|
+
minDist = dist;
|
|
73
|
+
closest = candidate;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return closest;
|
|
77
|
+
}
|
|
17
78
|
export class ManifestValidationAssessor extends BaseAssessor {
|
|
18
79
|
/**
|
|
19
80
|
* Get mcp_config from manifest (supports both root and nested v0.3 format)
|
|
@@ -33,6 +94,57 @@ export class ManifestValidationAssessor extends BaseAssessor {
|
|
|
33
94
|
}
|
|
34
95
|
return undefined;
|
|
35
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Extract contact information from manifest (Issue #141 - D4 check)
|
|
99
|
+
* Supports: author object, author string (email parsing), repository fallback
|
|
100
|
+
*
|
|
101
|
+
* @param manifest - The parsed manifest JSON
|
|
102
|
+
* @returns Extracted contact info or undefined if no contact info found
|
|
103
|
+
*/
|
|
104
|
+
extractContactInfo(manifest) {
|
|
105
|
+
// 1. Check author object format (npm-style)
|
|
106
|
+
if (typeof manifest.author === "object" && manifest.author !== null) {
|
|
107
|
+
const authorObj = manifest.author;
|
|
108
|
+
return {
|
|
109
|
+
email: authorObj.email,
|
|
110
|
+
url: authorObj.url,
|
|
111
|
+
name: authorObj.name,
|
|
112
|
+
source: "author_object",
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// 2. Check author string (may contain email: "Name <email@example.com>")
|
|
116
|
+
if (typeof manifest.author === "string" && manifest.author.trim()) {
|
|
117
|
+
const emailMatch = manifest.author.match(/<([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})>/);
|
|
118
|
+
return {
|
|
119
|
+
name: manifest.author.replace(/<[^>]+>/, "").trim() || undefined,
|
|
120
|
+
email: emailMatch?.[1],
|
|
121
|
+
source: "author_string",
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// 3. Fallback to repository (provides contact via issues)
|
|
125
|
+
if (manifest.repository) {
|
|
126
|
+
return {
|
|
127
|
+
url: manifest.repository,
|
|
128
|
+
source: "repository",
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Extract version information from manifest (Issue #141 - D5 check)
|
|
135
|
+
*
|
|
136
|
+
* @param manifest - The parsed manifest JSON
|
|
137
|
+
* @returns Extracted version info or undefined if no version found
|
|
138
|
+
*/
|
|
139
|
+
extractVersionInfo(manifest) {
|
|
140
|
+
if (!manifest.version)
|
|
141
|
+
return undefined;
|
|
142
|
+
return {
|
|
143
|
+
version: manifest.version,
|
|
144
|
+
valid: true,
|
|
145
|
+
semverCompliant: SEMVER_PATTERN.test(manifest.version),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
36
148
|
/**
|
|
37
149
|
* Run manifest validation assessment
|
|
38
150
|
*/
|
|
@@ -129,6 +241,11 @@ export class ManifestValidationAssessor extends BaseAssessor {
|
|
|
129
241
|
// Validate version format
|
|
130
242
|
this.testCount++;
|
|
131
243
|
validationResults.push(this.validateVersionFormat(manifest.version));
|
|
244
|
+
// Validate tool names match server (Issue #140)
|
|
245
|
+
if (manifest.tools && context.tools.length > 0) {
|
|
246
|
+
const toolResults = this.validateToolNamesMatch(manifest, context.tools);
|
|
247
|
+
validationResults.push(...toolResults);
|
|
248
|
+
}
|
|
132
249
|
// Validate privacy policy URLs if present
|
|
133
250
|
let privacyPolicies;
|
|
134
251
|
if (manifest.privacy_policies &&
|
|
@@ -164,6 +281,9 @@ export class ManifestValidationAssessor extends BaseAssessor {
|
|
|
164
281
|
const status = this.determineManifestStatus(validationResults, hasRequiredFields);
|
|
165
282
|
const explanation = this.generateExplanation(validationResults, hasRequiredFields, hasIcon, privacyPolicies);
|
|
166
283
|
const recommendations = this.generateRecommendations(validationResults, privacyPolicies);
|
|
284
|
+
// Extract D4/D5 fields (Issue #141)
|
|
285
|
+
const contactInfo = this.extractContactInfo(manifest);
|
|
286
|
+
const versionInfo = this.extractVersionInfo(manifest);
|
|
167
287
|
this.logger.info(`Assessment complete: ${validationResults.filter((r) => r.valid).length}/${validationResults.length} checks passed`);
|
|
168
288
|
return {
|
|
169
289
|
hasManifest: true,
|
|
@@ -173,6 +293,8 @@ export class ManifestValidationAssessor extends BaseAssessor {
|
|
|
173
293
|
hasRequiredFields,
|
|
174
294
|
missingFields,
|
|
175
295
|
privacyPolicies,
|
|
296
|
+
contactInfo,
|
|
297
|
+
versionInfo,
|
|
176
298
|
status,
|
|
177
299
|
explanation,
|
|
178
300
|
recommendations,
|
|
@@ -426,9 +548,7 @@ export class ManifestValidationAssessor extends BaseAssessor {
|
|
|
426
548
|
severity: "ERROR",
|
|
427
549
|
};
|
|
428
550
|
}
|
|
429
|
-
|
|
430
|
-
const semverPattern = /^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?(\+[a-zA-Z0-9.]+)?$/;
|
|
431
|
-
if (!semverPattern.test(version)) {
|
|
551
|
+
if (!SEMVER_PATTERN.test(version)) {
|
|
432
552
|
return {
|
|
433
553
|
field: "version (format)",
|
|
434
554
|
valid: false,
|
|
@@ -444,6 +564,98 @@ export class ManifestValidationAssessor extends BaseAssessor {
|
|
|
444
564
|
severity: "INFO",
|
|
445
565
|
};
|
|
446
566
|
}
|
|
567
|
+
/**
|
|
568
|
+
* Validate manifest tool declarations against actual server tools (Issue #140)
|
|
569
|
+
* Compares tool names in manifest.tools against context.tools from tools/list
|
|
570
|
+
* Uses Levenshtein distance for "did you mean?" suggestions
|
|
571
|
+
*/
|
|
572
|
+
validateToolNamesMatch(manifest, serverTools) {
|
|
573
|
+
const results = [];
|
|
574
|
+
// Skip if manifest doesn't declare tools
|
|
575
|
+
if (!manifest.tools || manifest.tools.length === 0) {
|
|
576
|
+
return results;
|
|
577
|
+
}
|
|
578
|
+
this.testCount++;
|
|
579
|
+
const manifestToolNames = new Set(manifest.tools.map((t) => t.name));
|
|
580
|
+
const serverToolNames = new Set(serverTools.map((t) => t.name));
|
|
581
|
+
// Check for tools declared in manifest but not on server
|
|
582
|
+
const mismatches = [];
|
|
583
|
+
for (const name of manifestToolNames) {
|
|
584
|
+
if (!serverToolNames.has(name)) {
|
|
585
|
+
const suggestion = findClosestMatch(name, serverToolNames);
|
|
586
|
+
mismatches.push({ manifest: name, suggestion });
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
// Check for tools on server but not declared in manifest
|
|
590
|
+
const undeclaredTools = [];
|
|
591
|
+
for (const name of serverToolNames) {
|
|
592
|
+
if (!manifestToolNames.has(name)) {
|
|
593
|
+
undeclaredTools.push(name);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
// Report mismatches with suggestions
|
|
597
|
+
if (mismatches.length > 0) {
|
|
598
|
+
const issueLines = mismatches.map((m) => m.suggestion
|
|
599
|
+
? `"${m.manifest}" (did you mean "${m.suggestion}"?)`
|
|
600
|
+
: `"${m.manifest}"`);
|
|
601
|
+
results.push({
|
|
602
|
+
field: "tools (manifest vs server)",
|
|
603
|
+
valid: false,
|
|
604
|
+
value: mismatches,
|
|
605
|
+
issue: `Manifest declares tools not found on server: ${issueLines.join(", ")}`,
|
|
606
|
+
severity: "WARNING",
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
if (undeclaredTools.length > 0) {
|
|
610
|
+
results.push({
|
|
611
|
+
field: "tools (undeclared)",
|
|
612
|
+
valid: false,
|
|
613
|
+
value: undeclaredTools,
|
|
614
|
+
issue: `Server has tools not declared in manifest: ${undeclaredTools.join(", ")}`,
|
|
615
|
+
severity: "INFO",
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
// All matched
|
|
619
|
+
if (mismatches.length === 0 && undeclaredTools.length === 0) {
|
|
620
|
+
results.push({
|
|
621
|
+
field: "tools (manifest vs server)",
|
|
622
|
+
valid: true,
|
|
623
|
+
value: `${manifestToolNames.size} tools matched`,
|
|
624
|
+
severity: "INFO",
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
return results;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Fetch with retry logic for transient network failures
|
|
631
|
+
*/
|
|
632
|
+
async fetchWithRetry(url, method, retries = 2, backoffMs = 100) {
|
|
633
|
+
let lastError = null;
|
|
634
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
635
|
+
const controller = new AbortController();
|
|
636
|
+
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
637
|
+
try {
|
|
638
|
+
const response = await fetch(url, {
|
|
639
|
+
method,
|
|
640
|
+
signal: controller.signal,
|
|
641
|
+
redirect: "follow",
|
|
642
|
+
});
|
|
643
|
+
clearTimeout(timeoutId);
|
|
644
|
+
return response;
|
|
645
|
+
}
|
|
646
|
+
catch (error) {
|
|
647
|
+
clearTimeout(timeoutId);
|
|
648
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
649
|
+
// Don't retry on last attempt
|
|
650
|
+
if (attempt < retries) {
|
|
651
|
+
// Exponential backoff
|
|
652
|
+
await new Promise((resolve) => setTimeout(resolve, backoffMs * Math.pow(2, attempt)));
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
// All retries exhausted
|
|
657
|
+
throw lastError;
|
|
658
|
+
}
|
|
447
659
|
/**
|
|
448
660
|
* Validate privacy policy URLs are accessible
|
|
449
661
|
*/
|
|
@@ -467,15 +679,8 @@ export class ManifestValidationAssessor extends BaseAssessor {
|
|
|
467
679
|
continue;
|
|
468
680
|
}
|
|
469
681
|
try {
|
|
470
|
-
// Use HEAD request for efficiency
|
|
471
|
-
const
|
|
472
|
-
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
473
|
-
const response = await fetch(url, {
|
|
474
|
-
method: "HEAD",
|
|
475
|
-
signal: controller.signal,
|
|
476
|
-
redirect: "follow",
|
|
477
|
-
});
|
|
478
|
-
clearTimeout(timeoutId);
|
|
682
|
+
// Use HEAD request for efficiency with retry logic
|
|
683
|
+
const response = await this.fetchWithRetry(url, "HEAD");
|
|
479
684
|
results.push({
|
|
480
685
|
url,
|
|
481
686
|
accessible: response.ok,
|
|
@@ -489,14 +694,7 @@ export class ManifestValidationAssessor extends BaseAssessor {
|
|
|
489
694
|
error: headError instanceof Error ? headError.message : String(headError),
|
|
490
695
|
});
|
|
491
696
|
try {
|
|
492
|
-
const
|
|
493
|
-
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
494
|
-
const response = await fetch(url, {
|
|
495
|
-
method: "GET",
|
|
496
|
-
signal: controller.signal,
|
|
497
|
-
redirect: "follow",
|
|
498
|
-
});
|
|
499
|
-
clearTimeout(timeoutId);
|
|
697
|
+
const response = await this.fetchWithRetry(url, "GET");
|
|
500
698
|
results.push({
|
|
501
699
|
url,
|
|
502
700
|
accessible: response.ok,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfidenceScorer.d.ts","sourceRoot":"","sources":["../../../../../src/services/assessment/modules/securityTests/ConfidenceScorer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAmCD;;GAEG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;;;OAgBG;IACH,mBAAmB,CACjB,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,OAAO,EACrB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,eAAe,EACxB,kBAAkB,CAAC,EAAE,2BAA2B,GAC/C,gBAAgB;
|
|
1
|
+
{"version":3,"file":"ConfidenceScorer.d.ts","sourceRoot":"","sources":["../../../../../src/services/assessment/modules/securityTests/ConfidenceScorer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAmCD;;GAEG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;;;OAgBG;IACH,mBAAmB,CACjB,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,OAAO,EACrB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,eAAe,EACxB,kBAAkB,CAAC,EAAE,2BAA2B,GAC/C,gBAAgB;IAgMnB;;;;;OAKG;IACH,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO;IAOxE;;;;;OAKG;IACH,mBAAmB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO;CAOtD"}
|
|
@@ -58,6 +58,34 @@ export class ConfidenceScorer {
|
|
|
58
58
|
* @returns Confidence result with manual review requirements
|
|
59
59
|
*/
|
|
60
60
|
calculateConfidence(tool, isVulnerable, evidence, responseText, payload, sanitizationResult) {
|
|
61
|
+
// Issue #146: Extract execution context from evidence if present
|
|
62
|
+
// This handles context classification from SecurityResponseAnalyzer
|
|
63
|
+
const contextMatch = evidence.match(/\[Context: (CONFIRMED|LIKELY_FALSE_POSITIVE|SUSPECTED)/);
|
|
64
|
+
if (contextMatch) {
|
|
65
|
+
const context = contextMatch[1];
|
|
66
|
+
// LIKELY_FALSE_POSITIVE: Payload reflected in error message, not executed
|
|
67
|
+
// Mark as low confidence requiring manual review
|
|
68
|
+
if (context === "LIKELY_FALSE_POSITIVE") {
|
|
69
|
+
return {
|
|
70
|
+
confidence: "low",
|
|
71
|
+
requiresManualReview: true,
|
|
72
|
+
manualReviewReason: "Payload reflected in error message, operation failed",
|
|
73
|
+
reviewGuidance: "The server rejected the operation but echoed the payload in the error. " +
|
|
74
|
+
"Verify if the tool actually processed the payload or just reflected it in the error message. " +
|
|
75
|
+
"Check the HTTP status code and error type to confirm the operation was rejected.",
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// CONFIRMED: Operation succeeded, payload was executed
|
|
79
|
+
// High confidence vulnerability
|
|
80
|
+
if (context === "CONFIRMED") {
|
|
81
|
+
return {
|
|
82
|
+
confidence: "high",
|
|
83
|
+
requiresManualReview: false,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// SUSPECTED: Ambiguous case - continue with normal scoring but add review flag
|
|
87
|
+
// Will be handled by downstream logic with medium confidence
|
|
88
|
+
}
|
|
61
89
|
// Issue #56: If sanitization is detected, reduce confidence for vulnerabilities
|
|
62
90
|
// This helps reduce false positives on well-protected servers
|
|
63
91
|
if (isVulnerable && sanitizationResult?.detected) {
|
|
@@ -25,6 +25,37 @@ export declare const HTTP_ERROR_PATTERNS: {
|
|
|
25
25
|
* Used by: isMCPValidationError()
|
|
26
26
|
*/
|
|
27
27
|
export declare const VALIDATION_ERROR_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp];
|
|
28
|
+
/**
|
|
29
|
+
* Issue #146: Error context patterns indicating operation failure
|
|
30
|
+
* Used to detect when payload appears in error message (likely false positive)
|
|
31
|
+
* These patterns indicate the server rejected/failed the operation
|
|
32
|
+
*/
|
|
33
|
+
export declare const ERROR_CONTEXT_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp];
|
|
34
|
+
/**
|
|
35
|
+
* Issue #146: Success context patterns indicating operation completion
|
|
36
|
+
* Used to confirm operation actually executed (high confidence vulnerability)
|
|
37
|
+
* These patterns indicate the server processed and returned results
|
|
38
|
+
*/
|
|
39
|
+
export declare const SUCCESS_CONTEXT_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp];
|
|
40
|
+
/**
|
|
41
|
+
* Issue #146: Check if payload appears in error context (likely false positive)
|
|
42
|
+
* @param responseText The full response text from the tool
|
|
43
|
+
* @param payload The payload that was sent to the tool
|
|
44
|
+
* @returns true if payload is reflected in an error context
|
|
45
|
+
*/
|
|
46
|
+
export declare function isPayloadInErrorContext(responseText: string, payload: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Issue #146: Check if response indicates successful operation (high confidence)
|
|
49
|
+
* @param responseText The full response text from the tool
|
|
50
|
+
* @returns true if response indicates operation succeeded
|
|
51
|
+
*/
|
|
52
|
+
export declare function hasSuccessContext(responseText: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Issue #146: Check if response indicates failed operation (error context)
|
|
55
|
+
* @param responseText The full response text from the tool
|
|
56
|
+
* @returns true if response indicates operation failed
|
|
57
|
+
*/
|
|
58
|
+
export declare function hasErrorContext(responseText: string): boolean;
|
|
28
59
|
/**
|
|
29
60
|
* Patterns indicating actual code/command execution
|
|
30
61
|
* Used by: hasExecutionEvidence()
|
|
@@ -380,6 +411,70 @@ export declare const OUTPUT_INJECTION_PATTERNS: {
|
|
|
380
411
|
/** Canary markers for echo detection */
|
|
381
412
|
readonly canaryMarkers: readonly [RegExp];
|
|
382
413
|
};
|
|
414
|
+
/**
|
|
415
|
+
* Patterns indicating scope violation in tool response
|
|
416
|
+
* Detects when tools exceed their declared annotations at runtime
|
|
417
|
+
* CWE-250: Execution with Unnecessary Privileges
|
|
418
|
+
* CWE-269: Improper Privilege Management
|
|
419
|
+
*/
|
|
420
|
+
export declare const SCOPE_VIOLATION_PATTERNS: readonly [{
|
|
421
|
+
readonly pattern: RegExp;
|
|
422
|
+
readonly evidence: "scope_violation: true (tool exceeded declared scope)";
|
|
423
|
+
}, {
|
|
424
|
+
readonly pattern: RegExp;
|
|
425
|
+
readonly evidence: "scope_escalation: true (privilege escalation via input)";
|
|
426
|
+
}, {
|
|
427
|
+
readonly pattern: RegExp;
|
|
428
|
+
readonly evidence: "actual_scope indicates privileged operation";
|
|
429
|
+
}, {
|
|
430
|
+
readonly pattern: RegExp;
|
|
431
|
+
readonly evidence: "privileged_data exposed in response";
|
|
432
|
+
}, {
|
|
433
|
+
readonly pattern: RegExp;
|
|
434
|
+
readonly evidence: "system_secrets leaked in response";
|
|
435
|
+
}, {
|
|
436
|
+
readonly pattern: RegExp;
|
|
437
|
+
readonly evidence: "Admin mode activated via keyword trigger";
|
|
438
|
+
}];
|
|
439
|
+
/**
|
|
440
|
+
* Patterns indicating safe scope enforcement (hardened behavior)
|
|
441
|
+
* Used to confirm tools properly reject privileged actions
|
|
442
|
+
*/
|
|
443
|
+
export declare const SCOPE_ENFORCED_PATTERNS: readonly [{
|
|
444
|
+
readonly pattern: RegExp;
|
|
445
|
+
readonly evidence: "scope_enforced: true (safe)";
|
|
446
|
+
}, {
|
|
447
|
+
readonly pattern: RegExp;
|
|
448
|
+
readonly evidence: "Action blocked by allowlist";
|
|
449
|
+
}, {
|
|
450
|
+
readonly pattern: RegExp;
|
|
451
|
+
readonly evidence: "Allowlist enforcement";
|
|
452
|
+
}, {
|
|
453
|
+
readonly pattern: RegExp;
|
|
454
|
+
readonly evidence: "Explicit rejection: action not in allowlist";
|
|
455
|
+
}, {
|
|
456
|
+
readonly pattern: RegExp;
|
|
457
|
+
readonly evidence: "No escalation attempted (safe)";
|
|
458
|
+
}, {
|
|
459
|
+
readonly pattern: RegExp;
|
|
460
|
+
readonly evidence: "Allowlist defined and enforced";
|
|
461
|
+
}];
|
|
462
|
+
/**
|
|
463
|
+
* Privileged actions that should be blocked by readOnlyHint=True tools
|
|
464
|
+
*/
|
|
465
|
+
export declare const PRIVILEGED_ACTIONS: readonly ["write", "write_file", "delete", "delete_data", "execute", "execute_command", "network", "network_request", "modify", "modify_config", "admin", "environment_access"];
|
|
466
|
+
/**
|
|
467
|
+
* Escalation keywords that may trigger hidden privilege escalation
|
|
468
|
+
*/
|
|
469
|
+
export declare const ESCALATION_KEYWORDS: readonly ["admin", "sudo", "elevate", "root", "superuser", "privilege"];
|
|
470
|
+
/**
|
|
471
|
+
* Check if response contains scope violation indicators (Issue #144)
|
|
472
|
+
*/
|
|
473
|
+
export declare function hasScopeViolation(text: string): boolean;
|
|
474
|
+
/**
|
|
475
|
+
* Check if response contains scope enforcement indicators (Issue #144)
|
|
476
|
+
*/
|
|
477
|
+
export declare function hasScopeEnforcement(text: string): boolean;
|
|
383
478
|
/**
|
|
384
479
|
* Check if any pattern in array matches text
|
|
385
480
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SecurityPatternLibrary.d.ts","sourceRoot":"","sources":["../../../../../src/services/assessment/modules/securityTests/SecurityPatternLibrary.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;GAGG;AACH,eAAO,MAAM,mBAAmB;IAC9B,kEAAkE;;IAIlE,8DAA8D;;IAG9D,kCAAkC;;IAGlC,gCAAgC;;CAExB,CAAC;AAMX;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,2JAmB5B,CAAC;AAMX;;;GAGG;AACH,eAAO,MAAM,oBAAoB,2LAuBvB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,2BAA2B;IACtC,iCAAiC;;IAejC,0DAA0D;;CAElD,CAAC;AAMX;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,2KA4BxB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,yBAAyB;IACpC,uDAAuD;;IAOvD,oDAAoD;;CAO5C,CAAC;AAMX;;;GAGG;AACH,eAAO,MAAM,yBAAyB;IACpC,oCAAoC;;IAqBpC,4DAA4D;;IAW5D,+BAA+B;;CAEvB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,6BAA6B;;;;CAMhC,CAAC;AAMX;;;GAGG;AACH,eAAO,MAAM,eAAe,mJAkBlB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,mBAAmB,2rBAwGtB,CAAC;AAMX;;;GAGG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+B1B,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAc5B,CAAC;AAMX;;;;GAIG;AAC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AAkB,mGAYrB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,2BAA2B,QACO,CAAC;AAMhD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QAC8B,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,wBAAwB,2EAS3B,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,2BAA2B,oRA4B9B,CAAC;AAMX;;;GAGG;AACH,eAAO,MAAM,0BAA0B;;;;;CAK7B,CAAC;AAMX;;;GAGG;AACH,eAAO,MAAM,uBAAuB;IAClC,iCAAiC;;IAQjC,mDAAmD;;IAInD,gDAAgD;;IAIhD,oCAAoC;;IAEpC,6CAA6C;;CAIrC,CAAC;AAMX;;;;GAIG;AACH,eAAO,MAAM,yBAAyB;IACpC,oDAAoD;;IAOpD,wCAAwC;;CAEhC,CAAC;AAMX;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOjD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKrE"}
|
|
1
|
+
{"version":3,"file":"SecurityPatternLibrary.d.ts","sourceRoot":"","sources":["../../../../../src/services/assessment/modules/securityTests/SecurityPatternLibrary.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;GAGG;AACH,eAAO,MAAM,mBAAmB;IAC9B,kEAAkE;;IAIlE,8DAA8D;;IAG9D,kCAAkC;;IAGlC,gCAAgC;;CAExB,CAAC;AAMX;;;;GAIG;AACH,eAAO,MAAM,yBAAy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AM,GAAG,OAAO,CAKrE"}
|
|
@@ -51,6 +51,75 @@ export const VALIDATION_ERROR_PATTERNS = [
|
|
|
51
51
|
/field.*required/i,
|
|
52
52
|
];
|
|
53
53
|
// =============================================================================
|
|
54
|
+
// ERROR CONTEXT PATTERNS (Issue #146)
|
|
55
|
+
// =============================================================================
|
|
56
|
+
/**
|
|
57
|
+
* Issue #146: Error context patterns indicating operation failure
|
|
58
|
+
* Used to detect when payload appears in error message (likely false positive)
|
|
59
|
+
* These patterns indicate the server rejected/failed the operation
|
|
60
|
+
*/
|
|
61
|
+
export const ERROR_CONTEXT_PATTERNS = [
|
|
62
|
+
/failed\s+to\s+(?:get|read|load|access|process|fetch|retrieve|find)/i,
|
|
63
|
+
/error:\s+response\s+status:\s+\d{3}/i,
|
|
64
|
+
/(?:could\s+not|cannot|unable\s+to)\s+(?:find|locate|access|read|get|load)/i,
|
|
65
|
+
/\b(?:not\s+found|doesn['']t\s+exist|no\s+such|does\s+not\s+exist)\b/i,
|
|
66
|
+
/error\s+(?:loading|reading|processing|fetching|accessing)/i,
|
|
67
|
+
/(?:operation|request)\s+failed/i,
|
|
68
|
+
/invalid\s+(?:path|file|resource|input|parameter)/i,
|
|
69
|
+
/\b(?:rejected|refused|denied)\b/i,
|
|
70
|
+
/(?:resource|file|path)\s+(?:is\s+)?(?:invalid|not\s+allowed)/i,
|
|
71
|
+
/access\s+(?:denied|forbidden)/i,
|
|
72
|
+
/permission\s+denied/i,
|
|
73
|
+
/\b(?:4\d{2}|5\d{2})\s*(?:error|not\s+found|bad\s+request|unauthorized|forbidden)/i,
|
|
74
|
+
];
|
|
75
|
+
/**
|
|
76
|
+
* Issue #146: Success context patterns indicating operation completion
|
|
77
|
+
* Used to confirm operation actually executed (high confidence vulnerability)
|
|
78
|
+
* These patterns indicate the server processed and returned results
|
|
79
|
+
*/
|
|
80
|
+
export const SUCCESS_CONTEXT_PATTERNS = [
|
|
81
|
+
/(?:successfully|completed)\s+(?:read|loaded|accessed|executed|retrieved)/i,
|
|
82
|
+
/file\s+contents?:/i,
|
|
83
|
+
/data\s+retrieved/i,
|
|
84
|
+
/execution\s+result:/i,
|
|
85
|
+
/\boutput:/i,
|
|
86
|
+
/\bresults?:/i,
|
|
87
|
+
/returned\s+(?:data|content|results)/i,
|
|
88
|
+
/read\s+\d+\s+bytes/i,
|
|
89
|
+
/fetched\s+(?:from|data)/i,
|
|
90
|
+
];
|
|
91
|
+
/**
|
|
92
|
+
* Issue #146: Check if payload appears in error context (likely false positive)
|
|
93
|
+
* @param responseText The full response text from the tool
|
|
94
|
+
* @param payload The payload that was sent to the tool
|
|
95
|
+
* @returns true if payload is reflected in an error context
|
|
96
|
+
*/
|
|
97
|
+
export function isPayloadInErrorContext(responseText, payload) {
|
|
98
|
+
// Check if response contains error patterns
|
|
99
|
+
const hasErrorContext = ERROR_CONTEXT_PATTERNS.some((p) => p.test(responseText));
|
|
100
|
+
// Check if payload is reflected in the response
|
|
101
|
+
const payloadReflected = responseText
|
|
102
|
+
.toLowerCase()
|
|
103
|
+
.includes(payload.toLowerCase());
|
|
104
|
+
return hasErrorContext && payloadReflected;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Issue #146: Check if response indicates successful operation (high confidence)
|
|
108
|
+
* @param responseText The full response text from the tool
|
|
109
|
+
* @returns true if response indicates operation succeeded
|
|
110
|
+
*/
|
|
111
|
+
export function hasSuccessContext(responseText) {
|
|
112
|
+
return SUCCESS_CONTEXT_PATTERNS.some((p) => p.test(responseText));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Issue #146: Check if response indicates failed operation (error context)
|
|
116
|
+
* @param responseText The full response text from the tool
|
|
117
|
+
* @returns true if response indicates operation failed
|
|
118
|
+
*/
|
|
119
|
+
export function hasErrorContext(responseText) {
|
|
120
|
+
return ERROR_CONTEXT_PATTERNS.some((p) => p.test(responseText));
|
|
121
|
+
}
|
|
122
|
+
// =============================================================================
|
|
54
123
|
// EXECUTION EVIDENCE PATTERNS
|
|
55
124
|
// =============================================================================
|
|
56
125
|
/**
|
|
@@ -985,6 +1054,111 @@ export const OUTPUT_INJECTION_PATTERNS = {
|
|
|
985
1054
|
canaryMarkers: [/SENTINEL_OUTPUT_MARKER_\d+/],
|
|
986
1055
|
};
|
|
987
1056
|
// =============================================================================
|
|
1057
|
+
// EXCESSIVE PERMISSIONS SCOPE PATTERNS (Issue #144, Challenge #22)
|
|
1058
|
+
// =============================================================================
|
|
1059
|
+
/**
|
|
1060
|
+
* Patterns indicating scope violation in tool response
|
|
1061
|
+
* Detects when tools exceed their declared annotations at runtime
|
|
1062
|
+
* CWE-250: Execution with Unnecessary Privileges
|
|
1063
|
+
* CWE-269: Improper Privilege Management
|
|
1064
|
+
*/
|
|
1065
|
+
export const SCOPE_VIOLATION_PATTERNS = [
|
|
1066
|
+
{
|
|
1067
|
+
pattern: /"scope_violation"\s*:\s*true/i,
|
|
1068
|
+
evidence: "scope_violation: true (tool exceeded declared scope)",
|
|
1069
|
+
},
|
|
1070
|
+
{
|
|
1071
|
+
pattern: /"scope_escalation"\s*:\s*true/i,
|
|
1072
|
+
evidence: "scope_escalation: true (privilege escalation via input)",
|
|
1073
|
+
},
|
|
1074
|
+
{
|
|
1075
|
+
pattern: /"actual_scope"\s*:\s*"(write|delete|execute|network)"/i,
|
|
1076
|
+
evidence: "actual_scope indicates privileged operation",
|
|
1077
|
+
},
|
|
1078
|
+
{
|
|
1079
|
+
pattern: /"privileged_data"\s*:/i,
|
|
1080
|
+
evidence: "privileged_data exposed in response",
|
|
1081
|
+
},
|
|
1082
|
+
{
|
|
1083
|
+
pattern: /"system_secrets"\s*:/i,
|
|
1084
|
+
evidence: "system_secrets leaked in response",
|
|
1085
|
+
},
|
|
1086
|
+
{
|
|
1087
|
+
pattern: /admin[\s_-]?mode[\s_-]?activated/i,
|
|
1088
|
+
evidence: "Admin mode activated via keyword trigger",
|
|
1089
|
+
},
|
|
1090
|
+
];
|
|
1091
|
+
/**
|
|
1092
|
+
* Patterns indicating safe scope enforcement (hardened behavior)
|
|
1093
|
+
* Used to confirm tools properly reject privileged actions
|
|
1094
|
+
*/
|
|
1095
|
+
export const SCOPE_ENFORCED_PATTERNS = [
|
|
1096
|
+
{
|
|
1097
|
+
pattern: /"scope_enforced"\s*:\s*true/i,
|
|
1098
|
+
evidence: "scope_enforced: true (safe)",
|
|
1099
|
+
},
|
|
1100
|
+
{
|
|
1101
|
+
pattern: /"blocked"\s*:\s*true/i,
|
|
1102
|
+
evidence: "Action blocked by allowlist",
|
|
1103
|
+
},
|
|
1104
|
+
{
|
|
1105
|
+
pattern: /action.*not.*in.*allowlist/i,
|
|
1106
|
+
evidence: "Allowlist enforcement",
|
|
1107
|
+
},
|
|
1108
|
+
{
|
|
1109
|
+
pattern: /"rejection_reason"\s*:\s*"action_not_in_allowlist"/i,
|
|
1110
|
+
evidence: "Explicit rejection: action not in allowlist",
|
|
1111
|
+
},
|
|
1112
|
+
{
|
|
1113
|
+
pattern: /"escalation_attempted"\s*:\s*false/i,
|
|
1114
|
+
evidence: "No escalation attempted (safe)",
|
|
1115
|
+
},
|
|
1116
|
+
{
|
|
1117
|
+
pattern: /"allowed_actions"\s*:\s*\[/i,
|
|
1118
|
+
evidence: "Allowlist defined and enforced",
|
|
1119
|
+
},
|
|
1120
|
+
];
|
|
1121
|
+
/**
|
|
1122
|
+
* Privileged actions that should be blocked by readOnlyHint=True tools
|
|
1123
|
+
*/
|
|
1124
|
+
export const PRIVILEGED_ACTIONS = [
|
|
1125
|
+
"write",
|
|
1126
|
+
"write_file",
|
|
1127
|
+
"delete",
|
|
1128
|
+
"delete_data",
|
|
1129
|
+
"execute",
|
|
1130
|
+
"execute_command",
|
|
1131
|
+
"network",
|
|
1132
|
+
"network_request",
|
|
1133
|
+
"modify",
|
|
1134
|
+
"modify_config",
|
|
1135
|
+
"admin",
|
|
1136
|
+
"environment_access",
|
|
1137
|
+
];
|
|
1138
|
+
/**
|
|
1139
|
+
* Escalation keywords that may trigger hidden privilege escalation
|
|
1140
|
+
*/
|
|
1141
|
+
export const ESCALATION_KEYWORDS = [
|
|
1142
|
+
"admin",
|
|
1143
|
+
"sudo",
|
|
1144
|
+
"elevate",
|
|
1145
|
+
"root",
|
|
1146
|
+
"superuser",
|
|
1147
|
+
"privilege",
|
|
1148
|
+
];
|
|
1149
|
+
/**
|
|
1150
|
+
* Check if response contains scope violation indicators (Issue #144)
|
|
1151
|
+
*/
|
|
1152
|
+
export function hasScopeViolation(text) {
|
|
1153
|
+
return SCOPE_VIOLATION_PATTERNS.some(({ pattern }) => pattern.test(text));
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Check if response contains scope enforcement indicators (Issue #144)
|
|
1157
|
+
*/
|
|
1158
|
+
export function hasScopeEnforcement(text) {
|
|
1159
|
+
return SCOPE_ENFORCED_PATTERNS.some(({ pattern }) => pattern.test(text));
|
|
1160
|
+
}
|
|
1161
|
+
// =============================================================================
|
|
988
1162
|
// HELPER FUNCTIONS
|
|
989
1163
|
// =============================================================================
|
|
990
1164
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SecurityPayloadTester.d.ts","sourceRoot":"","sources":["../../../../../src/services/assessment/modules/securityTests/SecurityPayloadTester.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAIjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,2BAA2B,EAC3B,IAAI,EACL,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAGL,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAOhC;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,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AI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,CACR,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,OAAO,CAAC,2BAA2B,CAAC,GACxC,OAAO,CAAC,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"SecurityPayloadTester.d.ts","sourceRoot":"","sources":["../../../../../src/services/assessment/modules/securityTests/SecurityPayloadTester.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAIjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,2BAA2B,EAC3B,IAAI,EACL,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAGL,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAOhC;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACrD;AAED;;GAEG;AACH,qBAAa,qBAAqB;IAO9B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,kBAAkB;IAR5B,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,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