@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.
Files changed (34) hide show
  1. package/dataflow/environments/built-in-props.d.ts +5 -2
  2. package/dataflow/environments/built-in-props.js +6 -3
  3. package/dataflow/environments/default-builtin-config.d.ts +197 -11
  4. package/dataflow/environments/default-builtin-config.js +62 -42
  5. package/dataflow/environments/identifier.d.ts +1 -0
  6. package/dataflow/environments/query-fn-props.d.ts +3 -0
  7. package/dataflow/environments/query-fn-props.js +8 -0
  8. package/dataflow/environments/resolve-by-name.js +11 -4
  9. package/dataflow/eval/resolve/resolve-argument.js +5 -1
  10. package/dataflow/graph/graph.js +12 -0
  11. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +9 -0
  12. package/dataflow/internal/process/functions/call/named-call-handling.js +60 -8
  13. package/linter/linter-rules.d.ts +8 -3
  14. package/linter/rules/function-finder-util.d.ts +1 -1
  15. package/linter/rules/function-finder-util.js +1 -3
  16. package/linter/rules/network-functions.d.ts +4 -3
  17. package/linter/rules/network-functions.js +14 -12
  18. package/linter/rules/no-leaked-credentials.d.ts +8 -3
  19. package/linter/rules/no-leaked-credentials.js +133 -35
  20. package/linter/rules/problematic-inputs.d.ts +1 -1
  21. package/linter/rules/problematic-inputs.js +20 -14
  22. package/linter/rules/unescaped-arguments.d.ts +13 -2
  23. package/linter/rules/unescaped-arguments.js +100 -12
  24. package/package.json +1 -1
  25. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -1
  26. package/queries/catalog/input-sources-query/input-source-functions.d.ts +6 -4
  27. package/queries/catalog/input-sources-query/input-source-functions.js +11 -6
  28. package/queries/catalog/input-sources-query/input-sources-query-executor.js +1 -1
  29. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +1 -1
  30. package/queries/catalog/input-sources-query/input-sources-query-format.js +9 -2
  31. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +12 -4
  32. package/queries/catalog/input-sources-query/simple-input-classifier.js +227 -29
  33. package/search/search-executor/search-enrichers.js +5 -3
  34. package/util/version.js +2 -2
@@ -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[];
@@ -11,7 +11,12 @@ const identify_link_to_last_call_relation_1 = require("../../queries/catalog/cal
11
11
  const input_source_functions_1 = require("../../queries/catalog/input-sources-query/input-source-functions");
12
12
  const simple_input_classifier_1 = require("../../queries/catalog/input-sources-query/simple-input-classifier");
13
13
  const edge_1 = require("../../dataflow/graph/edge");
14
+ const frame_reflection_1 = require("../../dataflow/fn/frame-reflection");
14
15
  const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
16
+ const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
17
+ const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
18
+ const r_access_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-access");
19
+ const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
15
20
  const flowr_search_builder_1 = require("../../search/flowr-search-builder");
16
21
  const parse_1 = require("../../slicing/criterion/parse");
17
22
  const assert_1 = require("../../util/assert");
@@ -40,7 +45,7 @@ const ParameterSearchLimit = 256;
40
45
  /** Maximum depth to descent to find unescaped part of argument */
41
46
  const MaxDescentDepth = 5;
42
47
  /** Input types that are considered to be safe */
43
- const AcceptedInputs = [simple_input_classifier_1.InputType.Constant, simple_input_classifier_1.InputType.DerivedConstant];
48
+ const AcceptedInputs = [simple_input_classifier_1.InputType.Constant, simple_input_classifier_1.InputType.DerivedConstant, simple_input_classifier_1.InputType.TempFile];
44
49
  /** Input types that may be critical (uncertain) */
45
50
  const UncertainInputs = [simple_input_classifier_1.InputType.Unknown, simple_input_classifier_1.InputType.Parameter, simple_input_classifier_1.InputType.Scope];
46
51
  const UnescapedArgumentCategories = record_1.Record.values(UnescapedArgumentCategory);
@@ -58,17 +63,33 @@ function getCriticalTargets(elements, graph, config, builtIns) {
58
63
  const criticalCalls = Map.groupBy(getEnabledCriticalCalls(config, builtIns), call => identifier_1.Identifier.getName(call.name));
59
64
  const targets = [];
60
65
  const seen = new Set();
61
- for (const { node } of elements) {
62
- const call = graph.getVertex(node.info.id);
66
+ const ids = new Set(elements.map(({ node }) => node.info.id));
67
+ /* calls of an alias (`s <- system; s(x)`) link to the built-in they resolve to */
68
+ const aliases = new Map(graph.verticesOfType(vertex_1.VertexType.FunctionCall).map(([id]) => [id, new Set([...linkedBuiltIns(graph, id, edge_1.EdgeType.Calls), ...wrappedBuiltIns(graph, id)])]));
69
+ for (const [id, names] of aliases) {
70
+ if (names.values().some(name => criticalCalls.has(name))) {
71
+ ids.add(id);
72
+ }
73
+ }
74
+ const locate = (arg) => {
75
+ const node = graph.idMap?.get(arg);
76
+ const range = model_1.RNode.span(node);
77
+ return range === undefined || node === undefined ? undefined : range_1.SourceLocation.from(range, node.info.file);
78
+ };
79
+ for (const id of ids) {
80
+ const call = graph.getVertex(id);
63
81
  if (!vertex_1.DfgVertex.isFunctionCall(call)) {
64
82
  continue;
65
83
  }
66
- for (const { category, name, signature } of criticalCalls.get(identifier_1.Identifier.getName(call.name)) ?? []) {
67
- if (!identifier_1.Identifier.matches(name, call.name) && !identifier_1.Identifier.matches(call.name, name)) {
84
+ const aliased = aliases.get(id) ?? new Set();
85
+ for (const { category, name, signature } of [identifier_1.Identifier.getName(call.name), ...aliased].flatMap(n => criticalCalls.get(n) ?? [])) {
86
+ const viaAlias = !identifier_1.Identifier.matches(name, call.name) && !identifier_1.Identifier.matches(call.name, name);
87
+ /* a function handed on (`purrr::map(x, system)`) is called where it lands, not here */
88
+ if (viaAlias && (!aliased.has(identifier_1.Identifier.getName(name)) || call.args.some(a => linkedBuiltIns(graph, graph_1.FunctionArgument.getReference(a) ?? '', edge_1.EdgeType.Reads).includes(identifier_1.Identifier.getName(name))))) {
68
89
  continue;
69
90
  }
70
91
  for (const arg of function_semantics_1.FunctionSemantics.call.match.findWithProps(call.args, signature, config.categories[category].criticalArgs)) {
71
- const location = range_1.SourceLocation.fromNode(graph.idMap?.get(arg));
92
+ const location = locate(arg);
72
93
  const key = `${category}-${call.id}-${arg}`;
73
94
  if (location !== undefined && !seen.has(key)) {
74
95
  seen.add(key);
@@ -77,8 +98,66 @@ function getCriticalTargets(elements, graph, config, builtIns) {
77
98
  }
78
99
  }
79
100
  }
101
+ for (const category of UnescapedArgumentCategories.filter(c => !config.disabledCategories.includes(c))) {
102
+ for (const { call, callee } of methodCalls(graph, config.categories[category].methods ?? [])) {
103
+ for (const arg of call.args.filter(a => graph_1.FunctionArgument.getName(a) === undefined).map(graph_1.FunctionArgument.getReference).filter(assert_1.isNotUndefined)) {
104
+ const location = locate(arg);
105
+ if (location !== undefined) {
106
+ targets.push({ category, call, callee, signature: [], arg, location });
107
+ }
108
+ }
109
+ }
110
+ }
80
111
  return targets;
81
112
  }
113
+ /** the calls `obj$method(...)` of the given methods, on the named object or on one its constructor returned */
114
+ function methodCalls(graph, methods) {
115
+ if (methods.length === 0) {
116
+ return [];
117
+ }
118
+ /* a value made by the constructor, also through a branch or block (`if(a) V8::v8() else ...`) or another alias */
119
+ const holds = (v, receiver, depth) => {
120
+ const made = graph.getVertex(v);
121
+ const value = graph.idMap?.get(v);
122
+ if (vertex_1.DfgVertex.isVariableDefinition(made) || vertex_1.DfgVertex.hasOrigin(made, built_in_proc_name_1.BuiltInProcName.Assignment)) {
123
+ return false;
124
+ }
125
+ else if (r_symbol_1.RSymbol.is(value) && !vertex_1.DfgVertex.isFunctionCall(made)) {
126
+ return means(value, receiver, depth - 1);
127
+ }
128
+ return vertex_1.DfgVertex.isFunctionCall(made) && (identifier_1.Identifier.matches(made.name, receiver)
129
+ || (depth > 0 && (0, frame_reflection_1.edgeTargets)(graph, v, edge_1.EdgeType.Returns).some(r => holds(r, receiver, depth - 1))));
130
+ };
131
+ /* the named object where no binding of the program surely shadows it, otherwise what a binding holds */
132
+ const means = (symbol, receiver, depth = 4) => {
133
+ const defs = (0, frame_reflection_1.edgeTargets)(graph, symbol.info.id, edge_1.EdgeType.Reads).filter(d => !node_id_1.NodeId.isBuiltIn(d));
134
+ return (defs.every(d => graph.getVertex(d)?.cds?.length) && identifier_1.Identifier.matches(symbol.content, receiver))
135
+ || (depth > 0 && defs.some(def => (0, frame_reflection_1.edgeTargets)(graph, def, edge_1.EdgeType.DefinedBy).some(v => holds(v, receiver, depth))));
136
+ };
137
+ return graph.verticesOfType(vertex_1.VertexType.FunctionCall).flatMap(([id, call]) => {
138
+ const node = graph.idMap?.get(id);
139
+ const access = r_function_call_1.RFunctionCall.isUnnamed(node) ? node.calledFunction : undefined;
140
+ if (!r_access_1.RAccess.isNamed(access) || !r_symbol_1.RSymbol.is(access.accessed) || !vertex_1.DfgVertex.isFunctionCall(call)) {
141
+ return [];
142
+ }
143
+ const field = model_1.RNode.lexeme(access.access[0].value);
144
+ const accessed = access.accessed;
145
+ return methods.some(m => m.method === field && means(accessed, m.receiver)) ? [{ call, callee: model_1.RNode.lexeme(access) ?? field ?? '' }] : [];
146
+ }).toArray();
147
+ }
148
+ /** The names of the built-ins `id` links to with an edge of the given type, none if it may link to anything else (a closure checked where its body calls them) */
149
+ function linkedBuiltIns(graph, id, type) {
150
+ const linked = graph.outgoingEdges(id)?.entries().filter(([, edge]) => edge_1.DfEdge.includesType(edge, type)).map(([to]) => to).toArray() ?? [];
151
+ return linked.every(node_id_1.NodeId.isBuiltIn) ? linked.map(node_id_1.NodeId.fromBuiltIn) : [];
152
+ }
153
+ /** the built-ins handed to the call a called variable holds the result of, as `p` holds `purrr::partial(system)` */
154
+ function wrappedBuiltIns(graph, id) {
155
+ return (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Reads).flatMap(v => vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(v)) ? (0, frame_reflection_1.edgeTargets)(graph, v, edge_1.EdgeType.DefinedBy) : [])
156
+ .flatMap(w => {
157
+ const wrapper = graph.getVertex(w);
158
+ return vertex_1.DfgVertex.isFunctionCall(wrapper) ? wrapper.args.flatMap(a => linkedBuiltIns(graph, graph_1.FunctionArgument.getReference(a) ?? '', edge_1.EdgeType.Reads)) : [];
159
+ });
160
+ }
82
161
  function mapInputSourceToArgs(call, sources) {
83
162
  const args = call.args.map(graph_1.FunctionArgument.getReference).filter(assert_1.isNotUndefined);
84
163
  return args.flatMap((arg, i) => {
@@ -128,8 +207,9 @@ function isCertainlyCritical(source, config) {
128
207
  async function getUnescapedSources(category, targets, config, data, graph) {
129
208
  const sanitizers = config.categories[category].sanitizers ?? [];
130
209
  const sanitizerNames = new Set(sanitizers.map(call => identifier_1.Identifier.getName(call)));
131
- const narrowing = [...(0, input_source_functions_1.narrowingFunctions)(data.inspectContext().env.builtInIndex), ...sanitizers.map(call => ({ call }))];
132
- const queryConfig = { narrowing };
210
+ const builtIns = data.inspectContext().env.builtInIndex;
211
+ /* a count or a logical carries nothing that could be injected, even when it depends on the input */
212
+ const queryConfig = { narrowing: (0, input_source_functions_1.narrowingFunctions)(builtIns), sanitizers: [...(0, input_source_functions_1.contentFreeFunctions)(builtIns), ...sanitizers] };
133
213
  const found = new Map();
134
214
  let entries = targets.map(target => ({ target, call: target.call.id, only: new Set([target.arg]), depth: 0 }));
135
215
  while (entries.length > 0) {
@@ -197,7 +277,7 @@ function createResult(target, sources, config, idMap) {
197
277
  involvedId: [target.call.id, target.arg],
198
278
  loc: target.location,
199
279
  category: target.category,
200
- function: identifier_1.Identifier.toString(target.call.name),
280
+ function: target.callee ?? identifier_1.Identifier.toString(target.call.name),
201
281
  sources,
202
282
  input: [...new Set(sources.flatMap(source => source.types).filter(type => !config.acceptedInputs.includes(type)))],
203
283
  ...(quickFix.length > 0 ? { quickFix } : {})
@@ -223,7 +303,11 @@ exports.UNESCAPED_ARGUMENTS = {
223
303
  const unescaped = await getUnescapedSources(category, categoryTargets, config, data, graph);
224
304
  for (const target of categoryTargets) {
225
305
  const sources = unescaped.get(target);
226
- if (sources === undefined) {
306
+ /* `eval(parse_expr(x))` is reported where the inner call is handed `x` */
307
+ if (sources?.every(s => categoryTargets.some(t => t.call.id === s.id && unescaped.has(t)))) {
308
+ continue;
309
+ }
310
+ else if (sources === undefined) {
227
311
  escaped++;
228
312
  }
229
313
  else {
@@ -254,7 +338,7 @@ exports.UNESCAPED_ARGUMENTS = {
254
338
  quickFix: { call: 'shQuote' }
255
339
  },
256
340
  [UnescapedArgumentCategory.Eval]: {
257
- criticalCalls: built_in_props_1.SemanticCallTag.Eval,
341
+ criticalCalls: [built_in_props_1.SemanticCallTag.Eval, built_in_props_1.CallProp.Lang],
258
342
  criticalArgs: built_in_props_1.ArgProp.Injectable,
259
343
  sanitizers: [
260
344
  identifier_1.Identifier.from(['match.arg', "base" /* PkgName.Base */]),
@@ -294,7 +378,11 @@ exports.UNESCAPED_ARGUMENTS = {
294
378
  identifier_1.Identifier.from(['toJSON', 'RJSONIO']),
295
379
  identifier_1.Identifier.from(['toJSON', 'rjson'])
296
380
  ],
297
- quickFix: { call: identifier_1.Identifier.from(['toJSON', "jsonlite" /* PkgName.Jsonlite */]), partsOnly: true }
381
+ quickFix: { call: identifier_1.Identifier.from(['toJSON', "jsonlite" /* PkgName.Jsonlite */]), partsOnly: true },
382
+ methods: [
383
+ ...['eval', 'call', 'source'].flatMap(method => identifier_1.Identifier.fromAll('V8', ['v8', 'new_context']).map(receiver => ({ receiver, method }))),
384
+ ...identifier_1.Identifier.fromAllIn(["htmltools" /* PkgName.HtmlTools */, "shiny" /* PkgName.Shiny */], ['tags']).map(receiver => ({ receiver, method: 'script' }))
385
+ ]
298
386
  }
299
387
  },
300
388
  disabledCategories: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eagleoutice/flowr",
3
- "version": "2.16.1",
3
+ "version": "2.16.2",
4
4
  "description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -12,6 +12,7 @@ const identify_link_to_last_call_relation_1 = require("./identify-link-to-last-c
12
12
  const identify_link_to_relation_1 = require("./identify-link-to-relation");
13
13
  const identifier_1 = require("../../../dataflow/environments/identifier");
14
14
  const df_helper_1 = require("../../../dataflow/graph/df-helper");
15
+ const query_fn_props_1 = require("../../../dataflow/environments/query-fn-props");
15
16
  const queue_1 = require("../../../util/collections/queue");
16
17
  const r_base_packages_1 = require("../../../util/r-base-packages");
17
18
  function makeReport(collector) {
@@ -310,7 +311,7 @@ async function executeCallContextQueries({ analyzer }, queries) {
310
311
  continue;
311
312
  }
312
313
  }
313
- if (df_helper_1.Dataflow.isQuoted(nodeId, dataflow.graph)) {
314
+ if (df_helper_1.Dataflow.isQuoted(nodeId, dataflow.graph) && !(0, query_fn_props_1.quotedForWorker)(nodeId, dataflow.graph, analyzer.inspectContext().env.builtInIndex)) {
314
315
  /* if the call is quoted, we do not want to link to it */
315
316
  continue;
316
317
  }
@@ -1,3 +1,4 @@
1
+ import { Identifier } from '../../../dataflow/environments/identifier';
1
2
  import type { LinkedInputEntryPoint, LinkedInputObject, NarrowingFunction } from './simple-input-classifier';
2
3
  import type { BuiltInIndex } from '../../../dataflow/environments/query-fn-props';
3
4
  /**
@@ -8,12 +9,13 @@ import type { BuiltInIndex } from '../../../dataflow/environments/query-fn-props
8
9
  */
9
10
  export declare const LinkedInputObjects: readonly LinkedInputObject[];
10
11
  /**
11
- * The functions whose result is bounded no matter what flows in, read back from the {@link SemanticCallTag.Narrows}
12
- * built-ins: with an {@link ArgProp.Bounds} parameter the result is one of that argument's values (`match.arg`
13
- * and its `choices`), without one it is a count, an index, or a logical of the call's own making. Label a
14
- * built-in `Narrows` (in the {@link DefaultBuiltinConfig} or your own definitions) and it shows up here.
12
+ * The {@link SemanticCallTag.Narrows} built-ins with an {@link ArgProp.Bounds} parameter, whose result is one of
13
+ * that argument's values (`match.arg` and its `choices`). Label a built-in `Narrows` with such a parameter
14
+ * (in the {@link DefaultBuiltinConfig} or your own definitions) and it shows up here.
15
15
  */
16
16
  export declare function narrowingFunctions(index: BuiltInIndex): readonly NarrowingFunction[];
17
+ /** The {@link SemanticCallTag.Narrows} built-ins without an {@link ArgProp.Bounds} parameter: counts and logicals free of their arguments' content. */
18
+ export declare function contentFreeFunctions(index: BuiltInIndex): readonly Identifier[];
17
19
  /**
18
20
  * Calls that hand a function to a framework which binds its parameters by position.
19
21
  * @see {@link LinkedInputEntryPoint}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinkedInputEntryPoints = exports.LinkedInputObjects = void 0;
4
4
  exports.narrowingFunctions = narrowingFunctions;
5
+ exports.contentFreeFunctions = contentFreeFunctions;
5
6
  const identifier_1 = require("../../../dataflow/environments/identifier");
6
7
  const simple_input_classifier_1 = require("./simple-input-classifier");
7
8
  const built_in_props_1 = require("../../../dataflow/environments/built-in-props");
@@ -28,18 +29,22 @@ exports.LinkedInputObjects = [
28
29
  { name: 'session', type: simple_input_classifier_1.InputType.User, withParams: ['input', 'output'], requires: 'shiny', fields: ['clientData', 'request'] }
29
30
  ];
30
31
  /**
31
- * The functions whose result is bounded no matter what flows in, read back from the {@link SemanticCallTag.Narrows}
32
- * built-ins: with an {@link ArgProp.Bounds} parameter the result is one of that argument's values (`match.arg`
33
- * and its `choices`), without one it is a count, an index, or a logical of the call's own making. Label a
34
- * built-in `Narrows` (in the {@link DefaultBuiltinConfig} or your own definitions) and it shows up here.
32
+ * The {@link SemanticCallTag.Narrows} built-ins with an {@link ArgProp.Bounds} parameter, whose result is one of
33
+ * that argument's values (`match.arg` and its `choices`). Label a built-in `Narrows` with such a parameter
34
+ * (in the {@link DefaultBuiltinConfig} or your own definitions) and it shows up here.
35
35
  */
36
36
  function narrowingFunctions(index) {
37
37
  const bounds = new Map(index.params(built_in_props_1.ArgProp.Bounds).map(p => [identifier_1.Identifier.getName(p.call), p]));
38
- return index.with(built_in_props_1.SemanticCallTag.Narrows).map(call => {
38
+ return index.with(built_in_props_1.SemanticCallTag.Narrows).flatMap(call => {
39
39
  const bound = bounds.get(identifier_1.Identifier.getName(call));
40
- return bound === undefined ? { call } : { call, argName: bound.name, argIdx: bound.index };
40
+ return bound === undefined ? [] : [{ call, argName: bound.name, argIdx: bound.index }];
41
41
  });
42
42
  }
43
+ /** The {@link SemanticCallTag.Narrows} built-ins without an {@link ArgProp.Bounds} parameter: counts and logicals free of their arguments' content. */
44
+ function contentFreeFunctions(index) {
45
+ const bounded = new Set(index.params(built_in_props_1.ArgProp.Bounds).map(p => identifier_1.Identifier.getName(p.call)));
46
+ return index.with(built_in_props_1.SemanticCallTag.Narrows).filter(call => !bounded.has(identifier_1.Identifier.getName(call)));
47
+ }
43
48
  /** shiny binds `input`, `output`, and `session` positionally, so their names are up to whoever writes the server */
44
49
  const ShinyServerParams = ['input', undefined, 'session'];
45
50
  /**
@@ -70,7 +70,7 @@ function addAll(base, extra) {
70
70
  return result;
71
71
  }
72
72
  /** Config fields that hold structured values (not function searches) and are carried over verbatim. */
73
- const StructuredConfigKeys = ['linkedObjects', 'linkedEntryPoints', 'narrowing'];
73
+ const StructuredConfigKeys = ['linkedObjects', 'linkedEntryPoints', 'narrowing', 'templates'];
74
74
  function isStructuredConfigKey(key) {
75
75
  return StructuredConfigKeys.includes(key);
76
76
  }
@@ -23,7 +23,7 @@ export interface InputSourcesQuery extends BaseQueryFormat {
23
23
  /**
24
24
  * Which functions belong to which input type is stated with the functions themselves, in the built-in configuration
25
25
  * the analyzer registered (see {@link ReadOnlyFlowrAnalyzerEnvironmentContext#builtInDefinitions}):
26
- * a function that states its props and carries none of the {@link InputProps} derives its result from its arguments, the others bring in data of their own, and a {@link SemanticCallTag.Narrows} one bounds its result no matter what flows in. Add a function there (or override its props with your own built-in definitions) and it shows up here.
26
+ * a function that states its props and carries none of the {@link InputProps} derives its result from its arguments, the others bring in data of their own, and a {@link SemanticCallTag.Narrows} one with an {@link ArgProp.Bounds} parameter is classified by that argument alone. Add a function there (or override its props with your own built-in definitions) and it shows up here.
27
27
  */
28
28
  export declare const defaultInputClassifierConfig: (ctx: ReadOnlyFlowrAnalyzerContext) => InputClassifierConfig;
29
29
  export interface InputSourcesQueryResult extends BaseQueryResult {
@@ -21,7 +21,7 @@ const built_in_props_1 = require("../../../dataflow/environments/built-in-props"
21
21
  /**
22
22
  * Which functions belong to which input type is stated with the functions themselves, in the built-in configuration
23
23
  * the analyzer registered (see {@link ReadOnlyFlowrAnalyzerEnvironmentContext#builtInDefinitions}):
24
- * a function that states its props and carries none of the {@link InputProps} derives its result from its arguments, the others bring in data of their own, and a {@link SemanticCallTag.Narrows} one bounds its result no matter what flows in. Add a function there (or override its props with your own built-in definitions) and it shows up here.
24
+ * a function that states its props and carries none of the {@link InputProps} derives its result from its arguments, the others bring in data of their own, and a {@link SemanticCallTag.Narrows} one with an {@link ArgProp.Bounds} parameter is classified by that argument alone. Add a function there (or override its props with your own built-in definitions) and it shows up here.
25
25
  */
26
26
  const defaultInputClassifierConfig = (ctx) => ctx.env.derive(inputClassifierConfigOf);
27
27
  exports.defaultInputClassifierConfig = defaultInputClassifierConfig;
@@ -37,9 +37,13 @@ const inputClassifierConfigOf = (env) => {
37
37
  [simple_input_classifier_1.InputType.System]: builtIns.with(built_in_props_1.SemanticCallTag.Process),
38
38
  [simple_input_classifier_1.InputType.Ffi]: builtIns.with(built_in_props_1.CallProp.Ffi),
39
39
  [simple_input_classifier_1.InputType.Lang]: builtIns.with(built_in_props_1.CallProp.Lang),
40
- [simple_input_classifier_1.InputType.Options]: builtIns.with(built_in_props_1.CallProp.Ambient),
40
+ [simple_input_classifier_1.InputType.Options]: builtIns.with([built_in_props_1.CallProp.Ambient, built_in_props_1.SemanticCallTag.LoadsPackage, built_in_props_1.SemanticCallTag.ChecksPackage]),
41
41
  [simple_input_classifier_1.InputType.CommandLine]: builtIns.with(built_in_props_1.SemanticCallTag.CommandLine),
42
42
  [simple_input_classifier_1.InputType.User]: builtIns.with(built_in_props_1.SemanticCallTag.User),
43
+ [simple_input_classifier_1.InputType.Unknown]: builtIns.with(built_in_props_1.CallProp.NonDet),
44
+ evaluating: builtIns.with(built_in_props_1.SemanticCallTag.Eval),
45
+ editing: builtIns.with(built_in_props_1.SemanticCallTag.Edits),
46
+ templates: builtIns.params(built_in_props_1.ArgProp.Injectable).map(p => ({ call: p.call, argName: p.name, argIdx: p.index })),
43
47
  linkedObjects: input_source_functions_1.LinkedInputObjects,
44
48
  linkedEntryPoints: input_source_functions_1.LinkedInputEntryPoints,
45
49
  narrowing: (0, input_source_functions_1.narrowingFunctions)(builtIns)
@@ -87,6 +91,9 @@ exports.InputSourcesDefinition = {
87
91
  [simple_input_classifier_1.InputType.Options]: joi_1.default.array().items(joi_1.default.string()).optional().description('Functions that access or set global options (e.g., options, getOption).'),
88
92
  [simple_input_classifier_1.InputType.CommandLine]: joi_1.default.array().items(joi_1.default.string()).optional().description('Functions that hand back what the program was invoked with (e.g., commandArgs).'),
89
93
  [simple_input_classifier_1.InputType.User]: joi_1.default.array().items(joi_1.default.string()).optional().description('Functions that read interactive user input (e.g., file.choose, readline, menu, askYesNo).'),
94
+ sanitizers: joi_1.default.array().items(joi_1.default.string()).optional().description('Functions whose result counts as a derived constant whatever flows in (e.g., an escaping function).'),
95
+ evaluating: joi_1.default.array().items(joi_1.default.string()).optional().description('Functions that evaluate code or look up names at run time, whose result is unknown (e.g., eval, do.call, exists).'),
96
+ editing: joi_1.default.array().items(joi_1.default.string()).optional().description('Functions that cut or replace parts of a string, undoing what a sanitizer escaped (e.g., gsub, substr).'),
90
97
  linkedObjects: joi_1.default.array().items(joi_1.default.object({
91
98
  name: joi_1.default.string().required().description('Name of the object, e.g. input.'),
92
99
  type: joi_1.default.string().valid(...record_1.Record.values(simple_input_classifier_1.InputType)).required().description('How reads of the object (or of its fields) are classified.'),
@@ -53,10 +53,10 @@ export interface LinkedInputEntryPoint {
53
53
  /** A function whose result is bounded by one argument (e.g. `match.arg` by its `choices`), classified by that argument alone. */
54
54
  export interface NarrowingFunction {
55
55
  readonly call: Identifier;
56
- /** the name of the bounding argument; omit (with `argIdx`) for a result that is always a bounded, content-independent value */
57
- readonly argName?: string;
58
- /** the index of the bounding argument; omit (with `argName`) for an always-`DerivedConstant` result */
59
- readonly argIdx?: number;
56
+ /** the name of the bounding argument */
57
+ readonly argName: string;
58
+ /** the index of the bounding argument when it is passed positionally */
59
+ readonly argIdx: number;
60
60
  }
61
61
  /**
62
62
  * Scalar R constant values representable in TypeScript.
@@ -116,6 +116,14 @@ export interface InputClassifierConfig<Functions extends InputClassifierFunction
116
116
  * @see {@link NarrowingFunction}
117
117
  */
118
118
  narrowing?: readonly NarrowingFunction[];
119
+ /** Functions whose result counts as a {@link InputType.DerivedConstant} whatever flows in, like a linter's escaping functions. */
120
+ sanitizers?: Functions;
121
+ /** The arguments a {@link sanitizers|sanitizer} takes as code rather than escaping, like the template of `sqlInterpolate`, whose data still flows. */
122
+ templates?: readonly NarrowingFunction[];
123
+ /** Functions that evaluate code or look names up at run time (`eval`, `do.call`, `exists`), so their result is never constant. */
124
+ evaluating?: Functions;
125
+ /** Functions that cut or replace parts of a string (`gsub`), undoing what a {@link sanitizers|sanitizer} escaped. */
126
+ editing?: Functions;
119
127
  }
120
128
  /**
121
129
  * Takes the given id which is expected to either be: