@eagleoutice/flowr 2.16.1 → 2.16.2
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/dataflow/environments/built-in-props.d.ts +5 -2
- package/dataflow/environments/built-in-props.js +6 -3
- package/dataflow/environments/default-builtin-config.d.ts +197 -11
- package/dataflow/environments/default-builtin-config.js +62 -42
- package/dataflow/environments/identifier.d.ts +1 -0
- package/dataflow/environments/query-fn-props.d.ts +3 -0
- package/dataflow/environments/query-fn-props.js +8 -0
- package/dataflow/environments/resolve-by-name.js +11 -4
- package/dataflow/eval/resolve/resolve-argument.js +5 -1
- package/dataflow/graph/graph.js +12 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +9 -0
- package/dataflow/internal/process/functions/call/named-call-handling.js +60 -8
- package/linter/linter-rules.d.ts +8 -3
- package/linter/rules/function-finder-util.d.ts +1 -1
- package/linter/rules/function-finder-util.js +1 -3
- package/linter/rules/network-functions.d.ts +4 -3
- package/linter/rules/network-functions.js +14 -12
- package/linter/rules/no-leaked-credentials.d.ts +8 -3
- package/linter/rules/no-leaked-credentials.js +133 -35
- package/linter/rules/problematic-inputs.d.ts +1 -1
- package/linter/rules/problematic-inputs.js +20 -14
- package/linter/rules/unescaped-arguments.d.ts +13 -2
- package/linter/rules/unescaped-arguments.js +100 -12
- package/package.json +1 -1
- package/queries/catalog/call-context-query/call-context-query-executor.js +2 -1
- package/queries/catalog/input-sources-query/input-source-functions.d.ts +6 -4
- package/queries/catalog/input-sources-query/input-source-functions.js +11 -6
- package/queries/catalog/input-sources-query/input-sources-query-executor.js +1 -1
- package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +1 -1
- package/queries/catalog/input-sources-query/input-sources-query-format.js +9 -2
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +12 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.js +227 -29
- package/search/search-executor/search-enrichers.js +5 -3
- package/util/version.js +2 -2
|
@@ -7,6 +7,11 @@ const function_semantics_1 = require("../../../../fn/function-semantics");
|
|
|
7
7
|
const info_1 = require("../../../../info");
|
|
8
8
|
const known_call_handling_1 = require("./known-call-handling");
|
|
9
9
|
const append_1 = require("../../../../environments/append");
|
|
10
|
+
const r_parameter_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
|
|
11
|
+
const r_string_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
12
|
+
const r_expression_list_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
13
|
+
const model_1 = require("../../../../../r-bridge/lang-4.x/ast/model/model");
|
|
14
|
+
const operators_1 = require("../../../../../r-bridge/lang-4.x/ast/model/operators");
|
|
10
15
|
const r_function_call_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
11
16
|
const r_binary_op_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
|
|
12
17
|
const r_symbol_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
@@ -88,6 +93,35 @@ function rewrittenByReplacement(definition, data) {
|
|
|
88
93
|
const node = definition.type === identifier_1.ReferenceType.Unknown && at !== undefined ? data.completeAst.idMap.get(at) : undefined;
|
|
89
94
|
return r_function_call_1.RFunctionCall.is(node) || (r_binary_op_1.RBinaryOp.is(node) && r_function_call_1.RFunctionCall.is(node.lhs));
|
|
90
95
|
}
|
|
96
|
+
const bindingFrames = new WeakMap();
|
|
97
|
+
/** for each name the program binds, the functions binding it (`undefined` for the global frame or a `<<-`) */
|
|
98
|
+
function framesBinding(idMap) {
|
|
99
|
+
let frames = bindingFrames.get(idMap);
|
|
100
|
+
if (frames === undefined) {
|
|
101
|
+
const found = new Map();
|
|
102
|
+
for (const node of idMap.values()) {
|
|
103
|
+
const target = r_binary_op_1.RBinaryOp.is(node) && operators_1.OperatorDatabase[node.operator]?.usedAs === 'assignment' ? (node.operator.startsWith('-') ? node.rhs : node.lhs)
|
|
104
|
+
: r_parameter_1.RParameter.is(node) ? node.name : undefined;
|
|
105
|
+
const name = r_symbol_1.RSymbol.is(target) ? identifier_1.Identifier.getName(target.content) : r_string_1.RString.is(target) ? target.content.str : undefined;
|
|
106
|
+
if (name !== undefined) {
|
|
107
|
+
const global = r_binary_op_1.RBinaryOp.is(node) && (node.operator === '<<-' || node.operator === '->>');
|
|
108
|
+
const frame = global ? undefined : model_1.RNode.findEnclosing(node.info.id, idMap, r_function_definition_1.RFunctionDefinition.is);
|
|
109
|
+
found.set(name, new Set([...found.get(name) ?? [], frame]));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
bindingFrames.set(idMap, frames = found);
|
|
113
|
+
}
|
|
114
|
+
return frames;
|
|
115
|
+
}
|
|
116
|
+
/** whether the program binds `name` in a frame enclosing the function the call is in, which a built-in found there leaves out */
|
|
117
|
+
function mayBeShadowed(name, call, idMap) {
|
|
118
|
+
const frames = framesBinding(idMap).get(name);
|
|
119
|
+
if (frames === undefined || r_expression_list_1.RExpressionList.isImplicit(idMap.get(call))) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const own = model_1.RNode.findEnclosing(call, idMap, r_function_definition_1.RFunctionDefinition.is);
|
|
123
|
+
return frames.has(undefined) || [...model_1.RNode.iterateParents(idMap.get(own), idMap)].some(p => frames.has(p.info.id));
|
|
124
|
+
}
|
|
91
125
|
/**
|
|
92
126
|
* Processes a named function call within the dataflow analysis.
|
|
93
127
|
* For example, `myFunction(arg1, arg2)`, resolves against the environment.
|
|
@@ -95,7 +129,10 @@ function rewrittenByReplacement(definition, data) {
|
|
|
95
129
|
function processNamedCall(name, callArguments, rootId, data) {
|
|
96
130
|
const args = data.pipedArgument?.rootId === rootId ? [data.pipedArgument.argument, ...callArguments] : callArguments;
|
|
97
131
|
const resolved = resolve_helper_1.Resolve.byNameAndType(name.content, data.environment, identifier_1.ReferenceType.Function) ?? [];
|
|
98
|
-
|
|
132
|
+
/* a function body sees its enclosing frames only where it is called, so a built-in there may be shadowed by the program */
|
|
133
|
+
const shadowable = resolved.length > 0 && data.environment.level > 0 && resolved.every(r => r.type === identifier_1.ReferenceType.BuiltInFunction)
|
|
134
|
+
&& mayBeShadowed(identifier_1.Identifier.getName(name.content), rootId, data.completeAst.idMap);
|
|
135
|
+
let defaultProcessor = resolved.length === 0 || shadowable;
|
|
99
136
|
/* a call whose meaning a later pass looks up in its environment has to keep it */
|
|
100
137
|
const keepEnvironment = resolved.some(r => r.type === identifier_1.ReferenceType.BuiltInFunction && r.config?.keepEnvironment === true);
|
|
101
138
|
/* a call marked as built-in only (see below) needs no environment snapshot */
|
|
@@ -126,21 +163,36 @@ function processNamedCall(name, callArguments, rootId, data) {
|
|
|
126
163
|
}
|
|
127
164
|
/* flowR models what a package function does with its arguments, but not which of its options it reads */
|
|
128
165
|
let packageFn = false;
|
|
166
|
+
const alternatives = [];
|
|
167
|
+
const processDefault = () => {
|
|
168
|
+
/* if we do not know where we land, we force! reuse `resolved`, data.environment did not change above */
|
|
169
|
+
const sig = resolved.length > 0 ? undefined : function_semantics_1.FunctionSemantics.call.signature.every;
|
|
170
|
+
alternatives.push((0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, sig, origin: 'default' }).information);
|
|
171
|
+
};
|
|
172
|
+
/* first, so the arguments keep the promise the shadowing function makes of them, which holds for a forcing built-in, too */
|
|
173
|
+
if (shadowable) {
|
|
174
|
+
processDefault();
|
|
175
|
+
}
|
|
129
176
|
for (const own of toRun) {
|
|
130
|
-
|
|
177
|
+
alternatives.push(own.processor(name, args, rootId, data));
|
|
131
178
|
const pkg = own.name === undefined ? undefined : identifier_1.Identifier.getNamespace(own.name);
|
|
132
179
|
/* unless flowR states how it accesses the state, as for `withr::with_options` */
|
|
133
180
|
packageFn ||= pkg !== undefined && !(own.config !== undefined && ('ambient' in own.config || 'scope' in own.config)) && !(0, r_base_packages_1.isBaseRPackage)(String(pkg));
|
|
134
181
|
}
|
|
135
|
-
if (defaultProcessor) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
information = mergeInformation(information,
|
|
182
|
+
if (defaultProcessor && !shadowable) {
|
|
183
|
+
processDefault();
|
|
184
|
+
}
|
|
185
|
+
for (const alternative of alternatives) {
|
|
186
|
+
information = mergeInformation(information, alternative);
|
|
140
187
|
}
|
|
141
|
-
|
|
188
|
+
if (!defaultProcessor && information && builtIn) {
|
|
142
189
|
markAsOnlyBuiltIn(information.graph, rootId, keepEnvironment);
|
|
143
190
|
}
|
|
191
|
+
/* an exit only some of the possible callees take is not certain */
|
|
192
|
+
if (information !== undefined && alternatives.length > 1) {
|
|
193
|
+
const inAll = (e) => alternatives.every(a => a.exitPoints.some(o => o.nodeId === e.nodeId && o.type === e.type));
|
|
194
|
+
information = { ...information, exitPoints: information.exitPoints.map(e => inAll(e) ? e : { ...e, cds: (0, info_1.withCds)(e.cds, [{ id: rootId, when: true }]) }) };
|
|
195
|
+
}
|
|
144
196
|
/* a function whose body we do not see may read any option or draw on the device */
|
|
145
197
|
if (information !== undefined && (unknownBody || packageFn)) {
|
|
146
198
|
/* a function handed in as a parameter may be anything, `runif` included, and a function handed a function may call it;
|
package/linter/linter-rules.d.ts
CHANGED
|
@@ -241,7 +241,7 @@ export declare const LintingRules: {
|
|
|
241
241
|
};
|
|
242
242
|
};
|
|
243
243
|
readonly 'problematic-inputs': {
|
|
244
|
-
readonly createSearch: (
|
|
244
|
+
readonly createSearch: () => import("../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter", "with"], import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, Promise<import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>>;
|
|
245
245
|
readonly processSearchResult: (elements: import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, config: import("./rules/problematic-inputs").ProblematicInputsConfig, data: import("..").ReadonlyFlowrAnalysisProvider<import("..").KnownParser>) => Promise<{
|
|
246
246
|
results: import("./rules/problematic-inputs").ProblematicInputsResult[];
|
|
247
247
|
}>;
|
|
@@ -357,12 +357,13 @@ export declare const LintingRules: {
|
|
|
357
357
|
};
|
|
358
358
|
readonly info: {
|
|
359
359
|
readonly name: "No Leaked Credentials";
|
|
360
|
-
readonly description: "Detects hardcoded credentials assigned to variables whose names suggest they hold passwords, tokens, or API keys, or whose values match known credential formats (AWS, GitHub, Slack, Stripe, SSH).";
|
|
360
|
+
readonly description: "Detects hardcoded credentials assigned to variables or passed as arguments whose names suggest they hold passwords, tokens, or API keys, handed to authentication functions, or whose values match known credential formats (AWS, GitHub, Slack, Stripe, Google, JWT, SSH, URLs with passwords).";
|
|
361
361
|
readonly tags: readonly [import("./linter-tags").LintingRuleTag.Security, import("./linter-tags").LintingRuleTag.Experimental, import("./linter-tags").LintingRuleTag.Smell];
|
|
362
362
|
readonly certainty: import("./linter-format").LintingRuleCertainty.BestEffort;
|
|
363
363
|
readonly defaultConfig: () => {
|
|
364
364
|
credentialNamePattern: string;
|
|
365
365
|
credentialValuePattern: string;
|
|
366
|
+
credentialCallPattern: string;
|
|
366
367
|
};
|
|
367
368
|
};
|
|
368
369
|
};
|
|
@@ -490,7 +491,7 @@ export declare const LintingRules: {
|
|
|
490
491
|
};
|
|
491
492
|
};
|
|
492
493
|
eval: {
|
|
493
|
-
criticalCalls: import("..").SemanticCallTag.Eval;
|
|
494
|
+
criticalCalls: (import("..").SemanticCallTag.Eval | import("..").CallProp)[];
|
|
494
495
|
criticalArgs: import("..").ArgProp;
|
|
495
496
|
sanitizers: import("..").Identifier[];
|
|
496
497
|
};
|
|
@@ -520,6 +521,10 @@ export declare const LintingRules: {
|
|
|
520
521
|
call: import("..").Identifier;
|
|
521
522
|
partsOnly: true;
|
|
522
523
|
};
|
|
524
|
+
methods: {
|
|
525
|
+
receiver: import("..").Identifier;
|
|
526
|
+
method: string;
|
|
527
|
+
}[];
|
|
523
528
|
};
|
|
524
529
|
};
|
|
525
530
|
disabledCategories: never[];
|
|
@@ -31,7 +31,7 @@ export declare const functionFinderUtil: {
|
|
|
31
31
|
query: (result: FunctionsResult) => string;
|
|
32
32
|
full: (result: FunctionsResult) => string;
|
|
33
33
|
};
|
|
34
|
-
requireArgumentValue(element: FlowrSearchElement<ParentInformation>, pool: ReadonlyMap<string, FunctionInfo>, analyzer: ReadonlyFlowrAnalysisProvider, requireValue: RegExp | string | undefined): Promise<Ternary>;
|
|
34
|
+
requireArgumentValue(element: FlowrSearchElement<ParentInformation>, pool: ReadonlyMap<string, FunctionInfo>, analyzer: ReadonlyFlowrAnalysisProvider, requireValue: RegExp | string | undefined, identifier: Identifier | undefined): Promise<Ternary>;
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
37
|
* Test if a function call has an argument with a specific value
|
|
@@ -14,7 +14,6 @@ const vertex_1 = require("../../dataflow/graph/vertex");
|
|
|
14
14
|
const dependencies_query_format_1 = require("../../queries/catalog/dependencies-query/dependencies-query-format");
|
|
15
15
|
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
16
16
|
const logic_1 = require("../../util/logic");
|
|
17
|
-
const df_helper_1 = require("../../dataflow/graph/df-helper");
|
|
18
17
|
/**
|
|
19
18
|
* This helper object collects utility functions used to create linting rules that search for specific functions.
|
|
20
19
|
*/
|
|
@@ -66,9 +65,8 @@ exports.functionFinderUtil = {
|
|
|
66
65
|
[linter_format_1.LintingPrettyPrintContext.Full]: (result) => `Function \`${result.function}\` called at ${range_1.SourceLocation.format(result.loc)} is related to ${functionType}`
|
|
67
66
|
};
|
|
68
67
|
},
|
|
69
|
-
async requireArgumentValue(element, pool, analyzer, requireValue) {
|
|
68
|
+
async requireArgumentValue(element, pool, analyzer, requireValue, identifier) {
|
|
70
69
|
const dataflow = await analyzer.dataflow();
|
|
71
|
-
const identifier = df_helper_1.Dataflow.qualify(element.node.info.id, dataflow.graph, true) ?? (element.node.lexeme !== undefined ? identifier_1.Identifier.parse(element.node.lexeme) : undefined);
|
|
72
70
|
/* if we have no additional info, we assume they always access the network */
|
|
73
71
|
if (identifier === undefined || requireValue === undefined) {
|
|
74
72
|
return logic_1.Ternary.Always;
|
|
@@ -31,9 +31,10 @@ export interface NetworkFunction extends MergeableRecord {
|
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Every built-in that may reach the network, read back from the {@link DefaultBuiltinConfig}: the ones labeled
|
|
34
|
-
* {@link SemanticCallTag.Network} always do
|
|
35
|
-
*
|
|
36
|
-
* built-in `Network` or give it a resource
|
|
34
|
+
* {@link SemanticCallTag.Network} always do unless they may open a local {@link SemanticCallTag.File} instead,
|
|
35
|
+
* and any call naming an {@link ArgProp.Resource} does whenever that resource is a url rather than a path --
|
|
36
|
+
* which is what {@link UrlPattern} decides per call site. Label a built-in `Network` or give it a resource
|
|
37
|
+
* parameter and it shows up here; nothing is listed twice.
|
|
37
38
|
*/
|
|
38
39
|
export declare function networkFunctions(index: BuiltInIndex): NetworkFunction[];
|
|
39
40
|
export declare const NETWORK_FUNCTIONS: {
|
|
@@ -10,13 +10,13 @@ const logic_1 = require("../../util/logic");
|
|
|
10
10
|
const source_functions_1 = require("../../queries/catalog/dependencies-query/function-info/source-functions");
|
|
11
11
|
const write_functions_1 = require("../../queries/catalog/dependencies-query/function-info/write-functions");
|
|
12
12
|
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
13
|
-
const
|
|
13
|
+
const search_enrichers_1 = require("../../search/search-executor/search-enrichers");
|
|
14
14
|
const built_in_props_1 = require("../../dataflow/environments/built-in-props");
|
|
15
15
|
/**
|
|
16
16
|
* What an address looks like when one is written down. A call is only a network operation for the argument it
|
|
17
17
|
* is actually handed, so this is what decides that per call site rather than the name alone.
|
|
18
18
|
*/
|
|
19
|
-
const UrlPattern = /^(https?|ftps?):\/\//;
|
|
19
|
+
const UrlPattern = /^(https?|ftps?|sftp|scp|wss?):\/\//;
|
|
20
20
|
/** the parameter names that mean "the address", preferred over any other resource the same call names */
|
|
21
21
|
const AddressNames = new Set(['url', 'urls', 'uri', 'href', 'link', 'address', 'repo', 'repo_spec', 'pull']);
|
|
22
22
|
/**
|
|
@@ -29,16 +29,17 @@ function addressParam(params) {
|
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Every built-in that may reach the network, read back from the {@link DefaultBuiltinConfig}: the ones labeled
|
|
32
|
-
* {@link SemanticCallTag.Network} always do
|
|
33
|
-
*
|
|
34
|
-
* built-in `Network` or give it a resource
|
|
32
|
+
* {@link SemanticCallTag.Network} always do unless they may open a local {@link SemanticCallTag.File} instead,
|
|
33
|
+
* and any call naming an {@link ArgProp.Resource} does whenever that resource is a url rather than a path --
|
|
34
|
+
* which is what {@link UrlPattern} decides per call site. Label a built-in `Network` or give it a resource
|
|
35
|
+
* parameter and it shows up here; nothing is listed twice.
|
|
35
36
|
*/
|
|
36
37
|
function networkFunctions(index) {
|
|
37
38
|
const resources = new Map();
|
|
38
39
|
for (const param of index.params(built_in_props_1.ArgProp.Resource)) {
|
|
39
|
-
/* R opens a path it writes to as a local file (or a `|` pipe), never as a url */
|
|
40
|
+
/* R opens a path it writes to as a local file (or a `|` pipe), never as a url, and a command is no address either */
|
|
40
41
|
const tags = index.get(param.call)?.tags;
|
|
41
|
-
if (tags?.includes(built_in_props_1.SemanticCallTag.Writes) && !tags.includes(built_in_props_1.SemanticCallTag.Reads)) {
|
|
42
|
+
if ((tags?.includes(built_in_props_1.SemanticCallTag.Writes) && !tags.includes(built_in_props_1.SemanticCallTag.Reads)) || tags?.includes(built_in_props_1.SemanticCallTag.Process)) {
|
|
42
43
|
continue;
|
|
43
44
|
}
|
|
44
45
|
const key = identifier_1.Identifier.toString(param.call);
|
|
@@ -53,17 +54,17 @@ function networkFunctions(index) {
|
|
|
53
54
|
return [...names].map(([key, name]) => {
|
|
54
55
|
const params = resources.get(key);
|
|
55
56
|
const address = params === undefined ? undefined : addressParam(params);
|
|
57
|
+
const tags = index.get(name)?.tags;
|
|
56
58
|
return {
|
|
57
59
|
name,
|
|
58
60
|
...(address === undefined ? {} : { info: { argIdx: address.index, argName: address.name, resolveValue: true } }),
|
|
59
|
-
onlyTriggerWithArgument: UrlPattern
|
|
61
|
+
...(tags?.includes(built_in_props_1.SemanticCallTag.Network) && !tags.includes(built_in_props_1.SemanticCallTag.File) ? {} : { onlyTriggerWithArgument: UrlPattern })
|
|
60
62
|
};
|
|
61
63
|
});
|
|
62
64
|
}
|
|
63
65
|
exports.NETWORK_FUNCTIONS = {
|
|
64
66
|
createSearch: config => function_finder_util_1.functionFinderUtil.createSearch(config.fns.map(f => identifier_1.Identifier.is(f) ? f : f.name)),
|
|
65
67
|
processSearchResult: async (e, c, d) => {
|
|
66
|
-
const df = await d.dataflow();
|
|
67
68
|
const fnPool = new Map([
|
|
68
69
|
...(0, write_functions_1.writeFunctions)(d.inspectContext()).concat((0, read_functions_1.readFunctions)(d.inspectContext()), source_functions_1.SourceFunctions).map(f => [identifier_1.Identifier.toString(identifier_1.Identifier.make(f.name, f.package)), f]),
|
|
69
70
|
...c.fns.flatMap(f => identifier_1.Identifier.is(f) ? [] : f.info === undefined ? [] : [identifier_1.Identifier.getName(f.name), identifier_1.Identifier.toString(f.name)].map(key => [key, { name: identifier_1.Identifier.toString(f.name), ...f.info }]))
|
|
@@ -73,13 +74,14 @@ exports.NETWORK_FUNCTIONS = {
|
|
|
73
74
|
return function_finder_util_1.functionFinderUtil.processSearchResult(e, c, d, async (es) => {
|
|
74
75
|
const res = [];
|
|
75
76
|
for (const e of es) {
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
77
|
+
const target = (0, search_enrichers_1.enrichmentContent)(e, search_enrichers_1.Enrichment.CallTargets).targets.find(t => typeof t === 'string');
|
|
78
|
+
if (target === undefined) {
|
|
78
79
|
continue;
|
|
79
80
|
}
|
|
81
|
+
const identifier = identifier_1.Identifier.parse(target);
|
|
80
82
|
// we allow onlyTriggerLookup to contain non-namespaced functions
|
|
81
83
|
const requireValue = onlyTriggerLookup.get(identifier_1.Identifier.toString(identifier)) ?? onlyTriggerLookup.get(identifier_1.Identifier.getName(identifier));
|
|
82
|
-
const val = await function_finder_util_1.functionFinderUtil.requireArgumentValue(e, fnPool, d, requireValue);
|
|
84
|
+
const val = await function_finder_util_1.functionFinderUtil.requireArgumentValue(e, fnPool, d, requireValue, identifier);
|
|
83
85
|
if (val === logic_1.Ternary.Never) {
|
|
84
86
|
continue;
|
|
85
87
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type LintingResult, LintingRuleCertainty } from '../linter-format';
|
|
2
2
|
import type { MergeableRecord } from '../../util/objects';
|
|
3
3
|
import { LintingRuleTag } from '../linter-tags';
|
|
4
|
+
import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
4
5
|
export interface NoLeakedCredentialsResult extends LintingResult {
|
|
5
6
|
readonly variableName: string;
|
|
6
7
|
}
|
|
@@ -9,13 +10,16 @@ export interface NoLeakedCredentialsConfig extends MergeableRecord {
|
|
|
9
10
|
readonly credentialNamePattern: string;
|
|
10
11
|
/** Pattern matched against string literal values to detect known credential formats (e.g., AWS access key IDs, GitHub tokens) */
|
|
11
12
|
readonly credentialValuePattern: string;
|
|
13
|
+
/** Pattern matched (case-insensitively) against function names whose unnamed arguments are credentials, like `httr::authenticate` */
|
|
14
|
+
readonly credentialCallPattern: string;
|
|
12
15
|
}
|
|
13
16
|
export interface NoLeakedCredentialsMetadata extends MergeableRecord {
|
|
17
|
+
/** the number of string literals checked */
|
|
14
18
|
readonly totalChecked: number;
|
|
15
19
|
}
|
|
16
20
|
export declare const NO_LEAKED_CREDENTIALS: {
|
|
17
|
-
readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"],
|
|
18
|
-
readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<
|
|
21
|
+
readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"], ParentInformation, Promise<import("../../search/flowr-search").FlowrSearchElements<ParentInformation, [] | import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>>>;
|
|
22
|
+
readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>, config: NoLeakedCredentialsConfig, data: import("../..").ReadonlyFlowrAnalysisProvider<import("../..").KnownParser>) => Promise<{
|
|
19
23
|
results: NoLeakedCredentialsResult[];
|
|
20
24
|
".meta": NoLeakedCredentialsMetadata;
|
|
21
25
|
}>;
|
|
@@ -25,12 +29,13 @@ export declare const NO_LEAKED_CREDENTIALS: {
|
|
|
25
29
|
};
|
|
26
30
|
readonly info: {
|
|
27
31
|
readonly name: "No Leaked Credentials";
|
|
28
|
-
readonly description: "Detects hardcoded credentials assigned to variables whose names suggest they hold passwords, tokens, or API keys, or whose values match known credential formats (AWS, GitHub, Slack, Stripe, SSH).";
|
|
32
|
+
readonly description: "Detects hardcoded credentials assigned to variables or passed as arguments whose names suggest they hold passwords, tokens, or API keys, handed to authentication functions, or whose values match known credential formats (AWS, GitHub, Slack, Stripe, Google, JWT, SSH, URLs with passwords).";
|
|
29
33
|
readonly tags: readonly [LintingRuleTag.Security, LintingRuleTag.Experimental, LintingRuleTag.Smell];
|
|
30
34
|
readonly certainty: LintingRuleCertainty.BestEffort;
|
|
31
35
|
readonly defaultConfig: () => {
|
|
32
36
|
credentialNamePattern: string;
|
|
33
37
|
credentialValuePattern: string;
|
|
38
|
+
credentialCallPattern: string;
|
|
34
39
|
};
|
|
35
40
|
};
|
|
36
41
|
};
|
|
@@ -7,51 +7,148 @@ const range_1 = require("../../util/range");
|
|
|
7
7
|
const linter_tags_1 = require("../linter-tags");
|
|
8
8
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
9
9
|
const edge_1 = require("../../dataflow/graph/edge");
|
|
10
|
+
const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
|
|
11
|
+
const r_access_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-access");
|
|
12
|
+
const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
13
|
+
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
14
|
+
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
10
15
|
const frame_reflection_1 = require("../../dataflow/fn/frame-reflection");
|
|
16
|
+
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
11
17
|
const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
12
|
-
const defaultCredentialNamePattern = '(?:
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
18
|
+
const defaultCredentialNamePattern = '(?:passw(?:or)?d|authorization|passphrase|(?:^|[_.])pass(?:$|[_.])|pwd|secret|api[_.]?key|access[_.]?key|(?:^|[_.])token$|api[_.]?token|access[_.]?token|auth[_.]?token|bearer[_.]?token|private[_.]?key|credential|(?:^|[_.])pat$)';
|
|
19
|
+
const defaultCredentialCallPattern = '(?:auth|login|signin|credential|password|secret|token|key_?set)';
|
|
20
|
+
const defaultCredentialValuePattern = '(?:(?<![A-Za-z0-9_])|(?<=\\\\[nrt]))(?:' +
|
|
21
|
+
'(?:AKIA|AIPA|ASIA|AROA)[A-Z0-9]{16}' + // AWS access key IDs (exact 20-char format)
|
|
22
|
+
'|gh[psoar]_[A-Za-z0-9_]{10,}' + // GitHub Classic/App/OAuth/Actions tokens
|
|
23
|
+
'|github_pat_[A-Za-z0-9_]{10,}' + // GitHub fine-grained PATs
|
|
24
|
+
'|glpat-[A-Za-z0-9_-]{20}' + // GitLab Personal Access Tokens (fixed length)
|
|
25
|
+
'|xox[baprs]-[0-9A-Za-z]{10,}' + // Slack tokens (xoxb-, xoxp-, xoxa-, xoxr-, xoxs-)
|
|
26
|
+
'|sk_(?:live|test)_[A-Za-z0-9]{24}' + // Stripe secret/test keys (length-anchored)
|
|
27
|
+
'|rk_live_[A-Za-z0-9]{24}' + // Stripe restricted keys (length-anchored)
|
|
28
|
+
'|npm_[A-Za-z0-9]{36}' + // npm access tokens (fixed length)
|
|
29
|
+
'|shp(?:at|ss|pa|ca)_[A-Za-z0-9]{32}' + // Shopify Admin/Shared/Private/Custom tokens
|
|
30
|
+
'|sk-ant-[A-Za-z0-9_-]{10,}' + // Anthropic API keys
|
|
31
|
+
'|sk-(?:proj-)?[A-Za-z0-9_-]{20,}' + // OpenAI API keys
|
|
32
|
+
'|SG\\.[A-Za-z0-9_-]{22}\\.' + // SendGrid API keys (structured format)
|
|
33
|
+
'|AIza[0-9A-Za-z_-]{35}' + // Google API keys
|
|
34
|
+
'|hf_[A-Za-z0-9]{30,}' + // Hugging Face tokens
|
|
35
|
+
'|eyJ[A-Za-z0-9_-]{10,}\\.eyJ[A-Za-z0-9_-]{10,}\\.' + // JSON web tokens
|
|
36
|
+
'|[a-z][a-z0-9+.-]*://[^/\\s:@]+:[^/\\s@]+@' + // URLs with an embedded user and password
|
|
37
|
+
'|-----BEGIN(?:\\s[A-Z]+)* PRIVATE KEY' + // PEM private keys (RSA, EC, DSA, OpenSSH, etc.)
|
|
38
|
+
')';
|
|
39
|
+
/** what a credential-like name holds without leaking anything: a placeholder, or a path or link to look the secret up */
|
|
40
|
+
const NoCredentialValue = /^(?:<[^>]*>|\{\{.*\}\}|\$\{.*\}|your[_ -].*|x+|\*+|\.{3}|changeme|placeholder|dummy|(?:~|\.{0,2})\/.*|[a-z]+:\/\/[^@]*|(?:bearer|basic|token)\s*)$/i;
|
|
41
|
+
/** what a function asking for a credential is handed instead: a prompt, not the secret */
|
|
42
|
+
const PromptValue = /\s|[:?]$/;
|
|
43
|
+
/** names that only describe a credential: the label, prompt, or pattern of a password, the variable or file holding a key */
|
|
44
|
+
const NoCredentialName = /[_.](?:label|prompt|pattern|regex|env|var|file|path|dir|url|name|field|col|msg|message|text|title|hint|length|policy)$/i;
|
|
45
|
+
/** how many assignments a literal is followed through to the name or argument it ends up in */
|
|
46
|
+
const MaxCredentialHops = 3;
|
|
47
|
+
/** the name of a defined variable, with the fields of an access it is written through (`cfg$password`) */
|
|
48
|
+
function definedName(node, idMap) {
|
|
49
|
+
let name = node.lexeme ?? '';
|
|
50
|
+
for (const parent of model_1.RNode.iterateParents(node, idMap)) {
|
|
51
|
+
if (!r_access_1.RAccess.is(parent)) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
for (const arg of parent.access) {
|
|
55
|
+
if (arg !== r_function_call_1.EmptyArgument && arg.value !== undefined) {
|
|
56
|
+
name += '$' + (r_string_1.RString.is(arg.value) ? arg.value.content.str : arg.value.lexeme ?? '');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return name;
|
|
61
|
+
}
|
|
62
|
+
class CredentialContexts {
|
|
63
|
+
dfg;
|
|
64
|
+
idMap;
|
|
65
|
+
callPattern;
|
|
66
|
+
namePattern;
|
|
67
|
+
pure;
|
|
68
|
+
constructor(dfg, idMap, callPattern, namePattern, pure) {
|
|
69
|
+
this.dfg = dfg;
|
|
70
|
+
this.idMap = idMap;
|
|
71
|
+
this.callPattern = callPattern;
|
|
72
|
+
this.namePattern = namePattern;
|
|
73
|
+
this.pure = pure;
|
|
74
|
+
}
|
|
75
|
+
/** the variables, arguments, or credential-taking functions a literal ends up in, followed through up to {@link MaxCredentialHops} uses */
|
|
76
|
+
of(node, hops = 0, seen = new Set()) {
|
|
77
|
+
const found = [];
|
|
78
|
+
let child = node;
|
|
79
|
+
for (const current of [node, ...model_1.RNode.iterateParents(node, this.idMap)]) {
|
|
80
|
+
if (r_function_definition_1.RFunctionDefinition.is(current)) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
const fn = r_function_call_1.RFunctionCall.isNamed(current) ? current.functionName.content : '';
|
|
84
|
+
const name = identifier_1.Identifier.getName(fn);
|
|
85
|
+
/* only a value built from its arguments carries a literal on to where it is assigned, `assign` assigns its own */
|
|
86
|
+
const opaque = r_function_call_1.RFunctionCall.is(current) && r_argument_1.RArgument.is(child) && !this.pure.has(identifier_1.Identifier.getNamespace(fn) === undefined ? name : identifier_1.Identifier.toString(fn));
|
|
87
|
+
for (const def of (0, frame_reflection_1.edgeSources)(this.dfg, current.info.id, edge_1.EdgeType.DefinedBy)) {
|
|
88
|
+
const defNode = this.idMap.get(def);
|
|
89
|
+
if (defNode !== undefined && vertex_1.DfgVertex.isVariableDefinition(this.dfg.getVertex(def)) && !seen.has(def) && (!opaque || model_1.RNode.iterateParents(defNode, this.idMap).some(p => p === current))) {
|
|
90
|
+
seen.add(def);
|
|
91
|
+
found.push({ name: definedName(defNode, this.idMap), anchor: defNode }, ...this.usesOf(def, hops, seen));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (r_argument_1.RArgument.isNamed(current) && current !== node) {
|
|
95
|
+
found.push({ name: current.name.lexeme, anchor: current.name });
|
|
96
|
+
return found;
|
|
97
|
+
}
|
|
98
|
+
else if (r_function_call_1.RFunctionCall.is(current) && child === current.arguments.findLast(a => a !== r_function_call_1.EmptyArgument && a.name === undefined) && this.callPattern.test(name)
|
|
99
|
+
/* a secret handed by name (`key_set_with_value(service, password = ...)`) leaves the unnamed ones to say what it is for */
|
|
100
|
+
&& !current.arguments.some(a => a !== r_function_call_1.EmptyArgument && a.name !== undefined && this.namePattern.test(a.name.lexeme))) {
|
|
101
|
+
found.push({ name, anchor: current, handedTo: true });
|
|
102
|
+
}
|
|
103
|
+
if (opaque) {
|
|
104
|
+
return found;
|
|
105
|
+
}
|
|
106
|
+
child = current;
|
|
107
|
+
}
|
|
108
|
+
return found;
|
|
109
|
+
}
|
|
110
|
+
usesOf(def, hops, seen) {
|
|
111
|
+
return hops >= MaxCredentialHops ? [] : (0, frame_reflection_1.edgeSources)(this.dfg, def, edge_1.EdgeType.Reads).flatMap(r => {
|
|
112
|
+
const reader = this.idMap.get(r);
|
|
113
|
+
return reader === undefined ? [] : this.of(reader, hops + 1, seen);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
26
117
|
exports.NO_LEAKED_CREDENTIALS = {
|
|
27
|
-
createSearch: () => flowr_search_builder_1.Q.all().filter(vertex_1.VertexType.
|
|
118
|
+
createSearch: () => flowr_search_builder_1.Q.all().filter(vertex_1.VertexType.Value),
|
|
28
119
|
processSearchResult: async (elements, config, data) => {
|
|
29
120
|
const namePattern = new RegExp(config.credentialNamePattern, 'i');
|
|
30
121
|
const valuePattern = new RegExp(config.credentialValuePattern);
|
|
31
122
|
const normalize = await data.normalize();
|
|
32
123
|
const dfg = (await data.dataflow()).graph;
|
|
124
|
+
const contexts = new CredentialContexts(dfg, normalize.idMap, new RegExp(config.credentialCallPattern, 'i'), namePattern, new Set(data.inspectContext().env.builtInIndex.pure.flatMap(p => [identifier_1.Identifier.getName(p), identifier_1.Identifier.toString(p)])));
|
|
33
125
|
let totalChecked = 0;
|
|
34
|
-
const results =
|
|
126
|
+
const results = new Map();
|
|
127
|
+
for (const element of elements.getElements()) {
|
|
128
|
+
const node = element.node;
|
|
129
|
+
if (!r_string_1.RString.is(node)) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
35
132
|
totalChecked++;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return [];
|
|
133
|
+
if (vertex_1.DfgVertex.isVariableDefinition(dfg.getVertex(node.info.id))) {
|
|
134
|
+
continue;
|
|
39
135
|
}
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
/* a credential-like name only leaks a
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
136
|
+
const value = node.content.str;
|
|
137
|
+
const named = contexts.of(node);
|
|
138
|
+
/* a credential-like name only leaks a real value, a credential-like value leaks under any name */
|
|
139
|
+
const leaking = valuePattern.test(value) ? named[0] ?? { name: '', anchor: node }
|
|
140
|
+
: value === '' || NoCredentialValue.test(value) ? undefined
|
|
141
|
+
: named.find(c => c.handedTo ? !PromptValue.test(value) : namePattern.test(c.name) && !NoCredentialName.test(c.name));
|
|
142
|
+
if (leaking !== undefined && !results.has(leaking.anchor.info.id)) {
|
|
143
|
+
results.set(leaking.anchor.info.id, {
|
|
48
144
|
certainty: linter_format_1.LintingResultCertainty.Uncertain,
|
|
49
|
-
involvedId: id,
|
|
50
|
-
variableName: name,
|
|
51
|
-
loc: range_1.SourceLocation.fromNode(
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
145
|
+
involvedId: leaking.anchor.info.id,
|
|
146
|
+
variableName: leaking.name,
|
|
147
|
+
loc: range_1.SourceLocation.fromNode(leaking.anchor) ?? range_1.SourceLocation.invalid()
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { results: [...results.values()], '.meta': { totalChecked } };
|
|
55
152
|
},
|
|
56
153
|
prettyPrint: {
|
|
57
154
|
[linter_format_1.LintingPrettyPrintContext.Query]: (result) => `Possible hardcoded credential in \`${result.variableName}\` at ${range_1.SourceLocation.format(result.loc)}`,
|
|
@@ -59,12 +156,13 @@ exports.NO_LEAKED_CREDENTIALS = {
|
|
|
59
156
|
},
|
|
60
157
|
info: {
|
|
61
158
|
name: 'No Leaked Credentials',
|
|
62
|
-
description: 'Detects hardcoded credentials assigned to variables whose names suggest they hold passwords, tokens, or API keys, or whose values match known credential formats (AWS, GitHub, Slack, Stripe, SSH).',
|
|
159
|
+
description: 'Detects hardcoded credentials assigned to variables or passed as arguments whose names suggest they hold passwords, tokens, or API keys, handed to authentication functions, or whose values match known credential formats (AWS, GitHub, Slack, Stripe, Google, JWT, SSH, URLs with passwords).',
|
|
63
160
|
tags: [linter_tags_1.LintingRuleTag.Security, linter_tags_1.LintingRuleTag.Experimental, linter_tags_1.LintingRuleTag.Smell],
|
|
64
161
|
certainty: linter_format_1.LintingRuleCertainty.BestEffort,
|
|
65
162
|
defaultConfig: () => ({
|
|
66
163
|
credentialNamePattern: defaultCredentialNamePattern,
|
|
67
|
-
credentialValuePattern: defaultCredentialValuePattern
|
|
164
|
+
credentialValuePattern: defaultCredentialValuePattern,
|
|
165
|
+
credentialCallPattern: defaultCredentialCallPattern
|
|
68
166
|
})
|
|
69
167
|
}
|
|
70
168
|
};
|
|
@@ -19,7 +19,7 @@ export interface ProblematicInputsConfig extends MergeableRecord {
|
|
|
19
19
|
pipeCommandFunctions?: PipeCommandFunctionSpec | readonly PipeCommandFunctionSpec[];
|
|
20
20
|
}
|
|
21
21
|
export declare const PROBLEMATIC_INPUTS: {
|
|
22
|
-
readonly createSearch: (
|
|
22
|
+
readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter", "with"], import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, Promise<import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>>;
|
|
23
23
|
readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, config: ProblematicInputsConfig, data: import("../..").ReadonlyFlowrAnalysisProvider<import("../..").KnownParser>) => Promise<{
|
|
24
24
|
results: ProblematicInputsResult[];
|
|
25
25
|
}>;
|
|
@@ -10,15 +10,21 @@ const simple_input_classifier_1 = require("../../queries/catalog/input-sources-q
|
|
|
10
10
|
const parse_1 = require("../../slicing/criterion/parse");
|
|
11
11
|
const graph_1 = require("../../dataflow/graph/graph");
|
|
12
12
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
13
|
+
const df_helper_1 = require("../../dataflow/graph/df-helper");
|
|
14
|
+
const search_enrichers_1 = require("../../search/search-executor/search-enrichers");
|
|
13
15
|
const built_in_props_1 = require("../../dataflow/environments/built-in-props");
|
|
14
16
|
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
17
|
+
const query_fn_props_1 = require("../../dataflow/environments/query-fn-props");
|
|
15
18
|
const resolve_argument_1 = require("../../dataflow/eval/resolve/resolve-argument");
|
|
19
|
+
/** what runs a command, and what evaluates code beyond looking up a name (`get`) or calling a function it is handed (`do.call`) */
|
|
16
20
|
function defaultConsider(index) {
|
|
17
|
-
|
|
21
|
+
const evaluates = index.with(built_in_props_1.SemanticCallTag.Eval).filter(n => ((index.propsOf(n) ?? 0) & built_in_props_1.CallProp.Pure) === 0 && !index.get(n)?.sig?.some(([, p]) => (p & built_in_props_1.ArgProp.Callee) !== 0));
|
|
22
|
+
return [...index.with(built_in_props_1.SemanticCallTag.Process), ...evaluates].map(n => `^${identifier_1.Identifier.quote(identifier_1.Identifier.getName(n))}$`).concat('^fread$');
|
|
18
23
|
}
|
|
19
24
|
const defaultPipeCommandFunctions = [
|
|
20
25
|
{ pattern: '^pdf$', argIdx: 0, argName: 'file' },
|
|
21
|
-
{ pattern: '^postscript$', argIdx: 0, argName: 'file' }
|
|
26
|
+
{ pattern: '^postscript$', argIdx: 0, argName: 'file' },
|
|
27
|
+
{ pattern: '^bitmap$', argIdx: 0, argName: 'file' }
|
|
22
28
|
];
|
|
23
29
|
function normalizePatternList(cfg = []) {
|
|
24
30
|
return (0, arrays_1.isArray)(cfg) ? Array.from(new Set(cfg), s => new RegExp(s)) : [new RegExp(cfg)];
|
|
@@ -61,18 +67,12 @@ function resolveFileArgId(graph, vertex, argIdx, argName, ctx) {
|
|
|
61
67
|
return arg === undefined ? undefined : graph_1.FunctionArgument.getReference(arg);
|
|
62
68
|
}
|
|
63
69
|
exports.PROBLEMATIC_INPUTS = {
|
|
64
|
-
createSearch:
|
|
65
|
-
const toQ = (name, subkind) => ({ type: 'call-context', callName: name, callNameExact: false, subkind });
|
|
66
|
-
return flowr_search_builder_1.Q.fromQuery([
|
|
67
|
-
...normalizePatternList(config.consider).map((n, i) => toQ(n, `fn-${i}`)),
|
|
68
|
-
...normalizePipeSpecs(config.pipeCommandFunctions).map((s, i) => toQ(s.pattern, `pipe-${i}`))
|
|
69
|
-
]);
|
|
70
|
-
},
|
|
70
|
+
createSearch: () => flowr_search_builder_1.Q.all().filter(vertex_1.VertexType.FunctionCall).with(search_enrichers_1.Enrichment.CallTargets),
|
|
71
71
|
processSearchResult: async (elements, config, data) => {
|
|
72
72
|
const df = await data.dataflow();
|
|
73
73
|
const results = [];
|
|
74
74
|
const seen = new Set();
|
|
75
|
-
const defaultAccept = [simple_input_classifier_1.InputType.Constant, simple_input_classifier_1.InputType.DerivedConstant];
|
|
75
|
+
const defaultAccept = [simple_input_classifier_1.InputType.Constant, simple_input_classifier_1.InputType.DerivedConstant, simple_input_classifier_1.InputType.TempFile];
|
|
76
76
|
const considerPats = normalizePatternList(config.consider);
|
|
77
77
|
const pipePats = normalizePipeSpecs(config.pipeCommandFunctions);
|
|
78
78
|
for (const element of elements.getElements()) {
|
|
@@ -80,7 +80,11 @@ exports.PROBLEMATIC_INPUTS = {
|
|
|
80
80
|
if (seen.has(nid)) {
|
|
81
81
|
continue;
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
if (df_helper_1.Dataflow.isQuoted(nid, df.graph) && !(0, query_fn_props_1.quotedForWorker)(nid, df.graph, data.inspectContext().env.builtInIndex)) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const names = (0, search_enrichers_1.enrichmentContent)(element, search_enrichers_1.Enrichment.CallTargets).targets.flatMap(t => typeof t === 'string' ? [identifier_1.Identifier.getName(identifier_1.Identifier.parse(t))] : []);
|
|
87
|
+
const name = names.find(n => pipePats.some(s => s.pattern.test(n)) || considerPats.some(p => p.test(n))) ?? '';
|
|
84
88
|
const pipeSpec = pipePats.find(s => s.pattern.test(name));
|
|
85
89
|
/* a pipe spec checks the file argument of the call, a considered call the call itself */
|
|
86
90
|
let target;
|
|
@@ -93,9 +97,11 @@ exports.PROBLEMATIC_INPUTS = {
|
|
|
93
97
|
if (target === undefined) {
|
|
94
98
|
continue;
|
|
95
99
|
}
|
|
96
|
-
const criterion = parse_1.SlicingCriterion.fromId(target);
|
|
97
|
-
const
|
|
98
|
-
const
|
|
100
|
+
const [criterion, call] = [parse_1.SlicingCriterion.fromId(target), parse_1.SlicingCriterion.fromId(nid)];
|
|
101
|
+
const res = (await data.query([{ type: 'input-sources', criterion: target === nid ? call : [criterion, call], config: config.inputFns }]))['input-sources']?.results;
|
|
102
|
+
const own = res?.[criterion] ?? [];
|
|
103
|
+
/* a file argument that is an input itself (`pdf(readline())`) only shows as a source of the call */
|
|
104
|
+
const sources = target === nid || own.some(s => s.id === target) ? own : own.concat((res?.[call] ?? []).filter(s => s.id === target));
|
|
99
105
|
const pipeCommand = pipeSpec === undefined ? undefined : getPipeCommandValue(sources);
|
|
100
106
|
if (pipeCommand !== undefined || isProblematicForAllowed(sources, defaultAccept)) {
|
|
101
107
|
seen.add(nid);
|