@osovv/vv-opencode 0.12.0 → 0.13.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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// FILE: src/plugins/secrets-redaction/engine.ts
|
|
2
|
-
// VERSION: 1.
|
|
2
|
+
// VERSION: 1.1.0
|
|
3
3
|
// START_MODULE_CONTRACT
|
|
4
4
|
// PURPOSE: Core redaction engine — performs find/replace of secrets with placeholders in text.
|
|
5
|
-
// SCOPE: text scanning, match sorting,
|
|
5
|
+
// SCOPE: text scanning, overlap resolution, match sorting, and replacement
|
|
6
6
|
// DEPENDS: session, patterns
|
|
7
7
|
// LINKS: knowledge-graph://plugins/secrets-redaction
|
|
8
8
|
// ROLE: RUNTIME
|
|
@@ -12,37 +12,11 @@
|
|
|
12
12
|
// START_MODULE_MAP
|
|
13
13
|
// redactText - replaces secrets in text with placeholders, returns changed text + match list
|
|
14
14
|
// END_MODULE_MAP
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let currentEnd = intervals[0][0];
|
|
21
|
-
for (const [start, end] of intervals) {
|
|
22
|
-
if (start > currentEnd) {
|
|
23
|
-
result.push([currentEnd, start]);
|
|
24
|
-
}
|
|
25
|
-
if (end > currentEnd) {
|
|
26
|
-
currentEnd = end;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
function insertCovered(intervals, newInterval) {
|
|
32
|
-
const merged = [...intervals, newInterval];
|
|
33
|
-
merged.sort((a, b) => a[0] - b[0]);
|
|
34
|
-
const result = [];
|
|
35
|
-
for (const interval of merged) {
|
|
36
|
-
if (result.length > 0 && interval[0] <= result[result.length - 1][1]) {
|
|
37
|
-
result[result.length - 1][1] = Math.max(result[result.length - 1][1], interval[1]);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
result.push([...interval]);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
function sortByPositionDesc(rules, text) {
|
|
15
|
+
//
|
|
16
|
+
// START_CHANGE_SUMMARY
|
|
17
|
+
// LAST_CHANGE: [v1.1.0 - Fixed overlap handling so first and wider earlier matches redact correctly instead of being skipped entirely.]
|
|
18
|
+
// END_CHANGE_SUMMARY
|
|
19
|
+
function sortByPositionAsc(rules, text) {
|
|
46
20
|
const allMatches = [];
|
|
47
21
|
for (const rule of rules) {
|
|
48
22
|
const re = new RegExp(rule.pattern.source, rule.pattern.flags.includes("g") ? rule.pattern.flags : `${rule.pattern.flags}g`);
|
|
@@ -55,17 +29,23 @@ function sortByPositionDesc(rules, text) {
|
|
|
55
29
|
const aStart = a.match.index;
|
|
56
30
|
const bStart = b.match.index;
|
|
57
31
|
if (aStart !== bStart)
|
|
58
|
-
return
|
|
32
|
+
return aStart - bStart;
|
|
59
33
|
return b.match[0].length - a.match[0].length;
|
|
60
34
|
});
|
|
61
35
|
return allMatches.map((x) => ({ rule: x.rule, matches: x.match }));
|
|
62
36
|
}
|
|
37
|
+
function overlapsSelected(start, selected) {
|
|
38
|
+
const lastSelected = selected[selected.length - 1];
|
|
39
|
+
if (!lastSelected) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return start < lastSelected.end;
|
|
43
|
+
}
|
|
63
44
|
export function redactText(input, patternSet, session) {
|
|
64
45
|
if (!input || patternSet.rules.length === 0) {
|
|
65
46
|
return { text: input, matches: [] };
|
|
66
47
|
}
|
|
67
|
-
const sorted =
|
|
68
|
-
const covered = [];
|
|
48
|
+
const sorted = sortByPositionAsc(patternSet.rules, input);
|
|
69
49
|
const matches = [];
|
|
70
50
|
for (const { rule, matches: match } of sorted) {
|
|
71
51
|
const start = match.index;
|
|
@@ -74,40 +54,20 @@ export function redactText(input, patternSet, session) {
|
|
|
74
54
|
if (patternSet.exclude.has(value.toLowerCase())) {
|
|
75
55
|
continue;
|
|
76
56
|
}
|
|
77
|
-
|
|
78
|
-
const isInside = gaps.every(([gStart, gEnd]) => start >= gStart && end <= gEnd);
|
|
79
|
-
if (isInside)
|
|
57
|
+
if (overlapsSelected(start, matches)) {
|
|
80
58
|
continue;
|
|
59
|
+
}
|
|
81
60
|
const placeholder = session.getOrCreatePlaceholder(value, rule.category);
|
|
82
61
|
matches.push({ start, end, original: value, placeholder, category: rule.category });
|
|
83
|
-
const remainingGaps = [];
|
|
84
|
-
for (const [gStart, gEnd] of gaps) {
|
|
85
|
-
if (start >= gEnd || end <= gStart) {
|
|
86
|
-
remainingGaps.push([gStart, gEnd]);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
if (start > gStart) {
|
|
90
|
-
remainingGaps.push([gStart, start]);
|
|
91
|
-
}
|
|
92
|
-
if (end < gEnd) {
|
|
93
|
-
remainingGaps.push([end, gEnd]);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
covered.length = 0;
|
|
98
|
-
for (const g of remainingGaps) {
|
|
99
|
-
insertCovered(covered, g);
|
|
100
|
-
}
|
|
101
62
|
}
|
|
102
|
-
const sortedMatches = [...matches].sort((a, b) => a.start - b.start);
|
|
103
63
|
let result = "";
|
|
104
64
|
let lastIndex = 0;
|
|
105
|
-
for (const m of
|
|
65
|
+
for (const m of matches) {
|
|
106
66
|
result += input.slice(lastIndex, m.start);
|
|
107
67
|
result += m.placeholder;
|
|
108
68
|
lastIndex = m.end;
|
|
109
69
|
}
|
|
110
70
|
result += input.slice(lastIndex);
|
|
111
|
-
return { text: result, matches
|
|
71
|
+
return { text: result, matches };
|
|
112
72
|
}
|
|
113
73
|
//# sourceMappingURL=engine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../../src/plugins/secrets-redaction/engine.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,iBAAiB;AACjB,wBAAwB;AACxB,iGAAiG;A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