@c4a/extract-proto 0.7.5 → 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 +64 -6
  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) {
@@ -12018,6 +12024,55 @@ var INDEXABLE_EXTENSIONS = new Set([
12018
12024
  var UPLOAD_ALLOWED_EXTENSIONS = collectExtensions(() => true);
12019
12025
  var TEXT_EXTENSIONS = collectExtensions((definition) => definition.cas.encoding === "utf8");
12020
12026
  var UPLOAD_MAX_FILE_SIZE = 5 * 1024 * 1024;
12027
+ // src/protoFields.ts
12028
+ function protoFields(tokens, kind, oneof) {
12029
+ const fields = [];
12030
+ let start = 0;
12031
+ for (let index = 0;index < tokens.length; index++) {
12032
+ if (tokens[index].value === "{") {
12033
+ let end = index + 1;
12034
+ let depth = 1;
12035
+ for (;end < tokens.length && depth > 0; end++) {
12036
+ if (tokens[end].value === "{")
12037
+ depth++;
12038
+ if (tokens[end].value === "}")
12039
+ depth--;
12040
+ }
12041
+ if (tokens[start]?.value === "oneof")
12042
+ fields.push(...protoFields(tokens.slice(index + 1, end - 1), "message", tokens[start + 1]?.value));
12043
+ index = end - 1;
12044
+ start = end;
12045
+ continue;
12046
+ }
12047
+ if (tokens[index].value !== ";")
12048
+ continue;
12049
+ const statement = tokens.slice(start, index);
12050
+ start = index + 1;
12051
+ if (["option", "reserved", "extensions"].includes(statement[0]?.value ?? ""))
12052
+ continue;
12053
+ const equals = statement.findIndex((token) => token.value === "=");
12054
+ const name = statement[equals - 1];
12055
+ const number = statement[equals + 1];
12056
+ if (name?.kind !== "identifier" || number === undefined)
12057
+ continue;
12058
+ const label = statement[0]?.value;
12059
+ const offset = ["optional", "required", "repeated"].includes(label ?? "") ? 1 : 0;
12060
+ const defaultIndex = statement.findIndex((token, at) => token.value === "default" && statement[at + 1]?.value === "=");
12061
+ const defaultToken = statement[defaultIndex + 2];
12062
+ fields.push({
12063
+ name: name.value,
12064
+ number: number.value,
12065
+ type: kind === "enum" ? "enum value" : statement.slice(offset, equals - 1).map((token) => token.value).join(""),
12066
+ ...label === "optional" ? { optional: true } : label === "required" ? { optional: false } : {},
12067
+ repeated: label === "repeated",
12068
+ ...oneof === undefined ? {} : { oneof },
12069
+ ...defaultIndex < 0 || defaultToken === undefined ? {} : { defaultValue: defaultToken.kind === "string" ? JSON.stringify(defaultToken.value) : defaultToken.value },
12070
+ location: { line: name.line, column: name.column }
12071
+ });
12072
+ }
12073
+ return fields;
12074
+ }
12075
+
12021
12076
  // src/protoParser.ts
12022
12077
  import { posix } from "node:path";
12023
12078
 
@@ -12276,8 +12331,10 @@ class ProtoDocumentParser {
12276
12331
  const kind = this.take().value;
12277
12332
  const name = this.identifier(`${kind} name`);
12278
12333
  const qualifiedName = prefix ? `${prefix}.${name.value}` : name.value;
12279
- this.document.types.push({ kind, name: name.value, qualified_name: qualifiedName, locator: { path: this.path, line: name.line, column: name.column } });
12334
+ const declaration = { kind, name: name.value, qualified_name: qualifiedName, locator: { path: this.path, line: name.line, column: name.column } };
12335
+ this.document.types.push(declaration);
12280
12336
  this.take("{");
12337
+ const fieldStart = this.index;
12281
12338
  while (this.token() && this.token().value !== "}") {
12282
12339
  if (this.token().value === ";") {
12283
12340
  this.index += 1;
@@ -12293,6 +12350,7 @@ class ProtoDocumentParser {
12293
12350
  }
12294
12351
  this.skipDeclaration();
12295
12352
  }
12353
+ declaration.fields = protoFields(this.tokens.slice(fieldStart, this.index), kind);
12296
12354
  this.take("}");
12297
12355
  }
12298
12356
  parseService() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c4a/extract-proto",
3
- "version": "0.7.5",
3
+ "version": "0.7.9",
4
4
  "type": "module",
5
5
  "description": "Protocol Buffers IDL catalog parser for Context",
6
6
  "license": "MIT",