@eagleoutice/flowr 2.16.0 → 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/README.md +9 -9
- package/cli/flowr-main-options.d.ts +15 -0
- package/cli/flowr-main-options.js +18 -0
- package/cli/flowr.d.ts +18 -0
- package/cli/flowr.js +13 -2
- package/cli/repl/commands/repl-clipboard.js +2 -1
- package/cli/repl/commands/repl-commands.js +2 -0
- package/cli/repl/commands/repl-main.d.ts +5 -0
- package/cli/repl/commands/repl-signature.js +2 -0
- package/cli/repl/core.d.ts +7 -1
- package/cli/repl/core.js +17 -8
- package/cli/repl/execute.js +2 -0
- package/cli/repl/server/connection.js +2 -1
- package/cli/repl/server/net.d.ts +10 -0
- package/cli/repl/server/net.js +34 -1
- package/cli/slicer-app.js +2 -1
- package/config.d.ts +12 -2
- package/config.js +91 -14
- 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/extractor.js +14 -5
- package/dataflow/fn/frame-reflection.js +14 -2
- package/dataflow/graph/graph.js +12 -0
- package/dataflow/internal/control-flow.d.ts +11 -0
- package/dataflow/internal/control-flow.js +15 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +4 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +9 -0
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +8 -7
- package/dataflow/internal/process/functions/call/deferred.js +6 -1
- package/dataflow/internal/process/functions/call/named-call-handling.js +70 -9
- package/documentation/doc-capabilities.js +4 -1
- package/documentation/wiki-interface.js +4 -0
- package/engines.js +11 -3
- package/linter/linter-executor.js +19 -1
- package/linter/linter-rules.d.ts +8 -3
- package/linter/rules/file-path-validity.js +4 -1
- 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/seeded-randomness.js +3 -1
- package/linter/rules/unescaped-arguments.d.ts +13 -2
- package/linter/rules/unescaped-arguments.js +100 -12
- package/package.json +1 -1
- package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +14 -5
- package/project/plugins/file-plugins/files/flowr-rda-file.js +35 -24
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +2 -1
- package/project/sigdb/decompress.js +3 -1
- package/project/sigdb/sigdb-download.js +9 -6
- package/queries/catalog/call-context-query/call-context-query-executor.js +2 -1
- package/queries/catalog/config-query/config-query-executor.js +9 -2
- 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/r-bridge/shell-executor.js +2 -0
- package/r-bridge/shell.js +2 -0
- package/search/search-executor/search-enrichers.js +5 -3
- package/slicing/static/static-slicer.js +14 -9
- package/util/files.d.ts +6 -0
- package/util/files.js +12 -0
- package/util/parallel.js +2 -0
- package/util/secure-mode.d.ts +42 -0
- package/util/secure-mode.js +70 -0
- package/util/version.js +2 -2
|
@@ -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);
|
|
@@ -80,6 +80,8 @@ exports.SEEDED_RANDOMNESS = {
|
|
|
80
80
|
const loops = graph.getVertex(reader)?.cds?.filter(cd => info_1.ControlDependency.isIterated(cd, idMap)) ?? [];
|
|
81
81
|
return loops.some(loop => writerCds?.some(cd => info_1.ControlDependency.same(cd, loop)));
|
|
82
82
|
};
|
|
83
|
+
/** a call of a draw by another name, like a parameter `f` bound to `runif` */
|
|
84
|
+
const drawsThrough = (call) => (0, frame_reflection_1.edgeTargets)(graph, call, edge_1.EdgeType.Calls).some(t => node_id_1.NodeId.isBuiltIn(t) && consumers.has(node_id_1.NodeId.fromBuiltIn(t))) ? 'draw' : undefined;
|
|
83
85
|
/** the writes a draw reads the generator state from: its own, and those of the calls running the function it sits in, which link what was written before them */
|
|
84
86
|
const statesReadBy = (id) => {
|
|
85
87
|
const within = idMap === undefined ? undefined : model_1.RNode.findEnclosing(id, idMap, r_function_definition_1.RFunctionDefinition.is);
|
|
@@ -95,7 +97,7 @@ exports.SEEDED_RANDOMNESS = {
|
|
|
95
97
|
let always = false;
|
|
96
98
|
for (const target of statesReadBy(id)) {
|
|
97
99
|
const writer = graph.getVertex(target);
|
|
98
|
-
const kind = vertex_1.DfgVertex.isFunctionCall(writer) && !visiting.has(target) ? writerKind(writer) : undefined;
|
|
100
|
+
const kind = vertex_1.DfgVertex.isFunctionCall(writer) && !visiting.has(target) ? writerKind(writer) ?? drawsThrough(target) : undefined;
|
|
99
101
|
if (kind === undefined) {
|
|
100
102
|
continue;
|
|
101
103
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArgProps, PropSelector } from '../../dataflow/environments/built-in-props';
|
|
2
|
-
import { ArgProp, SemanticCallTag } from '../../dataflow/environments/built-in-props';
|
|
2
|
+
import { ArgProp, CallProp, SemanticCallTag } from '../../dataflow/environments/built-in-props';
|
|
3
3
|
import { Identifier } from '../../dataflow/environments/identifier';
|
|
4
4
|
import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
|
|
5
5
|
import type { InputSources } from '../../queries/catalog/input-sources-query/simple-input-classifier';
|
|
@@ -45,6 +45,13 @@ interface UnescapedArgumentsEntry {
|
|
|
45
45
|
* @see {@link EscapeQuickFix}
|
|
46
46
|
*/
|
|
47
47
|
readonly quickFix?: EscapeQuickFix;
|
|
48
|
+
/** Methods whose unnamed arguments are critical, called on an object by `$` */
|
|
49
|
+
readonly methods?: readonly CriticalMethod[];
|
|
50
|
+
}
|
|
51
|
+
/** A method `obj$method(...)` of an object that is either the named one (`htmltools::tags`) or made by the named constructor (`V8::v8()`) */
|
|
52
|
+
export interface CriticalMethod extends MergeableRecord {
|
|
53
|
+
readonly receiver: Identifier;
|
|
54
|
+
readonly method: string;
|
|
48
55
|
}
|
|
49
56
|
/** A quick fix to escape an unescaped expression */
|
|
50
57
|
export interface EscapeQuickFix extends MergeableRecord {
|
|
@@ -120,7 +127,7 @@ export declare const UNESCAPED_ARGUMENTS: {
|
|
|
120
127
|
};
|
|
121
128
|
};
|
|
122
129
|
eval: {
|
|
123
|
-
criticalCalls: SemanticCallTag.Eval;
|
|
130
|
+
criticalCalls: (SemanticCallTag.Eval | CallProp)[];
|
|
124
131
|
criticalArgs: ArgProp;
|
|
125
132
|
sanitizers: Identifier[];
|
|
126
133
|
};
|
|
@@ -150,6 +157,10 @@ export declare const UNESCAPED_ARGUMENTS: {
|
|
|
150
157
|
call: Identifier;
|
|
151
158
|
partsOnly: true;
|
|
152
159
|
};
|
|
160
|
+
methods: {
|
|
161
|
+
receiver: Identifier;
|
|
162
|
+
method: string;
|
|
163
|
+
}[];
|
|
153
164
|
};
|
|
154
165
|
};
|
|
155
166
|
disabledCategories: never[];
|