@zereight/mcp-gitlab 2.3.28-next.241 → 2.3.28-next.242
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/build/masking/engine.js +158 -24
- package/package.json +1 -1
package/build/masking/engine.js
CHANGED
|
@@ -24,6 +24,42 @@ const BUILTIN_RULES = [
|
|
|
24
24
|
flags: "g",
|
|
25
25
|
replacement: "[IP address]",
|
|
26
26
|
},
|
|
27
|
+
{
|
|
28
|
+
id: "jwt",
|
|
29
|
+
type: "regex",
|
|
30
|
+
// Three base64url segments starting with eyJ ({"). Segment lengths are bounded.
|
|
31
|
+
// The lookbehind allows a start only where the base64url run begins. Without
|
|
32
|
+
// it, every eyJ inside a run such as "-eyJ-eyJ-..." rescans up to 8192 chars.
|
|
33
|
+
// Trade-off: an eyJ directly after "-" (e.g. "sess-eyJ...") is no longer a start.
|
|
34
|
+
pattern: "(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{0,8192}\\.[A-Za-z0-9_-]{1,8192}\\.[A-Za-z0-9_-]{1,8192}(?![A-Za-z0-9_-])",
|
|
35
|
+
flags: "g",
|
|
36
|
+
replacement: "[JWT masked]",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "pem-private-key",
|
|
40
|
+
type: "regex",
|
|
41
|
+
// BEGIN/END labels must match. Line breaks may be real or literal \n / \r\n
|
|
42
|
+
// escapes (a key nested in an escaped JSON string), and "/" may be written
|
|
43
|
+
// as the JSON escape \/. The body is PEM base64,
|
|
44
|
+
// Proc-Type / DEK-Info lines, and single dashes. It cannot contain a run of
|
|
45
|
+
// five dashes, which valid PEM bodies never do, so each scan stops at the
|
|
46
|
+
// next header or footer. Without that bound, every BEGIN rescans up to 32768
|
|
47
|
+
// chars through the following headers.
|
|
48
|
+
pattern: "-----BEGIN ([A-Z0-9 ]{0,40}PRIVATE KEY)-----(?:\\r?\\n|\\\\r\\\\n|\\\\n)(?:[A-Za-z0-9+/=\\s,.:]|\\\\[rn/]|-(?!----)){1,32768}?-----END \\1-----",
|
|
49
|
+
flags: "g",
|
|
50
|
+
replacement: "[Private key masked]",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "aws-access-key",
|
|
54
|
+
type: "regex",
|
|
55
|
+
// AKIA/ASIA IDs are a fixed 20-char shape. Secret values are only matched
|
|
56
|
+
// on aws_secret_access_key assignments (quoted or unquoted names) to keep
|
|
57
|
+
// false positives low. A JSON-escaped "\/" counts as one secret character.
|
|
58
|
+
// JSON object fields are handled separately.
|
|
59
|
+
pattern: "\\b(?:AKIA|ASIA)[A-Z0-9]{16}\\b|\\b(?:aws_secret_access_key|AWS_SECRET_ACCESS_KEY)[\"']?\\s*[=:]\\s*[\"']?(?:[A-Za-z0-9/+=]|\\\\/){40}(?![A-Za-z0-9/+=]|\\\\/)",
|
|
60
|
+
flags: "g",
|
|
61
|
+
replacement: "[AWS key masked]",
|
|
62
|
+
},
|
|
27
63
|
];
|
|
28
64
|
const ALLOWED_REGEX_FLAGS = new Set(["g", "i", "m", "s", "u"]);
|
|
29
65
|
function assertString(value, field) {
|
|
@@ -188,21 +224,59 @@ function validateMaskingFile(value, description) {
|
|
|
188
224
|
throw new Error(`${description}.rules must be an array`);
|
|
189
225
|
}
|
|
190
226
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
227
|
+
const AWS_SECRET_FIELD_NAMES = new Set(["aws_secret_access_key", "AWS_SECRET_ACCESS_KEY"]);
|
|
228
|
+
const AWS_SECRET_VALUE_PATTERN = /^[A-Za-z0-9/+=]{40}$/;
|
|
229
|
+
function applyAwsSecretFieldMask(parentKey, value, masked, replacement) {
|
|
230
|
+
if (replacement !== undefined &&
|
|
231
|
+
parentKey !== undefined &&
|
|
232
|
+
AWS_SECRET_FIELD_NAMES.has(parentKey) &&
|
|
233
|
+
AWS_SECRET_VALUE_PATTERN.test(value)) {
|
|
234
|
+
return replacement;
|
|
195
235
|
}
|
|
236
|
+
return masked;
|
|
237
|
+
}
|
|
238
|
+
function readJsonStringToken(token) {
|
|
239
|
+
const parsed = JSON.parse(token);
|
|
240
|
+
if (typeof parsed !== "string") {
|
|
241
|
+
throw new Error("JSON string token did not decode to a string");
|
|
242
|
+
}
|
|
243
|
+
return parsed;
|
|
244
|
+
}
|
|
245
|
+
function readGitlabCiAwsSecretKey(value) {
|
|
246
|
+
if (!("key" in value))
|
|
247
|
+
return undefined;
|
|
248
|
+
const key = value.key;
|
|
249
|
+
if (typeof key !== "string" || !AWS_SECRET_FIELD_NAMES.has(key))
|
|
250
|
+
return undefined;
|
|
251
|
+
return key;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Masks one string value under its field name. maskStrings and the JSON-text
|
|
255
|
+
* path both call this so structured and text output agree for every field.
|
|
256
|
+
*/
|
|
257
|
+
function maskFieldValue(value, parentKey, mask) {
|
|
258
|
+
const masked = mask(value, parentKey);
|
|
259
|
+
return masked !== value && parentKey === "download_url" ? "[Download URL masked]" : masked;
|
|
260
|
+
}
|
|
261
|
+
function maskStrings(value, mask, parentKey) {
|
|
262
|
+
if (typeof value === "string")
|
|
263
|
+
return maskFieldValue(value, parentKey, mask);
|
|
196
264
|
if (Array.isArray(value))
|
|
197
265
|
return value.map(item => maskStrings(item, mask, parentKey));
|
|
198
266
|
if (value && typeof value === "object") {
|
|
267
|
+
const ciKey = readGitlabCiAwsSecretKey(value);
|
|
199
268
|
const output = {};
|
|
200
|
-
for (const [key, item] of Object.entries(value))
|
|
201
|
-
|
|
269
|
+
for (const [key, item] of Object.entries(value)) {
|
|
270
|
+
const fieldKey = key === "value" && ciKey !== undefined ? ciKey : key;
|
|
271
|
+
output[key] = maskStrings(item, mask, fieldKey);
|
|
272
|
+
}
|
|
202
273
|
return output;
|
|
203
274
|
}
|
|
204
275
|
return value;
|
|
205
276
|
}
|
|
277
|
+
// Complete JSON string literals and structural punctuation. Text between these
|
|
278
|
+
// matches (numbers, literals, whitespace) is copied through untouched.
|
|
279
|
+
const JSON_STRING_OR_STRUCTURE_PATTERN = /"(?:\\.|[^"\\])*"|[{}[\],]/g;
|
|
206
280
|
function maskJsonText(text, mask) {
|
|
207
281
|
try {
|
|
208
282
|
const parsed = JSON.parse(text);
|
|
@@ -213,23 +287,81 @@ function maskJsonText(text, mask) {
|
|
|
213
287
|
return mask(text);
|
|
214
288
|
}
|
|
215
289
|
// Rewrite only JSON string values. Re-serializing the parsed object would
|
|
216
|
-
// change whitespace and lose precision in numeric values from GitLab.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
290
|
+
// change whitespace and lose precision in numeric values from GitLab. The
|
|
291
|
+
// scope stack follows the same rules as maskStrings: an object value takes
|
|
292
|
+
// the property name, an array element inherits the enclosing field name, and
|
|
293
|
+
// leaving a nested container restores the enclosing scope. Collect values
|
|
294
|
+
// first so a GitLab CI `value` is masked even when it appears before `key`.
|
|
295
|
+
const scopes = [];
|
|
296
|
+
const stringValues = [];
|
|
297
|
+
const objectCiKeys = new Map();
|
|
298
|
+
let nextObjectId = 0;
|
|
299
|
+
for (const match of text.matchAll(JSON_STRING_OR_STRUCTURE_PATTERN)) {
|
|
300
|
+
const token = match[0];
|
|
301
|
+
const index = match.index;
|
|
302
|
+
if (index === undefined)
|
|
303
|
+
continue;
|
|
304
|
+
const scope = scopes[scopes.length - 1];
|
|
305
|
+
if (token === "{") {
|
|
306
|
+
scopes.push({
|
|
307
|
+
isObject: true,
|
|
308
|
+
expectingKey: true,
|
|
309
|
+
fieldName: undefined,
|
|
310
|
+
objectId: nextObjectId,
|
|
311
|
+
});
|
|
312
|
+
nextObjectId += 1;
|
|
313
|
+
continue;
|
|
223
314
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
315
|
+
if (token === "[") {
|
|
316
|
+
scopes.push({
|
|
317
|
+
isObject: false,
|
|
318
|
+
expectingKey: false,
|
|
319
|
+
fieldName: scope?.fieldName,
|
|
320
|
+
objectId: scope?.objectId ?? -1,
|
|
321
|
+
});
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (token === "}" || token === "]") {
|
|
325
|
+
scopes.pop();
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (token === ",") {
|
|
329
|
+
if (scope?.isObject)
|
|
330
|
+
scope.expectingKey = true;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const decoded = readJsonStringToken(token);
|
|
334
|
+
if (scope?.isObject && scope.expectingKey) {
|
|
335
|
+
scope.fieldName = decoded;
|
|
336
|
+
scope.expectingKey = false;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (scope?.isObject && scope.fieldName === "key" && AWS_SECRET_FIELD_NAMES.has(decoded)) {
|
|
340
|
+
objectCiKeys.set(scope.objectId, decoded);
|
|
341
|
+
}
|
|
342
|
+
stringValues.push({
|
|
343
|
+
index,
|
|
344
|
+
token,
|
|
345
|
+
decoded,
|
|
346
|
+
fieldName: scope?.fieldName,
|
|
347
|
+
objectId: scope?.objectId ?? -1,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
let output = "";
|
|
351
|
+
let cursor = 0;
|
|
352
|
+
for (const item of stringValues) {
|
|
353
|
+
output += text.slice(cursor, item.index);
|
|
354
|
+
const ciKey = objectCiKeys.get(item.objectId);
|
|
355
|
+
const parentKey = item.fieldName === "value" && ciKey !== undefined ? ciKey : item.fieldName;
|
|
356
|
+
const masked = maskFieldValue(item.decoded, parentKey, mask);
|
|
357
|
+
output += masked === item.decoded ? item.token : JSON.stringify(masked);
|
|
358
|
+
cursor = item.index + item.token.length;
|
|
359
|
+
}
|
|
360
|
+
return output + text.slice(cursor);
|
|
230
361
|
}
|
|
231
362
|
function createMaskingEngineFromFile(file, configPath) {
|
|
232
|
-
const
|
|
363
|
+
const builtinRules = mergeBuiltinRules(file);
|
|
364
|
+
const rules = [...(file.rules ?? []), ...builtinRules].map(compileRule);
|
|
233
365
|
const maskedErrors = new WeakSet();
|
|
234
366
|
const maskText = (text) => {
|
|
235
367
|
const matches = [];
|
|
@@ -269,10 +401,12 @@ function createMaskingEngineFromFile(file, configPath) {
|
|
|
269
401
|
}
|
|
270
402
|
return output + text.slice(cursor);
|
|
271
403
|
};
|
|
404
|
+
const awsSecretFieldReplacement = builtinRules.find(rule => rule.id === "aws-access-key")?.replacement;
|
|
405
|
+
const maskString = (text, parentKey) => applyAwsSecretFieldMask(parentKey, text, maskText(text), awsSecretFieldReplacement);
|
|
272
406
|
return {
|
|
273
407
|
configPath,
|
|
274
408
|
maskText,
|
|
275
|
-
maskValue: (value) => maskStrings(value,
|
|
409
|
+
maskValue: (value) => maskStrings(value, maskString),
|
|
276
410
|
maskToolResult: (result, options) => {
|
|
277
411
|
const output = { ...result };
|
|
278
412
|
if (Array.isArray(output.content))
|
|
@@ -283,13 +417,13 @@ function createMaskingEngineFromFile(file, configPath) {
|
|
|
283
417
|
if (typeof block.text === "string") {
|
|
284
418
|
block.text =
|
|
285
419
|
options?.textFormat === "plain"
|
|
286
|
-
?
|
|
287
|
-
: maskJsonText(block.text,
|
|
420
|
+
? maskString(block.text)
|
|
421
|
+
: maskJsonText(block.text, maskString);
|
|
288
422
|
}
|
|
289
423
|
return block;
|
|
290
424
|
});
|
|
291
425
|
if (output.structuredContent !== undefined)
|
|
292
|
-
output.structuredContent = maskStrings(output.structuredContent,
|
|
426
|
+
output.structuredContent = maskStrings(output.structuredContent, maskString);
|
|
293
427
|
return output;
|
|
294
428
|
},
|
|
295
429
|
maskError: (error) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zereight/mcp-gitlab",
|
|
3
|
-
"version": "2.3.28-next.
|
|
3
|
+
"version": "2.3.28-next.242",
|
|
4
4
|
"mcpName": "io.github.zereight/gitlab-mcp",
|
|
5
5
|
"description": "GitLab MCP server for projects, merge requests, issues, pipelines, wiki, releases, and more",
|
|
6
6
|
"keywords": [
|