@c4a/extract-thrift 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.
- package/index.js +74 -7
- 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,
|
|
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,
|
|
11453
|
-
|
|
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,59 @@ 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/thriftFields.ts
|
|
12028
|
+
function thriftFields(tokens) {
|
|
12029
|
+
const fields = [];
|
|
12030
|
+
for (let index = 0;index < tokens.length; index++) {
|
|
12031
|
+
if (tokens[index]?.kind !== "number" || tokens[index + 1]?.value !== ":")
|
|
12032
|
+
continue;
|
|
12033
|
+
const number = tokens[index].value;
|
|
12034
|
+
let cursor = index + 2;
|
|
12035
|
+
const label = tokens[cursor]?.value;
|
|
12036
|
+
if (label === "optional" || label === "required")
|
|
12037
|
+
cursor++;
|
|
12038
|
+
const typeStart = cursor++;
|
|
12039
|
+
if (tokens[cursor]?.value === "<") {
|
|
12040
|
+
let depth = 0;
|
|
12041
|
+
do {
|
|
12042
|
+
if (tokens[cursor]?.value === "<")
|
|
12043
|
+
depth++;
|
|
12044
|
+
if (tokens[cursor]?.value === ">")
|
|
12045
|
+
depth--;
|
|
12046
|
+
cursor++;
|
|
12047
|
+
} while (cursor < tokens.length && depth > 0);
|
|
12048
|
+
}
|
|
12049
|
+
const name = tokens[cursor];
|
|
12050
|
+
if (name?.kind !== "identifier")
|
|
12051
|
+
continue;
|
|
12052
|
+
const type = tokens.slice(typeStart, cursor).map((token) => token.value).join("");
|
|
12053
|
+
cursor++;
|
|
12054
|
+
let defaultValue;
|
|
12055
|
+
if (tokens[cursor]?.value === "=") {
|
|
12056
|
+
const start = ++cursor;
|
|
12057
|
+
let depth = 0;
|
|
12058
|
+
do {
|
|
12059
|
+
if (["[", "{"].includes(tokens[cursor]?.value ?? ""))
|
|
12060
|
+
depth++;
|
|
12061
|
+
if (["]", "}"].includes(tokens[cursor]?.value ?? ""))
|
|
12062
|
+
depth--;
|
|
12063
|
+
cursor++;
|
|
12064
|
+
} while (cursor < tokens.length && depth > 0);
|
|
12065
|
+
defaultValue = tokens.slice(start, cursor).map((token) => token.kind === "string" ? JSON.stringify(token.value) : token.value).join("");
|
|
12066
|
+
}
|
|
12067
|
+
fields.push({
|
|
12068
|
+
name: name.value,
|
|
12069
|
+
type,
|
|
12070
|
+
number,
|
|
12071
|
+
...label === "optional" ? { optional: true } : label === "required" ? { optional: false } : {},
|
|
12072
|
+
...defaultValue === undefined ? {} : { defaultValue },
|
|
12073
|
+
location: { line: name.line, column: name.column }
|
|
12074
|
+
});
|
|
12075
|
+
index = cursor - 1;
|
|
12076
|
+
}
|
|
12077
|
+
return fields;
|
|
12078
|
+
}
|
|
12079
|
+
|
|
12021
12080
|
// src/thriftParser.ts
|
|
12022
12081
|
import { posix } from "node:path";
|
|
12023
12082
|
|
|
@@ -12206,11 +12265,14 @@ function parseMethods(path2, serviceName, tokens) {
|
|
|
12206
12265
|
name: nameToken.value,
|
|
12207
12266
|
return_type: tokenText(returnTokens),
|
|
12208
12267
|
oneway,
|
|
12268
|
+
fields: thriftFields(tokens.slice(open + 1, matching(tokens, open, "(", ")"))),
|
|
12209
12269
|
locator: { path: path2, line: nameToken.line, column: nameToken.column }
|
|
12210
12270
|
});
|
|
12211
12271
|
index = matching(tokens, open, "(", ")") + 1;
|
|
12212
12272
|
if (tokens[index]?.value === "throws" && tokens[index + 1]?.value === "(") {
|
|
12213
|
-
|
|
12273
|
+
const end = matching(tokens, index + 1, "(", ")");
|
|
12274
|
+
methods.at(-1).throws = thriftFields(tokens.slice(index + 2, end));
|
|
12275
|
+
index = end + 1;
|
|
12214
12276
|
}
|
|
12215
12277
|
if (tokens[index]?.value === "(") {
|
|
12216
12278
|
const parsed = parseAnnotationGroup(`service:${serviceName}:method:${nameToken.value}`, path2, tokens, index);
|
|
@@ -12281,7 +12343,12 @@ function parseThriftSources(files) {
|
|
|
12281
12343
|
const open = tokens.findIndex((candidate, candidateIndex) => candidateIndex > index && candidate.value === "{");
|
|
12282
12344
|
if (open < 0)
|
|
12283
12345
|
throw new ThriftSyntaxError(`${token.value} body is missing`, token.line, token.column);
|
|
12284
|
-
document.types.push({
|
|
12346
|
+
document.types.push({
|
|
12347
|
+
kind: token.value,
|
|
12348
|
+
name: name.value,
|
|
12349
|
+
fields: thriftFields(tokens.slice(open + 1, matching(tokens, open, "{", "}"))),
|
|
12350
|
+
locator: { path: path2, line: name.line, column: name.column }
|
|
12351
|
+
});
|
|
12285
12352
|
index = matching(tokens, open, "{", "}") + 1;
|
|
12286
12353
|
if (tokens[index]?.value === "(") {
|
|
12287
12354
|
const parsed = parseAnnotationGroup(`type:${name.value}`, path2, tokens, index);
|