@c4a/extract-go 0.7.8 → 0.7.9

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.
Files changed (2) hide show
  1. package/index.js +31 -19
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -11444,15 +11444,21 @@ function replaceWithCount(value, pattern, replacement, count) {
11444
11444
  return replacement(...args.slice(0, -2));
11445
11445
  });
11446
11446
  }
11447
+ var SECRET_TEXT_KEY = "(?:[A-Za-z0-9_.-]*(?:password|passwd|pwd|secret|token|credential|cookie)[A-Za-z0-9_.-]*|api[-_]?key|access[-_]?(?:key|token)|private[-_]?key|client[-_]?secret|authorization)";
11448
+ var SECRET_TEXT_ASSIGNMENT = `(?:=\\s*|:\\s+(?=\\S)|:\\s*(?=["']))`;
11449
+ var AUTHORIZATION_TEXT_PATTERN = new RegExp(`(\\bauthorization\\s*:\\s*(?:bearer|basic)\\s+)` + `(?!${escapeRegExp(INDEXER_OUTPUT_REDACTION_MARKER)})[^\\s,;]+`, "giu");
11450
+ var QUERY_SECRET_TEXT_PATTERN = new RegExp(`([?&](?:access_token|refresh_token|api_key|password|secret)=)` + `(?!${escapeRegExp(INDEXER_OUTPUT_REDACTION_MARKER)})[^&#\\s]+`, "giu");
11451
+ var ASSIGNMENT_SECRET_TEXT_PATTERN = new RegExp(`((?:["']?${SECRET_TEXT_KEY}["']?)\\s*${SECRET_TEXT_ASSIGNMENT})` + `(?!["']?${escapeRegExp(INDEXER_OUTPUT_REDACTION_MARKER)})` + `(?:"(?:\\\\.|[^"])*"|'(?:\\\\.|[^'])*'|[^\\s,;}\\]]+)`, "giu");
11447
11452
  function redactKnownText(value, count) {
11453
+ if (!value.includes(":") && !value.includes("=") && !value.includes("-----BEGIN ")) {
11454
+ return value;
11455
+ }
11448
11456
  let output = value;
11449
11457
  output = replaceWithCount(output, /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/gu, INDEXER_OUTPUT_REDACTION_MARKER, count);
11450
- output = replaceWithCount(output, new RegExp(`(\\bauthorization\\s*:\\s*(?:bearer|basic)\\s+)` + `(?!${escapeRegExp(INDEXER_OUTPUT_REDACTION_MARKER)})[^\\s,;]+`, "giu"), (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}`, count);
11458
+ output = replaceWithCount(output, AUTHORIZATION_TEXT_PATTERN, (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}`, count);
11451
11459
  output = replaceWithCount(output, /([a-z][a-z0-9+.-]*:\/\/)[^\s/@:]+:[^\s/@]+@/giu, (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}@`, count);
11452
- output = replaceWithCount(output, new RegExp(`([?&](?:access_token|refresh_token|api_key|password|secret)=)` + `(?!${escapeRegExp(INDEXER_OUTPUT_REDACTION_MARKER)})[^&#\\s]+`, "giu"), (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}`, count);
11453
- const key = "(?:[A-Za-z0-9_.-]*(?:password|passwd|pwd|secret|token|credential|cookie)[A-Za-z0-9_.-]*|api[-_]?key|access[-_]?(?:key|token)|private[-_]?key|client[-_]?secret|authorization)";
11454
- const assignment = `(?:=\\s*|:\\s+(?=\\S)|:\\s*(?=["']))`;
11455
- output = replaceWithCount(output, new RegExp(`((?:["']?${key}["']?)\\s*${assignment})` + `(?!["']?${escapeRegExp(INDEXER_OUTPUT_REDACTION_MARKER)})` + `(?:"(?:\\\\.|[^"])*"|'(?:\\\\.|[^'])*'|[^\\s,;}\\]]+)`, "giu"), (_match, prefix) => `${prefix}"${INDEXER_OUTPUT_REDACTION_MARKER}"`, count);
11460
+ output = replaceWithCount(output, QUERY_SECRET_TEXT_PATTERN, (_match, prefix) => `${prefix}${INDEXER_OUTPUT_REDACTION_MARKER}`, count);
11461
+ output = replaceWithCount(output, ASSIGNMENT_SECRET_TEXT_PATTERN, (_match, prefix) => `${prefix}"${INDEXER_OUTPUT_REDACTION_MARKER}"`, count);
11456
11462
  return output;
11457
11463
  }
11458
11464
  function redactBlockedText(value, blocked, count) {
@@ -12359,20 +12365,24 @@ function indexGoSource(source, filePath, options = {}) {
12359
12365
  const tree = parser.parse(source);
12360
12366
  if (!tree)
12361
12367
  throw new Error(`Go parser returned no syntax tree for ${filePath}`);
12362
- const root = tree.rootNode;
12363
- const packageName = descendants(root, "package_identifier")[0]?.text ?? "unknown";
12364
- const imports = extractImports(root, filePath);
12365
- const relations = extractCallsAndRoutes(root, filePath, imports);
12366
- return {
12367
- path: filePath,
12368
- package: packageName,
12369
- imports,
12370
- symbols: extractSymbols(root, filePath, packageName, options.exportedOnly ?? false),
12371
- calls: relations.calls,
12372
- routes: relations.routes,
12373
- parseErrors: countParseErrors(root),
12374
- lines: source.length === 0 ? 0 : source.split(/\r\n|\r|\n/u).length
12375
- };
12368
+ try {
12369
+ const root = tree.rootNode;
12370
+ const packageName = descendants(root, "package_identifier")[0]?.text ?? "unknown";
12371
+ const imports = extractImports(root, filePath);
12372
+ const relations = extractCallsAndRoutes(root, filePath, imports);
12373
+ return {
12374
+ path: filePath,
12375
+ package: packageName,
12376
+ imports,
12377
+ symbols: extractSymbols(root, filePath, packageName, options.exportedOnly ?? false),
12378
+ calls: relations.calls,
12379
+ routes: relations.routes,
12380
+ parseErrors: countParseErrors(root),
12381
+ lines: source.length === 0 ? 0 : source.split(/\r\n|\r|\n/u).length
12382
+ };
12383
+ } finally {
12384
+ tree.delete();
12385
+ }
12376
12386
  }
12377
12387
 
12378
12388
  // src/plugin.ts
@@ -12489,6 +12499,7 @@ class GoPlugin {
12489
12499
  relations.push({
12490
12500
  type: "imports" /* Imports */,
12491
12501
  from: entry.path,
12502
+ file: entry.path,
12492
12503
  to: imported.path,
12493
12504
  isExternal: true,
12494
12505
  grounding: "code" /* Code */,
@@ -12503,6 +12514,7 @@ class GoPlugin {
12503
12514
  relations.push({
12504
12515
  type: "calls" /* Calls */,
12505
12516
  from: call.enclosingSymbol,
12517
+ file: entry.path,
12506
12518
  to: call.callee,
12507
12519
  isExternal: call.importPath !== undefined,
12508
12520
  grounding: "code" /* Code */,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c4a/extract-go",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "type": "module",
5
5
  "description": "Go extraction plugin and structural index for Context",
6
6
  "license": "MIT",