@eagleoutice/flowr 2.16.8 → 2.17.0

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 (94) hide show
  1. package/README.md +16 -10
  2. package/abstract-interpretation/absint-inference.d.ts +17 -1
  3. package/abstract-interpretation/absint-inference.js +118 -3
  4. package/abstract-interpretation/data-frame/arguments.d.ts +11 -1
  5. package/abstract-interpretation/data-frame/arguments.js +12 -0
  6. package/abstract-interpretation/domains/lattice.d.ts +2 -0
  7. package/abstract-interpretation/domains/lattice.js +0 -6
  8. package/abstract-interpretation/domains/multi-value-state-domain.d.ts +2 -1
  9. package/abstract-interpretation/domains/multi-value-state-domain.js +7 -3
  10. package/abstract-interpretation/domains/partial-product-domain.js +2 -1
  11. package/abstract-interpretation/domains/state-abstract-domain.d.ts +6 -3
  12. package/abstract-interpretation/domains/state-abstract-domain.js +13 -7
  13. package/abstract-interpretation/domains/state-domain.d.ts +4 -0
  14. package/config.js +1 -1
  15. package/control-flow/useless-loop.js +10 -8
  16. package/data/r-primitives.generated.d.ts +1 -0
  17. package/data/r-primitives.generated.js +9 -0
  18. package/data/sigdb/sigdb.remote.json +110 -110
  19. package/dataflow/environments/query-fn-props.d.ts +9 -3
  20. package/dataflow/environments/query-fn-props.js +13 -5
  21. package/dataflow/fn/class-declaration.js +1 -8
  22. package/dataflow/graph/df-helper.d.ts +2 -0
  23. package/dataflow/graph/df-helper.js +7 -0
  24. package/documentation/wiki-linter.js +29 -0
  25. package/documentation/wiki-query.js +20 -1
  26. package/linter/linter-executor.js +2 -1
  27. package/linter/linter-rules.d.ts +65 -0
  28. package/linter/linter-rules.js +5 -1
  29. package/linter/rules/cmd-check/global-environment-modification.d.ts +14 -1
  30. package/linter/rules/cmd-check/global-environment-modification.js +15 -7
  31. package/linter/rules/no-leaked-credentials.d.ts +1 -0
  32. package/linter/rules/no-leaked-credentials.js +3 -3
  33. package/linter/rules/process-state-in-session.d.ts +71 -0
  34. package/linter/rules/process-state-in-session.js +267 -0
  35. package/linter/rules/secret-exfiltration.d.ts +80 -0
  36. package/linter/rules/secret-exfiltration.js +183 -0
  37. package/package.json +1 -1
  38. package/project/flowr-analyzer.d.ts +6 -0
  39. package/project/flowr-analyzer.js +4 -0
  40. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +2 -0
  41. package/project/plugins/file-plugins/files/flowr-namespace-file.js +22 -3
  42. package/project/sigdb/decompress.d.ts +4 -0
  43. package/project/sigdb/decompress.js +60 -25
  44. package/project/sigdb/manifest.d.ts +1 -1
  45. package/project/sigdb/manifest.js +2 -5
  46. package/project/sigdb/reader.js +15 -6
  47. package/project/sigdb/sigdb-download.d.ts +3 -7
  48. package/project/sigdb/sigdb-download.js +71 -72
  49. package/queries/catalog/taint-query/taint-query-executor.d.ts +7 -0
  50. package/queries/catalog/taint-query/taint-query-executor.js +30 -0
  51. package/queries/catalog/taint-query/taint-query-format.d.ts +29 -0
  52. package/queries/catalog/taint-query/taint-query-format.js +124 -0
  53. package/queries/query.d.ts +12 -1
  54. package/queries/query.js +2 -0
  55. package/taint-analysis/builder/domain.d.ts +14 -0
  56. package/taint-analysis/builder/domain.js +69 -0
  57. package/taint-analysis/builder/report-template.d.ts +50 -0
  58. package/taint-analysis/builder/report-template.js +46 -0
  59. package/taint-analysis/builder/taint-analysis-definition.d.ts +108 -0
  60. package/taint-analysis/builder/taint-analysis-definition.js +128 -0
  61. package/taint-analysis/builder/taint-analysis.d.ts +124 -0
  62. package/taint-analysis/builder/taint-analysis.js +93 -0
  63. package/taint-analysis/builtin-index-bridge.d.ts +20 -0
  64. package/taint-analysis/builtin-index-bridge.js +48 -0
  65. package/taint-analysis/eval/eval.d.ts +1 -0
  66. package/taint-analysis/eval/eval.js +124 -0
  67. package/taint-analysis/eval/instrumentation.d.ts +59 -0
  68. package/taint-analysis/eval/instrumentation.js +124 -0
  69. package/taint-analysis/finite-domain.d.ts +41 -0
  70. package/taint-analysis/finite-domain.js +118 -0
  71. package/taint-analysis/function-categories.d.ts +31 -0
  72. package/taint-analysis/function-categories.js +61 -0
  73. package/taint-analysis/logger.d.ts +1 -0
  74. package/taint-analysis/logger.js +6 -0
  75. package/taint-analysis/predefined/determinism.d.ts +6 -0
  76. package/taint-analysis/predefined/determinism.js +14 -0
  77. package/taint-analysis/predefined/normalization.d.ts +17 -0
  78. package/taint-analysis/predefined/normalization.js +150 -0
  79. package/taint-analysis/predefined/predefined.d.ts +12 -0
  80. package/taint-analysis/predefined/predefined.js +18 -0
  81. package/taint-analysis/predefined/randomness-analysis.d.ts +6 -0
  82. package/taint-analysis/predefined/randomness-analysis.js +124 -0
  83. package/taint-analysis/predefined/secret-analysis.d.ts +77 -0
  84. package/taint-analysis/predefined/secret-analysis.js +165 -0
  85. package/taint-analysis/predefined/security-analysis.d.ts +7 -0
  86. package/taint-analysis/predefined/security-analysis.js +91 -0
  87. package/taint-analysis/taint-mapping.d.ts +86 -0
  88. package/taint-analysis/taint-mapping.js +70 -0
  89. package/taint-analysis/taint-resolve.d.ts +26 -0
  90. package/taint-analysis/taint-resolve.js +86 -0
  91. package/taint-analysis/taint-visitor.d.ts +80 -0
  92. package/taint-analysis/taint-visitor.js +82 -0
  93. package/util/flowr-version.d.ts +1 -1
  94. package/util/flowr-version.js +2 -2
@@ -2,6 +2,7 @@ import { type LintingResult, LintingRuleCertainty } from '../linter-format';
2
2
  import type { MergeableRecord } from '../../util/objects';
3
3
  import { LintingRuleTag } from '../linter-tags';
4
4
  import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
+ export declare const defaultCredentialValuePattern: string;
5
6
  export interface NoLeakedCredentialsResult extends LintingResult {
6
7
  readonly variableName: string;
7
8
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NO_LEAKED_CREDENTIALS = void 0;
3
+ exports.NO_LEAKED_CREDENTIALS = exports.defaultCredentialValuePattern = void 0;
4
4
  const linter_format_1 = require("../linter-format");
5
5
  const flowr_search_builder_1 = require("../../search/flowr-search-builder");
6
6
  const range_1 = require("../../util/range");
@@ -17,7 +17,7 @@ const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
17
17
  const df_helper_1 = require("../../dataflow/graph/df-helper");
18
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
19
  const defaultCredentialCallPattern = '(?:auth|login|signin|credential|password|secret|token|key_?set)';
20
- const defaultCredentialValuePattern = '(?:(?<![A-Za-z0-9_])|(?<=\\\\[nrt]))(?:' +
20
+ exports.defaultCredentialValuePattern = '(?:(?<![A-Za-z0-9_])|(?<=\\\\[nrt]))(?:' +
21
21
  '(?:AKIA|AIPA|ASIA|AROA)[A-Z0-9]{16}' + // AWS access key IDs (exact 20-char format)
22
22
  '|gh[psoar]_[A-Za-z0-9_]{10,}' + // GitHub Classic/App/OAuth/Actions tokens
23
23
  '|github_pat_[A-Za-z0-9_]{10,}' + // GitHub fine-grained PATs
@@ -158,7 +158,7 @@ exports.NO_LEAKED_CREDENTIALS = {
158
158
  certainty: linter_format_1.LintingRuleCertainty.BestEffort,
159
159
  defaultConfig: () => ({
160
160
  credentialNamePattern: defaultCredentialNamePattern,
161
- credentialValuePattern: defaultCredentialValuePattern,
161
+ credentialValuePattern: exports.defaultCredentialValuePattern,
162
162
  credentialCallPattern: defaultCredentialCallPattern
163
163
  })
164
164
  }
@@ -0,0 +1,71 @@
1
+ import { type LintingResult, LintingRuleCertainty } from '../linter-format';
2
+ import type { MergeableRecord } from '../../util/objects';
3
+ import { LintingRuleTag } from '../linter-tags';
4
+ import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
+ /** Ways per-session code changes process-wide state: `<<-` and `assign` to globals, `assignInNamespace`, setters like `options`, top-level reactive values, cache keys missing session values, and `addResourcePath` */
6
+ export declare enum ProcessStateChange {
7
+ GlobalSuperAssignment = "global-superassignment",
8
+ GlobalAssign = "global-assign",
9
+ NamespacePatch = "namespace-patch",
10
+ ProcessSetting = "process-setting",
11
+ SharedState = "shared-state",
12
+ CacheKey = "cache-key",
13
+ ResourcePath = "resource-path"
14
+ }
15
+ export interface ProcessStateInSessionResult extends LintingResult {
16
+ readonly change: ProcessStateChange;
17
+ /** the function or variable changing the state */
18
+ readonly name: string;
19
+ /** what to use instead */
20
+ readonly suggestion: string;
21
+ }
22
+ export interface ProcessStateInSessionConfig extends MergeableRecord {
23
+ /** parameter lists marking a session function (Shiny server or module), all of one must be present */
24
+ readonly sessionSignatures: readonly (readonly string[])[];
25
+ /** process-wide setters, with what to use instead */
26
+ readonly settings: Readonly<Record<string, string>>;
27
+ /** functions creating state, shared when called at the top level */
28
+ readonly sharedState: readonly string[];
29
+ /** cache constructors */
30
+ readonly caches: readonly string[];
31
+ /** memoisers */
32
+ readonly memoisers: readonly string[];
33
+ }
34
+ export interface ProcessStateInSessionMetadata extends MergeableRecord {
35
+ /** functions run per session */
36
+ readonly sessionFunctions: number;
37
+ }
38
+ export declare const PROCESS_STATE_IN_SESSION: {
39
+ readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"from", [], ParentInformation, import("../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>>;
40
+ readonly processSearchResult: (_elements: import("../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>, config: ProcessStateInSessionConfig, data: import("../..").ReadonlyFlowrAnalysisProvider<import("../..").KnownParser>) => Promise<{
41
+ results: ProcessStateInSessionResult[];
42
+ '.meta': {
43
+ sessionFunctions: number;
44
+ };
45
+ }>;
46
+ readonly prettyPrint: {
47
+ readonly query: (r: ProcessStateInSessionResult, metadata: unknown) => string;
48
+ readonly full: (r: ProcessStateInSessionResult, metadata: unknown) => string;
49
+ };
50
+ readonly info: {
51
+ readonly name: "Process State in Session";
52
+ readonly tags: readonly [LintingRuleTag.Bug, LintingRuleTag.Security, LintingRuleTag.Shiny];
53
+ readonly certainty: LintingRuleCertainty.BestEffort;
54
+ readonly description: "Finds per-session Shiny code changing state all sessions share: globals, options, environment variables, the working directory, namespaces, top-level reactive values, shared caches (memoise, bindCache, cachem) whose key misses session values, and resource paths.";
55
+ readonly defaultConfig: () => {
56
+ sessionSignatures: string[][];
57
+ settings: {
58
+ options: string;
59
+ 'Sys.setenv': string;
60
+ 'Sys.unsetenv': string;
61
+ setwd: string;
62
+ 'Sys.setlocale': string;
63
+ 'set.seed': string;
64
+ 'Sys.umask': string;
65
+ };
66
+ sharedState: string[];
67
+ caches: string[];
68
+ memoisers: string[];
69
+ };
70
+ };
71
+ };
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROCESS_STATE_IN_SESSION = exports.ProcessStateChange = void 0;
4
+ const linter_format_1 = require("../linter-format");
5
+ const flowr_search_builder_1 = require("../../search/flowr-search-builder");
6
+ const range_1 = require("../../util/range");
7
+ const linter_tags_1 = require("../linter-tags");
8
+ const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
9
+ const r_binary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
10
+ const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
11
+ const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
12
+ const r_access_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-access");
13
+ const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
14
+ const r_expression_list_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
15
+ const r_parameter_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
16
+ const r_pipe_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-pipe");
17
+ const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
18
+ const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
19
+ const vertex_1 = require("../../dataflow/graph/vertex");
20
+ const edge_1 = require("../../dataflow/graph/edge");
21
+ const df_helper_1 = require("../../dataflow/graph/df-helper");
22
+ const identifier_1 = require("../../dataflow/environments/identifier");
23
+ const linter_util_1 = require("../linter-util");
24
+ const function_semantics_1 = require("../../dataflow/fn/function-semantics");
25
+ const arrays_1 = require("../../util/collections/arrays");
26
+ const linker_1 = require("../../dataflow/internal/linker");
27
+ const cmd_check_util_1 = require("./cmd-check/cmd-check-util");
28
+ const global_environment_modification_1 = require("./cmd-check/global-environment-modification");
29
+ /** Ways per-session code changes process-wide state: `<<-` and `assign` to globals, `assignInNamespace`, setters like `options`, top-level reactive values, cache keys missing session values, and `addResourcePath` */
30
+ var ProcessStateChange;
31
+ (function (ProcessStateChange) {
32
+ ProcessStateChange["GlobalSuperAssignment"] = "global-superassignment";
33
+ ProcessStateChange["GlobalAssign"] = "global-assign";
34
+ ProcessStateChange["NamespacePatch"] = "namespace-patch";
35
+ ProcessStateChange["ProcessSetting"] = "process-setting";
36
+ ProcessStateChange["SharedState"] = "shared-state";
37
+ ProcessStateChange["CacheKey"] = "cache-key";
38
+ ProcessStateChange["ResourcePath"] = "resource-path";
39
+ })(ProcessStateChange || (exports.ProcessStateChange = ProcessStateChange = {}));
40
+ const SessionLocal = 'session$userData or a value created within the server function';
41
+ /** the functions reading what a setter changes */
42
+ const SettingReaders = { 'options': ['getOption', 'options'], 'Sys.setenv': ['Sys.getenv'], 'Sys.unsetenv': ['Sys.getenv'], 'setwd': ['getwd'], 'Sys.setlocale': ['Sys.getlocale'] };
43
+ const MagrittrPipe = new Set(['%>%']);
44
+ const parentOf = (model_1.RNode.directParent);
45
+ const argValue = (r_argument_1.RArgument.valueOf);
46
+ const argumentValue = (call, name) => argValue(r_argument_1.RArgument.findNamed(call.arguments, name));
47
+ /** the value a plain assignment binds to the definition `def` */
48
+ const assigned = (def, graph, idMap) => idMap.get(df_helper_1.Dataflow.assignedValueOf(def, graph) ?? '');
49
+ const references = (node, graph) => [node.info.id, ...df_helper_1.Dataflow.targetsOf(graph, node.info.id, edge_1.EdgeType.Reads)];
50
+ const extendsPath = (path, prefix) => path.startsWith(prefix) && (path.length === prefix.length || '$('.includes(path[prefix.length]));
51
+ /** whether the call is undone when its function exits, as in `op <- options(x = 1); on.exit(options(op))` */
52
+ function restoredOnExit(call, name, idMap) {
53
+ const fn = idMap.get(model_1.RNode.strictlyEnclosingFunction(call.info.id, idMap) ?? -1);
54
+ let restored = false;
55
+ model_1.RNode.visitAst(r_function_definition_1.RFunctionDefinition.is(fn) ? fn.body : undefined, n => {
56
+ if (r_function_call_1.RFunctionCall.isNamed(n, 'on.exit')) {
57
+ model_1.RNode.visitAst(n, inner => {
58
+ restored ||= r_function_call_1.RFunctionCall.isNamed(inner, name);
59
+ });
60
+ }
61
+ return restored || r_function_definition_1.RFunctionDefinition.is(n);
62
+ });
63
+ return restored;
64
+ }
65
+ /** variables bound at the top level to a call of `creators`, by id */
66
+ function topLevelOf(nodes, idMap, creators) {
67
+ return new Map(nodes.flatMap(n => r_binary_op_1.RBinaryOp.is(n) && ['<-', '='].includes(n.operator) && r_symbol_1.RSymbol.is(n.lhs) && r_function_call_1.RFunctionCall.isNamed(n.rhs, new Set(creators))
68
+ && model_1.RNode.strictlyEnclosingFunction(n.info.id, idMap) === undefined ? [[n.lhs.info.id, identifier_1.Identifier.getName(n.lhs.content)]] : []));
69
+ }
70
+ const fieldName = (access) => access.access.length === 1 ? (0, linker_1.accessedFieldName)(argValue(access.access[0]), r_access_1.RAccess.isNamed(access)) : undefined;
71
+ /** the path a symbol is read by, e.g., `session$user$name` or `rv()` */
72
+ function readPath(symbol, idMap) {
73
+ let path = identifier_1.Identifier.getName(symbol.content);
74
+ for (let cur = symbol, parent = parentOf(cur, idMap); parent !== undefined; cur = parent, parent = parentOf(cur, idMap)) {
75
+ const field = r_access_1.RAccess.is(parent) && parent.accessed === cur ? fieldName(parent) : undefined;
76
+ const read = r_function_call_1.RFunctionCall.isNamed(parent) && parent.functionName === cur && parent.arguments.length === 0;
77
+ if (field === undefined && !read) {
78
+ break;
79
+ }
80
+ path += field === undefined ? '()' : `$${field}`;
81
+ }
82
+ return path;
83
+ }
84
+ /** session values (parameters, reactive state, globals and settings a session writes) an expression reads, as paths; definitions are followed */
85
+ function sessionDependence(graph, idMap, sessions, stateCreators, writtenGlobals, changedSettings) {
86
+ const inSession = (id) => sessions.some(s => (0, cmd_check_util_1.isWithin)(id, s, idMap));
87
+ const isSessionValue = (def) => {
88
+ const node = idMap.get(def);
89
+ const param = r_parameter_1.RParameter.is(node) ? node : node && parentOf(node, idMap);
90
+ return r_parameter_1.RParameter.is(param) ? sessions.includes(param.info.parent ?? -1) : inSession(def) && r_function_call_1.RFunctionCall.isNamed(assigned(def, graph, idMap), stateCreators);
91
+ };
92
+ /* reads without a resolved definition (reactives and function bodies run later) use the definitions in scope */
93
+ const byName = df_helper_1.Dataflow.definitionsByName(graph);
94
+ const inScope = (symbol) => byName.get(identifier_1.Identifier.getName(symbol.content)).filter(d => {
95
+ const scope = model_1.RNode.strictlyEnclosingFunction(d, idMap);
96
+ return scope === undefined || (0, cmd_check_util_1.isWithin)(symbol.info.id, scope, idMap);
97
+ });
98
+ const expanded = new Map();
99
+ const ofDefinition = (def) => {
100
+ if (!expanded.has(def)) {
101
+ expanded.set(def, new Set());
102
+ expanded.set(def, of(assigned(def, graph, idMap)));
103
+ }
104
+ return expanded.get(def) ?? new Set();
105
+ };
106
+ const of = (root) => {
107
+ const paths = new Set();
108
+ model_1.RNode.visitAst(root, n => {
109
+ const parent = parentOf(n, idMap);
110
+ if (!r_symbol_1.RSymbol.is(n) || vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(n.info.id)) || (r_argument_1.RArgument.is(parent) && r_access_1.RAccess.isNamed(parentOf(parent, idMap)))) {
111
+ return;
112
+ }
113
+ const reader = r_function_call_1.RFunctionCall.isNamed(parent) && parent.functionName === n ? parent : n;
114
+ const read = df_helper_1.Dataflow.targetsOf(graph, reader.info.id, edge_1.EdgeType.Reads);
115
+ const defs = read.length > 0 ? read : inScope(n);
116
+ const name = identifier_1.Identifier.getName(n.content);
117
+ if (writtenGlobals.has(name) || (reader !== n && changedSettings.has(name)) || defs.some(isSessionValue)) {
118
+ paths.add(readPath(n, idMap));
119
+ }
120
+ else {
121
+ defs.forEach(d => ofDefinition(d).forEach(p => paths.add(p)));
122
+ }
123
+ });
124
+ return paths;
125
+ };
126
+ return {
127
+ inSession,
128
+ /** session values `value` depends on that `key` misses */
129
+ missing: (value, key) => {
130
+ const keyPaths = key.flatMap(k => [...of(k)]);
131
+ return (0, arrays_1.uniqueArray)(value.flatMap(v => [...of(v)])).filter(p => !keyPaths.some(k => extendsPath(p, k) || extendsPath(k, p)));
132
+ }
133
+ };
134
+ }
135
+ /** whether a cache argument names a shared cache, calls create fresh ones unless a function returns a shared one */
136
+ function sharedCache(arg, graph, idMap, inSession, absent) {
137
+ if (arg === undefined || r_string_1.RString.is(arg)) {
138
+ return arg === undefined ? absent : arg.content.str !== 'session';
139
+ }
140
+ else if (r_function_call_1.RFunctionCall.isNamed(arg)) {
141
+ return (0, cmd_check_util_1.calledDefinitions)(graph, arg.info.id, idMap).some(fn => sharedCache(r_expression_list_1.RExpressionList.is(fn.body) ? fn.body.children.at(-1) : fn.body, graph, idMap, inSession, false));
142
+ }
143
+ const defs = df_helper_1.Dataflow.targetsOf(graph, arg.info.id, edge_1.EdgeType.Reads);
144
+ return r_symbol_1.RSymbol.is(arg) && (defs.length === 0 || defs.some(d => !inSession(d)));
145
+ }
146
+ /** the expression `bindCache` caches when it is piped into it */
147
+ function pipedInto(call, idMap) {
148
+ const parent = parentOf(call, idMap);
149
+ const outer = r_argument_1.RArgument.is(parent) ? parentOf(parent, idMap) : undefined;
150
+ return r_pipe_1.RPipe.is(parent) ? parent.rhs === call ? parent.lhs : undefined
151
+ : r_function_call_1.RFunctionCall.isNamed(outer, MagrittrPipe) && argValue(outer.arguments[1]) === call ? argValue(outer.arguments[0]) : undefined;
152
+ }
153
+ /** a write to a shared cache: by `bindCache`, a function a memoiser wraps, or `$set` of a cache */
154
+ function cacheWrite(node, graph, idMap, inSession, caches, memoisers) {
155
+ if (r_function_call_1.RFunctionCall.isNamed(node, new Set(['bindCache']))) {
156
+ const args = node.arguments.filter(a => a === r_function_call_1.EmptyArgument || a.name?.content !== 'cache').map(argValue);
157
+ const piped = pipedInto(node, idMap);
158
+ return sharedCache(argumentValue(node, 'cache'), graph, idMap, inSession, true) ? { name: 'bindCache', value: [piped ?? args[0]], key: piped === undefined ? args.slice(1) : args, fix: 'bindCache keys that include %s, or cache = "session"' } : undefined;
159
+ }
160
+ else if (r_function_call_1.RFunctionCall.isNamed(node)) {
161
+ const direct = r_function_call_1.RFunctionCall.isNamed(node, new Set(['memoizedCall']));
162
+ const memo = direct ? node : df_helper_1.Dataflow.targetsOf(graph, node.info.id, edge_1.EdgeType.Reads).map(d => assigned(d, graph, idMap)).find(v => r_function_call_1.RFunctionCall.isNamed(v, memoisers));
163
+ if (!r_function_call_1.RFunctionCall.is(memo) || (!direct && inSession(memo.info.id) && !sharedCache(argumentValue(memo, 'cache'), graph, idMap, inSession, false))) {
164
+ return undefined;
165
+ }
166
+ const wrapped = argValue(memo.arguments[0]);
167
+ const fn = r_symbol_1.RSymbol.is(wrapped) ? df_helper_1.Dataflow.targetsOf(graph, wrapped.info.id, edge_1.EdgeType.Reads).map(d => assigned(d, graph, idMap)).find(r_function_definition_1.RFunctionDefinition.is) : wrapped;
168
+ const args = direct ? memo.arguments.slice(1) : node.arguments;
169
+ const omitted = new Set();
170
+ model_1.RNode.visitAst(argumentValue(memo, 'omit_args'), n => {
171
+ if (r_string_1.RString.is(n)) {
172
+ omitted.add(n.content.str);
173
+ }
174
+ });
175
+ const left = [...function_semantics_1.FunctionSemantics.call.match.toNames(args, r_function_definition_1.RFunctionDefinition.is(fn) ? (0, cmd_check_util_1.formalNames)(fn) : [])].filter(([p]) => omitted.has(p)).map(([, a]) => a);
176
+ return {
177
+ name: identifier_1.Identifier.getName(node.functionName.content),
178
+ value: [r_function_definition_1.RFunctionDefinition.is(fn) ? fn.body : undefined, ...left.map(a => a.value)],
179
+ key: args.filter(a => a === r_function_call_1.EmptyArgument || !left.includes(a)).map(argValue),
180
+ fix: `arguments to ${identifier_1.Identifier.getName(node.functionName.content)} that include %s, or a cache per session`
181
+ };
182
+ }
183
+ const called = r_function_call_1.RFunctionCall.is(node) ? node.calledFunction : undefined;
184
+ const cache = r_access_1.RAccess.isNamed(called) && fieldName(called) === 'set' ? references(called.accessed, graph).map(d => caches.get(d)).find(n => n !== undefined) : undefined;
185
+ return cache === undefined || !r_function_call_1.RFunctionCall.is(node) ? undefined : { name: cache, value: [argValue(node.arguments[1])], key: [argValue(node.arguments[0])], fix: 'a key that includes %s, or a cache per session' };
186
+ }
187
+ exports.PROCESS_STATE_IN_SESSION = {
188
+ createSearch: () => flowr_search_builder_1.Q.from([]),
189
+ processSearchResult: async (_elements, config, data) => {
190
+ const df = await data.dataflow();
191
+ const ast = await data.normalize();
192
+ const idMap = ast.idMap;
193
+ const nodes = (0, cmd_check_util_1.projectNodes)(ast);
194
+ const sessions = nodes.filter(n => r_function_definition_1.RFunctionDefinition.is(n) && config.sessionSignatures.some(sig => sig.every(p => (0, cmd_check_util_1.formalNames)(n).includes(p)))).map(n => n.info.id);
195
+ const inSession = (node) => sessions.some(s => (0, cmd_check_util_1.isWithin)(node.info.id, s, idMap));
196
+ const shared = topLevelOf(nodes, idMap, config.sharedState);
197
+ const scopes = new Map();
198
+ const results = [];
199
+ const add = (node, change, name, suggestion) => results.push({ ...(0, linter_util_1.at)(node), change, name, suggestion });
200
+ for (const [id, vertex] of df.graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
201
+ const node = idMap.get(id);
202
+ const fn = identifier_1.Identifier.getName((0, linter_util_1.builtInOf)(df.graph, id) ?? '');
203
+ if (fn === 'addResourcePath' && node !== undefined) {
204
+ add(node, ProcessStateChange.ResourcePath, fn, 'serve the files from the www directory of the app, or check that every client may see the directory');
205
+ }
206
+ if (!r_function_call_1.RFunctionCall.is(node) || !inSession(node)) {
207
+ continue;
208
+ }
209
+ const global = fn === 'assign' ? (0, global_environment_modification_1.globalAssignment)(vertex, df, idMap, data.inspectContext()) : undefined;
210
+ if (config.settings[fn] !== undefined && node.arguments.length > 0 && !restoredOnExit(node, fn, idMap)) {
211
+ add(node, ProcessStateChange.ProcessSetting, fn, config.settings[fn]);
212
+ }
213
+ else if (fn === 'assignInNamespace' || fn === 'assignInMyNamespace') {
214
+ add(node, ProcessStateChange.NamespacePatch, fn, 'pass the changed behavior as an argument instead of patching the namespace');
215
+ }
216
+ else if (global !== undefined) {
217
+ add(node, ProcessStateChange.GlobalAssign, global.variable ?? fn, SessionLocal);
218
+ }
219
+ }
220
+ for (const node of nodes.filter(inSession)) {
221
+ const symbol = r_binary_op_1.RBinaryOp.is(node) && ['<-', '=', '<<-'].includes(node.operator) && r_access_1.RAccess.is(node.lhs) ? node.lhs.accessed : r_function_call_1.RFunctionCall.isNamed(node) && node.arguments.length > 0 ? node : undefined;
222
+ const variable = symbol && references(symbol, df.graph).map(d => shared.get(d)).find(n => n !== undefined);
223
+ const target = r_binary_op_1.RBinaryOp.is(node) && (node.operator === '<<-' || node.operator === '->>') ? (0, global_environment_modification_1.targetVariable)(node.operator === '->>' ? node.rhs : node.lhs) : undefined;
224
+ if (variable !== undefined) {
225
+ add(node, ProcessStateChange.SharedState, variable, `create '${variable}' within the server function, or key it by the session`);
226
+ }
227
+ else if (target !== undefined && (0, global_environment_modification_1.superAssignmentTarget)(node, target, idMap, new Set(), scopes) === 'global') {
228
+ add(node, ProcessStateChange.GlobalSuperAssignment, target, SessionLocal);
229
+ }
230
+ }
231
+ const writtenGlobals = new Set(results.filter(r => r.change === ProcessStateChange.GlobalSuperAssignment || r.change === ProcessStateChange.GlobalAssign).map(r => r.name));
232
+ const changedSettings = new Set(results.filter(r => r.change === ProcessStateChange.ProcessSetting).flatMap(r => SettingReaders[r.name] ?? []));
233
+ const dependence = sessionDependence(df.graph, idMap, sessions, new Set(config.sharedState), writtenGlobals, changedSettings);
234
+ const caches = topLevelOf(nodes, idMap, config.caches);
235
+ for (const node of nodes.filter(inSession)) {
236
+ const write = cacheWrite(node, df.graph, idMap, dependence.inSession, caches, new Set(config.memoisers));
237
+ const missing = write === undefined ? [] : dependence.missing(write.value, write.key);
238
+ if (write !== undefined && missing.length > 0) {
239
+ add(node, ProcessStateChange.CacheKey, write.name, write.fix.replace('%s', missing.join(', ')));
240
+ }
241
+ }
242
+ return { results: results.toSorted((a, b) => range_1.SourceLocation.compare(a.loc, b.loc)), '.meta': { sessionFunctions: sessions.length } };
243
+ },
244
+ prettyPrint: (0, linter_format_1.prettyPrint)(result => `${result.change} by ${result.name} at ${range_1.SourceLocation.format(result.loc)}`, result => `${result.name} changes the state all sessions share (${result.change}) at ${range_1.SourceLocation.format(result.loc)}; instead, use ${result.suggestion}`),
245
+ info: {
246
+ name: 'Process State in Session',
247
+ tags: [linter_tags_1.LintingRuleTag.Bug, linter_tags_1.LintingRuleTag.Security, linter_tags_1.LintingRuleTag.Shiny],
248
+ certainty: linter_format_1.LintingRuleCertainty.BestEffort,
249
+ description: 'Finds per-session Shiny code changing state all sessions share: globals, options, environment variables, the working directory, namespaces, top-level reactive values, shared caches (memoise, bindCache, cachem) whose key misses session values, and resource paths.',
250
+ defaultConfig: () => ({
251
+ sessionSignatures: [['input', 'output']],
252
+ settings: {
253
+ 'options': 'withr::with_options or withr::local_options',
254
+ 'Sys.setenv': 'withr::with_envvar or withr::local_envvar',
255
+ 'Sys.unsetenv': 'withr::with_envvar or withr::local_envvar',
256
+ 'setwd': 'absolute paths, or withr::with_dir',
257
+ 'Sys.setlocale': 'withr::with_locale',
258
+ 'set.seed': 'withr::with_seed',
259
+ 'Sys.umask': 'withr::with_umask'
260
+ },
261
+ sharedState: ['reactiveValues', 'reactiveVal'],
262
+ caches: ['cache_mem', 'cache_disk', 'cache_layered'],
263
+ memoisers: ['memoise', 'memoize', 'addMemoization']
264
+ })
265
+ }
266
+ };
267
+ //# sourceMappingURL=process-state-in-session.js.map
@@ -0,0 +1,80 @@
1
+ import { type LintingResult, LintingRuleCertainty } from '../linter-format';
2
+ import type { MergeableRecord } from '../../util/objects';
3
+ import { LintingRuleTag } from '../linter-tags';
4
+ import { Identifier } from '../../dataflow/environments/identifier';
5
+ import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
6
+ import { InputType } from '../../queries/catalog/input-sources-query/input-types';
7
+ import { FileTrust, type SecretSink, SecretSinkClass } from '../../taint-analysis/predefined/secret-analysis';
8
+ /** How a secret leaves the process, see {@link Leaks} */
9
+ export declare enum SecretLeak {
10
+ Exfiltration = "exfiltration",
11
+ Leakage = "leakage",
12
+ Url = "url",
13
+ Files = "files",
14
+ Process = "process",
15
+ Llm = "llm"
16
+ }
17
+ export type SecretLeakSeverity = 'high' | 'medium' | 'low';
18
+ export interface SecretExfiltrationResult extends LintingResult {
19
+ readonly function: string;
20
+ readonly sink: SecretSinkClass;
21
+ readonly leak: SecretLeak;
22
+ readonly severity: SecretLeakSeverity;
23
+ }
24
+ export interface SecretExfiltrationConfig extends MergeableRecord {
25
+ /** environment variable names that hold credentials (case-insensitive) */
26
+ readonly credentialNamePattern: string;
27
+ /** literals that are credentials, as in `no-leaked-credentials` */
28
+ readonly credentialValuePattern: string;
29
+ /** extra functions returning secrets */
30
+ readonly sources: readonly Identifier[];
31
+ /** extra functions whose result is never secret */
32
+ readonly declassifiers: readonly Identifier[];
33
+ /** where secrets leave the process */
34
+ readonly sinks: readonly SecretSink[];
35
+ /** low-severity leaks to report */
36
+ readonly optIn: readonly SecretLeak[];
37
+ /** input types that make a destination untrusted, including files (see `fileTrust` for what they hold) */
38
+ readonly controlledInputs: readonly InputType[];
39
+ /** how far the content of files is trusted not to hold secrets; untrusted content gives uncertain results */
40
+ readonly fileTrust: FileTrust;
41
+ /** paths of files holding secrets, in addition to credential files like `.Renviron` */
42
+ readonly secretFiles: string;
43
+ /** paths of files trusted to hold no secrets, an empty pattern trusts none */
44
+ readonly trustedFiles: string;
45
+ }
46
+ export interface SecretExfiltrationMetadata extends MergeableRecord {
47
+ /** sink calls a secret reaches */
48
+ readonly secretSinkCalls: number;
49
+ }
50
+ export declare const SECRET_EXFILTRATION: {
51
+ readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"from", [], import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, 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>[]>>;
52
+ 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: SecretExfiltrationConfig, data: ReadonlyFlowrAnalysisProvider<import("../..").KnownParser>) => Promise<{
53
+ results: SecretExfiltrationResult[];
54
+ '.meta': {
55
+ secretSinkCalls: number;
56
+ };
57
+ }>;
58
+ readonly prettyPrint: {
59
+ readonly query: (r: SecretExfiltrationResult, metadata: unknown) => string;
60
+ readonly full: (r: SecretExfiltrationResult, metadata: unknown) => string;
61
+ };
62
+ readonly info: {
63
+ readonly name: "Secret Exfiltration";
64
+ readonly tags: readonly [LintingRuleTag.Bug, LintingRuleTag.Security, LintingRuleTag.Shiny];
65
+ readonly certainty: LintingRuleCertainty.BestEffort;
66
+ readonly description: "Finds secrets (environment, keyrings, config, credential files) sent to untrusted hosts, the browser, or logs, and optionally into urls, files, other processes, or language models.";
67
+ readonly defaultConfig: () => {
68
+ credentialNamePattern: string;
69
+ credentialValuePattern: string;
70
+ sources: never[];
71
+ declassifiers: never[];
72
+ sinks: readonly SecretSink[];
73
+ optIn: never[];
74
+ controlledInputs: (InputType.Parameter | InputType.File | InputType.Network | InputType.CommandLine | InputType.User)[];
75
+ fileTrust: FileTrust.None;
76
+ secretFiles: string;
77
+ trustedFiles: string;
78
+ };
79
+ };
80
+ };
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SECRET_EXFILTRATION = exports.SecretLeak = void 0;
4
+ const linter_format_1 = require("../linter-format");
5
+ const flowr_search_builder_1 = require("../../search/flowr-search-builder");
6
+ const range_1 = require("../../util/range");
7
+ const linter_tags_1 = require("../linter-tags");
8
+ const identifier_1 = require("../../dataflow/environments/identifier");
9
+ const graph_1 = require("../../dataflow/graph/graph");
10
+ const vertex_1 = require("../../dataflow/graph/vertex");
11
+ const edge_1 = require("../../dataflow/graph/edge");
12
+ const df_helper_1 = require("../../dataflow/graph/df-helper");
13
+ const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
14
+ const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
15
+ const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
16
+ const arguments_1 = require("../../abstract-interpretation/data-frame/arguments");
17
+ const input_types_1 = require("../../queries/catalog/input-sources-query/input-types");
18
+ const parse_1 = require("../../slicing/criterion/parse");
19
+ const resolve_helper_1 = require("../../dataflow/environments/resolve-helper");
20
+ const config_1 = require("../../config");
21
+ const taint_mapping_1 = require("../../taint-analysis/taint-mapping");
22
+ const taint_visitor_1 = require("../../taint-analysis/taint-visitor");
23
+ const secret_analysis_1 = require("../../taint-analysis/predefined/secret-analysis");
24
+ const no_leaked_credentials_1 = require("./no-leaked-credentials");
25
+ const security_analysis_1 = require("../../taint-analysis/predefined/security-analysis");
26
+ /** How a secret leaves the process, see {@link Leaks} */
27
+ var SecretLeak;
28
+ (function (SecretLeak) {
29
+ SecretLeak["Exfiltration"] = "exfiltration";
30
+ SecretLeak["Leakage"] = "leakage";
31
+ SecretLeak["Url"] = "url";
32
+ SecretLeak["Files"] = "files";
33
+ SecretLeak["Process"] = "process";
34
+ SecretLeak["Llm"] = "llm";
35
+ })(SecretLeak || (exports.SecretLeak = SecretLeak = {}));
36
+ /** severity and message per leak, low ones need opt-in */
37
+ const Leaks = {
38
+ [SecretLeak.Exfiltration]: { severity: 'high', does: 'sends a secret to a destination others control' },
39
+ [SecretLeak.Leakage]: { severity: 'medium', does: 'shows a secret' },
40
+ [SecretLeak.Url]: { severity: 'low', does: 'puts a secret into a url' },
41
+ [SecretLeak.Files]: { severity: 'low', does: 'writes a secret to a file' },
42
+ [SecretLeak.Process]: { severity: 'low', does: 'passes a secret to another process' },
43
+ [SecretLeak.Llm]: { severity: 'low', does: 'sends a secret to a language model' }
44
+ };
45
+ /** request builders passing their destination on */
46
+ const RequestBuilder = /^(?:request|req_\w+)$/;
47
+ const StandardStreams = new Set(['stdout', 'stderr']);
48
+ const MaxDestinationHops = 5;
49
+ const argumentAt = (call, at, info) => at === undefined ? undefined : r_argument_1.RArgument.valueOf((0, arguments_1.getFunctionArgument)((0, arguments_1.getVertexArguments)(call, info.idMap), at, info))?.info.id;
50
+ function requestBuilder(vertex) {
51
+ return vertex_1.DfgVertex.isFunctionCall(vertex) && RequestBuilder.test(identifier_1.Identifier.getName(vertex.name)) ? vertex : undefined;
52
+ }
53
+ /** the expression naming the destination of a sink call, through request builders and the variables holding them */
54
+ function destinationOf(call, sink, info) {
55
+ const { graph, idMap } = info;
56
+ let id = argumentAt(call, sink.destination, info);
57
+ for (let i = 0; i < MaxDestinationHops && id !== undefined; i++) {
58
+ const first = requestBuilder(graph.getVertex(id))?.args.find(graph_1.FunctionArgument.isNotEmpty);
59
+ const next = r_symbol_1.RSymbol.is(idMap.get(id))
60
+ ? df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Reads).map(def => df_helper_1.Dataflow.assignedValueOf(def, graph)).find(v => v !== undefined && requestBuilder(graph.getVertex(v)) !== undefined)
61
+ : first && graph_1.FunctionArgument.getReference(first);
62
+ if (next === undefined) {
63
+ break;
64
+ }
65
+ id = next;
66
+ }
67
+ return id;
68
+ }
69
+ /** whether a destination is controlled by others, uncertain as it stems from a parameter, or trusted */
70
+ async function classifyDestination(data, id, controlled) {
71
+ const criterion = parse_1.SlicingCriterion.fromId(id);
72
+ const types = new Set((await data.query([{ type: 'input-sources', criterion }]))['input-sources']?.results[criterion]?.flatMap(s => s.types));
73
+ if (controlled.some(t => t !== input_types_1.InputType.Parameter && types.has(t))) {
74
+ return 'controlled';
75
+ }
76
+ return types.has(input_types_1.InputType.Parameter) && controlled.includes(input_types_1.InputType.Parameter) ? 'parameter' : 'trusted';
77
+ }
78
+ async function leakOf(data, call, untrusted, info, config) {
79
+ const fixed = call.sink.class === secret_analysis_1.SecretSinkClass.Browser ? SecretLeak.Leakage : [SecretLeak.Files, SecretLeak.Process, SecretLeak.Llm].find(l => l === call.sink.class);
80
+ const file = info.idMap.get(argumentAt(call.call, call.sink.file, info) ?? '');
81
+ if (fixed !== undefined || call.sink.class === secret_analysis_1.SecretSinkClass.Logs) {
82
+ return { leak: fixed ?? (file !== undefined && !r_function_call_1.RFunctionCall.isNamed(file, StandardStreams) && file.lexeme !== '""' ? SecretLeak.Files : SecretLeak.Leakage), certain: true };
83
+ }
84
+ const destination = destinationOf(call.call, call.sink, info);
85
+ const trust = untrusted ? 'controlled' : destination === undefined ? 'trusted' : await classifyDestination(data, destination, config.controlledInputs);
86
+ if (trust !== 'trusted') {
87
+ return { leak: SecretLeak.Exfiltration, certain: trust === 'controlled' };
88
+ }
89
+ const urlArgs = [argumentAt(call.call, call.sink.destination, info), argumentAt(call.call, { pos: -1, name: 'query' }, info)];
90
+ const inUrl = [...call.secret].some(([id, kind]) => kind !== secret_analysis_1.Credential && (call.sink.inUrl || urlArgs.includes(id)));
91
+ return call.sink.class === secret_analysis_1.SecretSinkClass.Network && inUrl ? { leak: SecretLeak.Url, certain: true } : undefined;
92
+ }
93
+ exports.SECRET_EXFILTRATION = {
94
+ createSearch: () => flowr_search_builder_1.Q.from([]),
95
+ processSearchResult: async (_elements, config, data) => {
96
+ const literal = new RegExp(config.credentialValuePattern);
97
+ const info = { graph: (await data.dataflow()).graph, idMap: (await data.normalize()).idMap, full: true, resolve: config_1.VariableResolve.Alias, ctx: data.inspectContext() };
98
+ const calls = new Map();
99
+ const untrusted = new Set();
100
+ const analysis = (0, secret_analysis_1.createSecretAnalysis)({
101
+ credentialNamePattern: new RegExp(config.credentialNamePattern, 'i'),
102
+ sources: config.sources,
103
+ declassifiers: config.declassifiers,
104
+ sinks: config.sinks,
105
+ fileTrust: config.fileTrust,
106
+ secretFiles: config.secretFiles === '' ? undefined : new RegExp(config.secretFiles),
107
+ trustedFiles: config.trustedFiles === '' ? undefined : new RegExp(config.trustedFiles)
108
+ });
109
+ await data.taint().add(analysis).addPredefined('security').withHook(({ name, call, node, projectArg }) => {
110
+ const called = (0, taint_visitor_1.taintCallName)(call, node);
111
+ const sink = config.sinks.find(s => s.fns.some(fn => taint_mapping_1.TaintMapper.matches(fn, called)));
112
+ if (sink === undefined) {
113
+ return;
114
+ }
115
+ if (name === security_analysis_1.securityAnalysis.name) {
116
+ const destination = destinationOf(call, sink, info);
117
+ const taint = destination === undefined ? undefined : projectArg(destination)?.value;
118
+ if (taint === security_analysis_1.UserInput || taint === security_analysis_1.NetworkInput || taint === security_analysis_1.FileInput) {
119
+ untrusted.add(call.id);
120
+ }
121
+ return;
122
+ }
123
+ const secret = new Map();
124
+ for (const id of call.args.map(graph_1.FunctionArgument.getReference)) {
125
+ if (id === undefined) {
126
+ continue;
127
+ }
128
+ const taint = projectArg(id)?.value;
129
+ if (taint === secret_analysis_1.Secret || taint === secret_analysis_1.Credential || taint === secret_analysis_1.FileContent || (taint === secret_analysis_1.Response && sink.serializes)) {
130
+ secret.set(id, taint);
131
+ }
132
+ else if (literal.test(resolve_helper_1.Resolve.toSingleString(id, info) ?? '')) {
133
+ secret.set(id, secret_analysis_1.Secret);
134
+ }
135
+ }
136
+ if (secret.size > 0) {
137
+ calls.set(call.id, { call, sink, secret });
138
+ }
139
+ else {
140
+ calls.delete(call.id);
141
+ }
142
+ }).run();
143
+ const results = [];
144
+ for (const call of calls.values()) {
145
+ const leak = await leakOf(data, call, untrusted.has(call.call.id), info, config);
146
+ if (leak === undefined || (Leaks[leak.leak].severity === 'low' && !config.optIn.includes(leak.leak))) {
147
+ continue;
148
+ }
149
+ const node = info.idMap.get(call.call.id);
150
+ const severity = call.sink.class === secret_analysis_1.SecretSinkClass.Browser ? 'high' : Leaks[leak.leak].severity;
151
+ results.push({
152
+ involvedId: call.call.id,
153
+ loc: range_1.SourceLocation.fromNode(node) ?? range_1.SourceLocation.invalid(),
154
+ certainty: leak.certain && [...call.secret.values()].some(k => k !== secret_analysis_1.FileContent) ? linter_format_1.LintingResultCertainty.Certain : linter_format_1.LintingResultCertainty.Uncertain,
155
+ function: identifier_1.Identifier.toString((0, taint_visitor_1.taintCallName)(call.call, node)),
156
+ sink: call.sink.class,
157
+ leak: leak.leak,
158
+ severity
159
+ });
160
+ }
161
+ return { results, '.meta': { secretSinkCalls: calls.size } };
162
+ },
163
+ prettyPrint: (0, linter_format_1.prettyPrint)(result => `${result.function} ${Leaks[result.leak].does} (${result.severity}) at ${range_1.SourceLocation.format(result.loc)}`, result => `${result.function} ${Leaks[result.leak].does} (${result.leak} via ${result.sink}, severity ${result.severity}) at ${range_1.SourceLocation.format(result.loc)}`),
164
+ info: {
165
+ name: 'Secret Exfiltration',
166
+ tags: [linter_tags_1.LintingRuleTag.Bug, linter_tags_1.LintingRuleTag.Security, linter_tags_1.LintingRuleTag.Shiny],
167
+ certainty: linter_format_1.LintingRuleCertainty.BestEffort,
168
+ description: 'Finds secrets (environment, keyrings, config, credential files) sent to untrusted hosts, the browser, or logs, and optionally into urls, files, other processes, or language models.',
169
+ defaultConfig: () => ({
170
+ credentialNamePattern: secret_analysis_1.CredentialNamePattern.source,
171
+ credentialValuePattern: no_leaked_credentials_1.defaultCredentialValuePattern,
172
+ sources: [],
173
+ declassifiers: [],
174
+ sinks: secret_analysis_1.DefaultSecretSinks,
175
+ optIn: [],
176
+ controlledInputs: [input_types_1.InputType.User, input_types_1.InputType.Network, input_types_1.InputType.File, input_types_1.InputType.CommandLine, input_types_1.InputType.Parameter],
177
+ fileTrust: secret_analysis_1.FileTrust.None,
178
+ secretFiles: '',
179
+ trustedFiles: ''
180
+ })
181
+ }
182
+ };
183
+ //# sourceMappingURL=secret-exfiltration.js.map