@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.
Files changed (80) hide show
  1. package/README.md +9 -9
  2. package/cli/flowr-main-options.d.ts +15 -0
  3. package/cli/flowr-main-options.js +18 -0
  4. package/cli/flowr.d.ts +18 -0
  5. package/cli/flowr.js +13 -2
  6. package/cli/repl/commands/repl-clipboard.js +2 -1
  7. package/cli/repl/commands/repl-commands.js +2 -0
  8. package/cli/repl/commands/repl-main.d.ts +5 -0
  9. package/cli/repl/commands/repl-signature.js +2 -0
  10. package/cli/repl/core.d.ts +7 -1
  11. package/cli/repl/core.js +17 -8
  12. package/cli/repl/execute.js +2 -0
  13. package/cli/repl/server/connection.js +2 -1
  14. package/cli/repl/server/net.d.ts +10 -0
  15. package/cli/repl/server/net.js +34 -1
  16. package/cli/slicer-app.js +2 -1
  17. package/config.d.ts +12 -2
  18. package/config.js +91 -14
  19. package/dataflow/environments/built-in-props.d.ts +5 -2
  20. package/dataflow/environments/built-in-props.js +6 -3
  21. package/dataflow/environments/default-builtin-config.d.ts +197 -11
  22. package/dataflow/environments/default-builtin-config.js +62 -42
  23. package/dataflow/environments/identifier.d.ts +1 -0
  24. package/dataflow/environments/query-fn-props.d.ts +3 -0
  25. package/dataflow/environments/query-fn-props.js +8 -0
  26. package/dataflow/environments/resolve-by-name.js +11 -4
  27. package/dataflow/eval/resolve/resolve-argument.js +5 -1
  28. package/dataflow/extractor.js +14 -5
  29. package/dataflow/fn/frame-reflection.js +14 -2
  30. package/dataflow/graph/graph.js +12 -0
  31. package/dataflow/internal/control-flow.d.ts +11 -0
  32. package/dataflow/internal/control-flow.js +15 -0
  33. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +4 -10
  34. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +1 -1
  35. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +9 -0
  36. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +8 -7
  37. package/dataflow/internal/process/functions/call/deferred.js +6 -1
  38. package/dataflow/internal/process/functions/call/named-call-handling.js +70 -9
  39. package/documentation/doc-capabilities.js +4 -1
  40. package/documentation/wiki-interface.js +4 -0
  41. package/engines.js +11 -3
  42. package/linter/linter-executor.js +19 -1
  43. package/linter/linter-rules.d.ts +8 -3
  44. package/linter/rules/file-path-validity.js +4 -1
  45. package/linter/rules/function-finder-util.d.ts +1 -1
  46. package/linter/rules/function-finder-util.js +1 -3
  47. package/linter/rules/network-functions.d.ts +4 -3
  48. package/linter/rules/network-functions.js +14 -12
  49. package/linter/rules/no-leaked-credentials.d.ts +8 -3
  50. package/linter/rules/no-leaked-credentials.js +133 -35
  51. package/linter/rules/problematic-inputs.d.ts +1 -1
  52. package/linter/rules/problematic-inputs.js +20 -14
  53. package/linter/rules/seeded-randomness.js +3 -1
  54. package/linter/rules/unescaped-arguments.d.ts +13 -2
  55. package/linter/rules/unescaped-arguments.js +100 -12
  56. package/package.json +1 -1
  57. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +14 -5
  58. package/project/plugins/file-plugins/files/flowr-rda-file.js +35 -24
  59. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +2 -1
  60. package/project/sigdb/decompress.js +3 -1
  61. package/project/sigdb/sigdb-download.js +9 -6
  62. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -1
  63. package/queries/catalog/config-query/config-query-executor.js +9 -2
  64. package/queries/catalog/input-sources-query/input-source-functions.d.ts +6 -4
  65. package/queries/catalog/input-sources-query/input-source-functions.js +11 -6
  66. package/queries/catalog/input-sources-query/input-sources-query-executor.js +1 -1
  67. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +1 -1
  68. package/queries/catalog/input-sources-query/input-sources-query-format.js +9 -2
  69. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +12 -4
  70. package/queries/catalog/input-sources-query/simple-input-classifier.js +227 -29
  71. package/r-bridge/shell-executor.js +2 -0
  72. package/r-bridge/shell.js +2 -0
  73. package/search/search-executor/search-enrichers.js +5 -3
  74. package/slicing/static/static-slicer.js +14 -9
  75. package/util/files.d.ts +6 -0
  76. package/util/files.js +12 -0
  77. package/util/parallel.js +2 -0
  78. package/util/secure-mode.d.ts +42 -0
  79. package/util/secure-mode.js +70 -0
  80. package/util/version.js +2 -2
@@ -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:
@@ -13,6 +13,8 @@ const vertex_1 = require("../../../dataflow/graph/vertex");
13
13
  const df_helper_1 = require("../../../dataflow/graph/df-helper");
14
14
  const edge_1 = require("../../../dataflow/graph/edge");
15
15
  const identifier_1 = require("../../../dataflow/environments/identifier");
16
+ const r_parameter_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
17
+ const r_comment_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-comment");
16
18
  const assert_1 = require("../../../util/assert");
17
19
  const arrays_1 = require("../../../util/collections/arrays");
18
20
  const built_in_proc_name_1 = require("../../../dataflow/environments/built-in-proc-name");
@@ -24,7 +26,11 @@ const r_symbol_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol"
24
26
  const convert_values_1 = require("../../../r-bridge/lang-4.x/convert-values");
25
27
  const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
26
28
  const r_function_definition_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
29
+ const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
30
+ const r_argument_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
27
31
  const frame_reflection_1 = require("../../../dataflow/fn/frame-reflection");
32
+ const range_1 = require("../../../util/range");
33
+ const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
28
34
  /** how far a function handed to an entry point may be passed along before we give up resolving it */
29
35
  const MaxFunctionResolveDepth = 4;
30
36
  function isConstantLike(type) {
@@ -77,8 +83,10 @@ class InputClassifier {
77
83
  packages;
78
84
  cache = new Map();
79
85
  fullClassifier;
86
+ unsanitized;
80
87
  declarationIndex;
81
88
  entryPointIndex;
89
+ rebinding;
82
90
  /** `packages` are the packages attached in the analyzed program, `undefined` if that is not known (then everything may match) */
83
91
  constructor(dfg, config, fullDfg, packages) {
84
92
  this.dfg = dfg;
@@ -90,7 +98,12 @@ class InputClassifier {
90
98
  return this.fullDfg ?? this.dfg;
91
99
  }
92
100
  matches(call, list) {
93
- return list?.some(id => call.id === id || (identifier_1.Identifier.is(id) && callMeans(call.name, id, this.packages))) ?? false;
101
+ /* a call of a definition in the code does not mean the built-in of the same name */
102
+ return list?.some(id => call.id === id || (identifier_1.Identifier.is(id) && callMeans(call.name, id, this.packages) && !this.callsDefinition(call))) ?? false;
103
+ }
104
+ /** whether the callee is a definition of the code rather than one handed in as an argument */
105
+ callsDefinition(call) {
106
+ return (0, frame_reflection_1.calledDefinitions)(this.whole, call.id).some(d => !(0, frame_reflection_1.hasEdgeOfType)(this.whole, call.id, d, edge_1.EdgeType.Argument));
94
107
  }
95
108
  /** whether the package the given entry needs is attached (unknown package information lets everything through) */
96
109
  hasPackage(name) {
@@ -98,7 +111,26 @@ class InputClassifier {
98
111
  }
99
112
  classifyAt(ref, graph = this.dfg) {
100
113
  const vtx = ref === undefined ? undefined : graph.getVertex(ref);
101
- return vtx ? this.classifyEntry(vtx) : undefined;
114
+ /* what the criterion's function reads through a template (`glue("{x}")`) is no node of its code */
115
+ return vtx ? this.classifyEntry(vtx) : ref !== undefined && graph === this.dfg ? this.classifyInFullGraph(ref) : undefined;
116
+ }
117
+ /** classifies an argument as written: the name a `get` looks up, the function `do.call` is handed */
118
+ classifyArgument(call, ref) {
119
+ const node = ref === undefined ? undefined : this.dfg.idMap?.get(ref);
120
+ const parent = node?.info.parent === undefined ? undefined : this.dfg.idMap?.get(node.info.parent);
121
+ const vtx = ref === undefined ? undefined : this.dfg.getVertex(ref);
122
+ if (ref === undefined || !r_symbol_1.RSymbol.is(node)) {
123
+ return this.classifyAt(ref);
124
+ }
125
+ else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Get) && parent !== undefined && !r_argument_1.RArgument.is(parent)) {
126
+ const written = r_string_1.RString.is(parent) ? (0, objects_1.compactRecord)({ ...sourceOf(ref, input_types_1.InputType.Constant), value: parent.content.str }) : this.classifyAt(parent.info.id);
127
+ return written && { ...written, id: ref };
128
+ }
129
+ else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Apply) && vertex_1.DfgVertex.isFunctionCall(vtx) && (0, frame_reflection_1.edgeTargets)(this.dfg, ref, edge_1.EdgeType.Reads).every(t => node_id_1.NodeId.isBuiltIn(t) || !this.functionDefinitionsAt(t).next().done)) {
130
+ /* a name of a function the code defines or flowR knows */
131
+ return sourceOf(ref, input_types_1.InputType.Constant);
132
+ }
133
+ return this.classifyAt(ref);
102
134
  }
103
135
  /**
104
136
  * Returns the specification of the {@link LinkedInputObject|linked input object} the given id refers to
@@ -276,6 +308,13 @@ class InputClassifier {
276
308
  const parameters = new Set(enclosing.flatMap(fn => fn.parameters.map(p => identifier_1.Identifier.getName(p.name.content))));
277
309
  for (const arg of call.args) {
278
310
  const ref = graph_1.FunctionArgument.getReference(arg);
311
+ /* an evaluated argument (`parse_expr(text)`) is code only as far as its value is */
312
+ if (ref !== undefined && (0, frame_reflection_1.hasEdgeOfType)(this.whole, call.id, ref, edge_1.EdgeType.Reads)) {
313
+ if (!this.classifyAt(ref)?.types.every(isConstantLike)) {
314
+ return false;
315
+ }
316
+ continue;
317
+ }
279
318
  const within = model_1.RNode.collectAllIds(ref === undefined ? undefined : idMap.get(ref));
280
319
  for (const id of within) {
281
320
  const node = idMap.get(id);
@@ -323,49 +362,95 @@ class InputClassifier {
323
362
  }
324
363
  return undefined;
325
364
  }
326
- /** the argument a built-in hands on: the value of a block or `get` (then `renamed`), the condition of a branch or loop */
365
+ /** the argument a built-in hands on: the value of a block or `get` (then `renamed`), the condition of a loop */
327
366
  passedOn(call) {
328
367
  if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.ExpressionList)) {
329
368
  // `{ a; b }` evaluates to its last expression, just like in R
330
369
  return { via: call.args.findLast(a => !graph_1.FunctionArgument.isEmpty(a)), renamed: true };
331
370
  }
332
- else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) || call.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop)) {
371
+ else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop)) {
333
372
  return { via: call.args[0], renamed: false };
334
373
  }
335
374
  else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.ForLoop)) {
336
375
  return { via: call.args[1], renamed: false };
337
376
  }
338
- else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Get) && !this.whole.unknownSideEffects.has(node_id_1.NodeId.normalize(call.id))) {
377
+ else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Get) && !this.whole.unknownSideEffects.has(node_id_1.NodeId.normalize(call.id))
378
+ && (0, frame_reflection_1.edgeTargets)(this.whole, call.id, edge_1.EdgeType.Returns).length > 0) {
339
379
  // a statically resolved `get("x")` yields the value of the retrieved variable, read via its first argument
340
380
  return { via: call.args[0], renamed: true };
341
381
  }
342
382
  return undefined;
343
383
  }
384
+ /** an `if` or `switch` yields one of its branches (`NULL` without a matching one), its condition only picks which */
385
+ classifyBranches(call) {
386
+ const acc = new ClassificationAccumulator();
387
+ const isSwitch = call.origin.includes(built_in_proc_name_1.BuiltInProcName.Switch);
388
+ const condition = conditionArgument(call);
389
+ const branches = call.args.filter(a => a !== condition);
390
+ for (const ref of branches.map(graph_1.FunctionArgument.getReference)) {
391
+ /* a branch flowR found dead is in no graph */
392
+ const vtx = ref === undefined ? undefined : this.dfg.getVertex(ref) ?? this.whole.getVertex(ref);
393
+ if (vtx !== undefined) {
394
+ acc.merge(this.classifyEntry(vtx));
395
+ }
396
+ }
397
+ if (isSwitch || branches.length < 2 || branches.some(graph_1.FunctionArgument.isEmpty)) {
398
+ acc.push(input_types_1.InputType.Constant, null);
399
+ }
400
+ acc.cds.push(...condition === undefined ? [] : this.dependencies(graph_1.FunctionArgument.getReference(condition), []));
401
+ return acc.build(call.id);
402
+ }
403
+ /** the arguments of a sanitizer it takes as code rather than escaping, see {@link InputClassifierConfig.templates} */
404
+ templateArguments(call) {
405
+ return (this.config.templates ?? []).filter(t => this.matches(call, [t.call])).flatMap(t => t.argName === '...'
406
+ ? call.args.filter(a => !graph_1.FunctionArgument.isNamed(a)).map(graph_1.FunctionArgument.getReference)
407
+ : [this.argumentReference(call, t.argIdx, t.argName)]);
408
+ }
409
+ /** the types and control dependencies of what `ref` yields, `unknown` when it cannot be classified */
410
+ dependencies(ref, unknown = [input_types_1.InputType.Unknown]) {
411
+ const c = this.classifyAt(ref);
412
+ return c ? [...c.types, ...c.cds ?? []] : unknown;
413
+ }
414
+ /** what a control dependency on the given id depends on: the condition of an `if` or `switch`, else the id itself */
415
+ conditionOf(id) {
416
+ const vtx = this.dfg.getVertex(id);
417
+ const condition = vertex_1.DfgVertex.isFunctionCall(vtx) ? conditionArgument(vtx) : undefined;
418
+ return condition === undefined ? id : graph_1.FunctionArgument.getReference(condition);
419
+ }
344
420
  classifyFunctionCall(call) {
345
421
  const linkedAccess = this.classifyLinkedObjectAccess(call);
346
422
  if (linkedAccess) {
347
423
  return this.classifyCdsAndReturn(call, linkedAccess);
348
424
  }
425
+ if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) || call.origin.includes(built_in_proc_name_1.BuiltInProcName.Switch)) {
426
+ return this.classifyCdsAndReturn(call, this.classifyBranches(call));
427
+ }
349
428
  const handed = this.passedOn(call);
350
429
  const passed = this.classifyAt(handed?.via === undefined ? undefined : graph_1.FunctionArgument.getReference(handed.via));
351
430
  if (passed) {
352
431
  return this.classifyCdsAndReturn(call, handed?.renamed ? { ...passed, id: call.id } : passed);
353
432
  }
354
- // a narrowing function returns a bounded value: either one of a specific argument's values (e.g. `match.arg`
355
- // -> its `choices`), or - with no bounding argument - a content-independent value like a count/index/logical
433
+ if (this.matches(call, this.config.sanitizers)) {
434
+ const acc = new ClassificationAccumulator();
435
+ acc.push(input_types_1.InputType.DerivedConstant);
436
+ this.templateArguments(call).forEach(t => acc.merge(this.classifyAt(t)));
437
+ return this.classifyCdsAndReturn(call, acc.build(call.id));
438
+ }
439
+ // a narrowing function returns one of a specific argument's values (e.g. `match.arg` -> its `choices`)
356
440
  for (const narrow of this.config.narrowing ?? []) {
357
441
  if (!this.matches(call, [narrow.call])) {
358
442
  continue;
359
443
  }
360
- if (narrow.argIdx === undefined) {
361
- return this.classifyCdsAndReturn(call, { id: call.id, types: [input_types_1.InputType.DerivedConstant], trace: input_types_1.InputTraceType.Pure });
362
- }
363
- const narrowed = this.classifyAt(this.argumentReference(call, narrow.argIdx, narrow.argName ?? ''));
444
+ const bound = this.argumentReference(call, narrow.argIdx, narrow.argName);
445
+ const narrowed = this.classifyAt(bound);
364
446
  if (narrowed) {
365
- return this.classifyCdsAndReturn(call, { ...narrowed, id: call.id });
447
+ /* which of the values it is depends on the other arguments */
448
+ const cds = call.args.map(graph_1.FunctionArgument.getReference).filter(a => a !== bound).flatMap(a => this.dependencies(a));
449
+ return this.classifyCdsAndReturn(call, { ...narrowed, id: call.id, cds: (0, arrays_1.uniqueArray)([...narrowed.cds ?? [], ...cds]) });
366
450
  }
367
451
  }
368
- if (!this.matches(call, this.config.pure)) {
452
+ const evaluates = this.matches(call, this.config.evaluating);
453
+ if (!evaluates && !this.matches(call, this.config.pure)) {
369
454
  const types = record_1.Record.values(input_types_1.InputType).filter(type => this.matches(call, this.config[type]));
370
455
  // if a File-typed call reads from a temp path, replace File with TempFile
371
456
  const readsFile = types.includes(input_types_1.InputType.File) && !types.includes(input_types_1.InputType.TempFile);
@@ -380,7 +465,20 @@ class InputClassifier {
380
465
  if (types.length === 0) {
381
466
  /* a call of something the code produced (a shiny `reactive()`) or defines yields what that produced or returns */
382
467
  const produced = this.classifyCallee(call) ?? this.classifyDefinitionResult(call);
383
- if (produced !== undefined) {
468
+ if (produced !== undefined && call.origin.includes(built_in_proc_name_1.BuiltInProcName.Try)) {
469
+ /* the handlers only answer for a failing block, which may just as well succeed */
470
+ const acc = new ClassificationAccumulator();
471
+ const block = this.argumentReference(call, 0, 'expr');
472
+ acc.merge(produced);
473
+ acc.merge(this.classifyAt(block));
474
+ /* and whether they answer depends on everything the block does */
475
+ const statements = block === undefined ? undefined : this.whole.getVertex(block);
476
+ for (const arg of vertex_1.DfgVertex.isFunctionCall(statements) && vertex_1.DfgVertex.hasOrigin(statements, built_in_proc_name_1.BuiltInProcName.ExpressionList) ? statements.args : []) {
477
+ acc.cds.push(...this.dependencies(graph_1.FunctionArgument.getReference(arg)));
478
+ }
479
+ return this.classifyCdsAndReturn(call, acc.build(call.id));
480
+ }
481
+ else if (produced !== undefined) {
384
482
  return this.classifyCdsAndReturn(call, { ...produced, id: call.id });
385
483
  }
386
484
  // if it is not pure, we cannot classify based on the inputs, in that case we do not know!
@@ -388,10 +486,18 @@ class InputClassifier {
388
486
  }
389
487
  return this.classifyCdsAndReturn(call, { id: call.id, types, trace: input_types_1.InputTraceType.Unknown });
390
488
  }
391
- const argTypes = [];
489
+ const argTypes = evaluates ? [input_types_1.InputType.Unknown] : [];
392
490
  const cdTypes = [];
393
- for (const arg of call.args.filter(graph_1.FunctionArgument.isNotEmpty)) {
394
- const classified = this.classifyAt(graph_1.FunctionArgument.getReference(arg));
491
+ const interpolated = this.templateReads(call);
492
+ /* cutting into what a sanitizer escaped undoes the escape */
493
+ const edits = this.matches(call, this.config.editing);
494
+ const of = edits && this.config.sanitizers !== undefined ? this.unsanitized ??= new InputClassifier(this.dfg, { ...this.config, sanitizers: undefined }, this.fullDfg, this.packages) : this;
495
+ for (const ref of (0, arrays_1.uniqueArray)([...call.args.filter(graph_1.FunctionArgument.isNotEmpty).map(graph_1.FunctionArgument.getReference), ...interpolated])) {
496
+ /* a function handed in (`sapply(x, function(i) runif(1))`) contributes what it returns */
497
+ const vtx = ref === undefined ? undefined : this.whole.getVertex(ref);
498
+ const fns = vtx === undefined || vertex_1.DfgVertex.isFunctionCall(vtx) ? [] : [...this.functionDefinitionsAt(ref)];
499
+ const classified = fns.length > 0 ? this.classifyExits(fns, ref)
500
+ : vertex_1.DfgVertex.isFunctionCall(vtx) && identifier_1.Identifier.getName(vtx.name) === '~' && (0, frame_reflection_1.hasEdgeOfType)(this.whole, call.id, vtx.id, edge_1.EdgeType.Calls) ? this.classifyFormula(vtx) : of.classifyAt(ref);
395
501
  argTypes.push(...classified?.types ?? [input_types_1.InputType.Unknown]);
396
502
  cdTypes.push(...classified?.cds ?? []);
397
503
  }
@@ -400,7 +506,7 @@ class InputClassifier {
400
506
  return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({
401
507
  id: call.id,
402
508
  types: constLike ? [input_types_1.InputType.DerivedConstant] : (0, arrays_1.uniqueArray)([...argTypes, input_types_1.InputType.DerivedConstant]),
403
- trace: constLike ? input_types_1.InputTraceType.Pure : input_types_1.InputTraceType.Known,
509
+ trace: constLike ? input_types_1.InputTraceType.Pure : evaluates || edits || interpolated.length > 0 ? input_types_1.InputTraceType.Unknown : input_types_1.InputTraceType.Known,
404
510
  cds: cdTypes.length > 0 ? (0, arrays_1.uniqueArray)(cdTypes) : undefined
405
511
  }));
406
512
  }
@@ -410,8 +516,22 @@ class InputClassifier {
410
516
  * when the call names no definition here or when none of them says anything about what it returns.
411
517
  */
412
518
  classifyDefinitionResult(call) {
519
+ return this.classifyExits(this.functionDefinitionsAt(call.id), call.id);
520
+ }
521
+ /** what a string template like `glue("{x}")` evaluates and reads, which is no argument, but flows in all the same */
522
+ templateReads(call) {
523
+ return call.origin.includes(built_in_proc_name_1.BuiltInProcName.StringTemplate) ? (0, frame_reflection_1.edgeTargets)(this.whole, call.id, edge_1.EdgeType.Reads).filter(t => this.whole.hasVertex(t) && !vertex_1.DfgVertex.hasOrigin(this.whole.getVertex(t), built_in_proc_name_1.BuiltInProcName.Library)) : [];
524
+ }
525
+ /** a formula called as a function (`purrr::map(x, ~ runif(1))`) yields what its body does */
526
+ classifyFormula(formula) {
413
527
  const acc = new ClassificationAccumulator();
414
- for (const fn of this.functionDefinitionsAt(call.id)) {
528
+ formula.args.forEach(a => acc.merge(this.classifyAt(graph_1.FunctionArgument.getReference(a))));
529
+ return acc.build(formula.id);
530
+ }
531
+ /** what the exit points of the given function definitions yield, see {@link classifyDefinitionResult} */
532
+ classifyExits(fns, id) {
533
+ const acc = new ClassificationAccumulator();
534
+ for (const fn of fns) {
415
535
  const definition = this.whole.getVertex(fn);
416
536
  for (const { nodeId } of vertex_1.DfgVertex.isFunctionDefinition(definition) ? definition.exitPoints : []) {
417
537
  for (const value of this.exitValues(nodeId)) {
@@ -428,7 +548,7 @@ class InputClassifier {
428
548
  if (acc.values.length === 0) {
429
549
  return undefined;
430
550
  }
431
- const built = acc.build(call.id);
551
+ const built = acc.build(id);
432
552
  return built.types.includes(input_types_1.InputType.Unknown) ? undefined : built;
433
553
  }
434
554
  /**
@@ -469,7 +589,11 @@ class InputClassifier {
469
589
  continue;
470
590
  }
471
591
  const classified = this.classifyAt(o.id) ?? this.classifyInFullGraph(o.id);
472
- if (classified !== undefined && !classified.types.includes(input_types_1.InputType.Unknown)) {
592
+ if (classified?.types.every(isConstantLike)) {
593
+ /* a constant held as a function (`get("readLines")`, a body set to quoted code) says nothing about what calling it yields */
594
+ return sourceOf(call.id, input_types_1.InputType.Unknown);
595
+ }
596
+ else if (classified !== undefined && !classified.types.includes(input_types_1.InputType.Unknown)) {
473
597
  return classified;
474
598
  }
475
599
  }
@@ -504,13 +628,35 @@ class InputClassifier {
504
628
  acc.merge(undefined);
505
629
  }
506
630
  }
631
+ if (this.mayBeRebound(vtx.id, origins.map(o => o.id))) {
632
+ acc.merge(undefined);
633
+ }
507
634
  return this.classifyCdsAndReturn(vtx, acc.build(vtx.id));
508
635
  }
636
+ /** what the default of a parameter yields when a call leaves the parameter out */
637
+ defaultTypes(id) {
638
+ const idMap = this.whole.idMap;
639
+ const param = idMap?.get(idMap.get(id)?.info.parent);
640
+ return r_parameter_1.RParameter.is(param) && param.defaultValue !== undefined ? this.classifyInFullGraph(param.defaultValue.info.id)?.types ?? [input_types_1.InputType.Unknown] : [];
641
+ }
509
642
  parameterType(id) {
510
643
  if (this.dfg.idMap?.get(id)?.info.role !== "param-n" /* RoleInParent.ParameterName */) {
511
644
  return undefined;
512
645
  }
513
- return this.matchWholeLinkedObject(id)?.type ?? input_types_1.InputType.Parameter;
646
+ return this.matchWholeLinkedObject(id)?.type ?? (this.isPlumberEndpointParameter(id) ? input_types_1.InputType.User : input_types_1.InputType.Parameter);
647
+ }
648
+ /** plumber hands each parameter of a function with a `#*` route annotation what a request sends */
649
+ isPlumberEndpointParameter(id) {
650
+ const idMap = this.whole.idMap;
651
+ for (const node of model_1.RNode.iterateParents(idMap.get(id), idMap)) {
652
+ if (node.info.adToks?.some(t => r_comment_1.RComment.is(t) && PlumberEndpoint.test(t.lexeme ?? ''))) {
653
+ return true;
654
+ }
655
+ else if (node.info.parent === undefined || (r_function_definition_1.RFunctionDefinition.is(node) && node.info.adToks?.length)) {
656
+ return false;
657
+ }
658
+ }
659
+ return false;
514
660
  }
515
661
  /**
516
662
  * Resolves a variable definition or use origin, handling the special cases of
@@ -529,7 +675,7 @@ class InputClassifier {
529
675
  const callers = onCall.map(t => this.classifyInFullGraph(t)).filter(assert_1.isNotUndefined);
530
676
  const known = callers.filter(c => !c.types.includes(input_types_1.InputType.Unknown));
531
677
  known.forEach(c => acc.merge(c));
532
- if (known.length > 0 && known.length === callers.length) {
678
+ if (known.length > 0 && known.length === callers.length && !this.escapes(v.id)) {
533
679
  return;
534
680
  }
535
681
  acc.push(input_types_1.InputType.Scope);
@@ -538,15 +684,50 @@ class InputClassifier {
538
684
  const parameter = vertex_1.DfgVertex.isVariableDefinition(v) ? this.parameterType(v.id) : undefined;
539
685
  if (parameter !== undefined) {
540
686
  acc.push(parameter);
687
+ acc.types.push(...this.defaultTypes(v.id));
541
688
  }
542
689
  else {
543
690
  acc.merge(this.classifyEntry(v));
544
691
  }
545
692
  }
693
+ /** whether the function binding the parameter is used as a value, so it may be called with anything the visible callers do not pass */
694
+ escapes(parameter) {
695
+ const idMap = this.whole.idMap;
696
+ const fn = idMap === undefined ? undefined : model_1.RNode.iterateParents(idMap.get(parameter), idMap).find(r_function_definition_1.RFunctionDefinition.is);
697
+ const holders = fn === undefined ? [] : (0, frame_reflection_1.edgeSources)(this.whole, fn.info.id, edge_1.EdgeType.DefinedBy);
698
+ return holders.length === 0 || holders.some(h => (0, frame_reflection_1.edgeSources)(this.whole, h, edge_1.EdgeType.Reads)
699
+ .some(r => !r_function_call_1.RFunctionCall.is(idMap?.get(r)) || !(0, frame_reflection_1.hasEdgeOfType)(this.whole, r, fn?.info.id, edge_1.EdgeType.Calls)));
700
+ }
701
+ /** whether code flowR cannot follow (`load`, `eval`, `e$x <-`) may rebind the variable before the use */
702
+ mayBeRebound(use, definitions) {
703
+ const idMap = this.whole.idMap;
704
+ const node = idMap.get(use);
705
+ const fn = model_1.RNode.iterateParents(node, idMap).find(r_function_definition_1.RFunctionDefinition.is);
706
+ const within = (id) => fn !== undefined && model_1.RNode.iterateParents(idMap.get(id), idMap).some(p => p === fn);
707
+ const local = definitions.length > 0 && definitions.every(within);
708
+ /* an unconditional definition after the effect binds anew */
709
+ const overwritten = (e) => definitions.length > 0 && definitions.every(d => !this.whole.getVertex(d)?.cds?.length
710
+ && runsAfter(idMap.get(idMap.get(d)?.info.parent), idMap.get(e), idMap));
711
+ return this.rebinders().some(([e, fields]) => (fields === undefined || fields.some(f => f === undefined || f === model_1.RNode.lexeme(node)))
712
+ && (!local || within(e)) && !overwritten(e) && !((fn === undefined || local) && runsAfter(idMap.get(e), node, idMap)));
713
+ }
714
+ /** the unknown side effects, and the replacements `e$x <- v` with the names they may bind (`undefined` for any) */
715
+ rebinders() {
716
+ const name = (a) => {
717
+ const ref = graph_1.FunctionArgument.getReference(a);
718
+ return ref === undefined ? undefined : this.extractConstantValue(ref) ?? model_1.RNode.lexeme(this.whole.idMap?.get(ref));
719
+ };
720
+ return this.rebinding ??= [
721
+ ...[...this.whole.unknownSideEffects].filter(e => !graph_1.UnknownSideEffect.isLinked(e)).map(e => [graph_1.UnknownSideEffect.id(e), undefined]),
722
+ ...this.whole.verticesOfType(vertex_1.VertexType.FunctionCall)
723
+ .filter(([, c]) => c.origin.includes(built_in_proc_name_1.BuiltInProcName.Replacement) && FieldReplacements.has(identifier_1.Identifier.getName(c.name)))
724
+ .map(([id, c]) => [id, c.args.slice(1, -1).map(name)])
725
+ ];
726
+ }
546
727
  classifyVariableDefinition(vtx) {
547
728
  const parameter = this.parameterType(vtx.id);
548
729
  if (parameter !== undefined) {
549
- return this.classifyCdsAndReturn(vtx, sourceOf(vtx.id, parameter));
730
+ return this.classifyCdsAndReturn(vtx, { ...sourceOf(vtx.id, parameter), types: (0, arrays_1.uniqueArray)([parameter, ...this.defaultTypes(vtx.id)]) });
550
731
  }
551
732
  else if (!vtx.source?.length) {
552
733
  // fallback to unknown if we cannot find the value
@@ -559,10 +740,7 @@ class InputClassifier {
559
740
  classifyCdsAndReturn(vtx, src) {
560
741
  if (vtx.cds) {
561
742
  /* running only once a call forces it is no condition on the data */
562
- const cds = (0, arrays_1.uniqueArray)(vtx.cds.filter(c => c.byPromise !== true).flatMap(c => {
563
- const e = this.classifyAt(c.id);
564
- return e ? [...e.types, ...e.cds ?? []] : [];
565
- }).concat(src.cds ?? []));
743
+ const cds = (0, arrays_1.uniqueArray)(vtx.cds.filter(c => c.byPromise !== true).flatMap(c => this.dependencies(this.conditionOf(c.id), [])).concat(src.cds ?? []));
566
744
  if (cds.length > 0) {
567
745
  src.cds = cds;
568
746
  }
@@ -574,6 +752,13 @@ class InputClassifier {
574
752
  return src;
575
753
  }
576
754
  }
755
+ /** the condition of an `if` or `switch`; with named arguments to an `if`, we do not know which it is */
756
+ function conditionArgument(call) {
757
+ if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Switch)) {
758
+ return call.args.find(a => graph_1.FunctionArgument.hasName(a, 'EXPR')) ?? call.args.find(a => !graph_1.FunctionArgument.isNamed(a));
759
+ }
760
+ return call.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) && !call.args.some(graph_1.FunctionArgument.isNamed) ? call.args[0] : undefined;
761
+ }
577
762
  /** the function definitions the given node is nested in, innermost first */
578
763
  function* enclosingFunctions(node, idMap) {
579
764
  for (const parent of model_1.RNode.iterateParents(node, idMap)) {
@@ -595,6 +780,19 @@ function isBoundAsLinkedObject(node, obj, idMap) {
595
780
  }
596
781
  return false;
597
782
  }
783
+ const PlumberEndpoint = /^#\*\s*@(?:get|post|put|delete|patch|head|options|any|use)\b/i;
784
+ /** the replacements that may write a binding of an environment, as `e$x <- v` does */
785
+ const FieldReplacements = new Set(['$<-', '[[<-']);
786
+ const LoopTypes = new Set([type_1.RType.ForLoop, type_1.RType.WhileLoop, type_1.RType.RepeatLoop]);
787
+ /** whether `later` surely runs after `node`: later in the same file, in no shared loop, not deferred into a function apart from it */
788
+ function runsAfter(later, node, idMap) {
789
+ const [first, second] = [model_1.RNode.span(node), model_1.RNode.span(later)];
790
+ if (first === undefined || second === undefined || node?.info.file !== later?.info.file || !(range_1.SourceRange.startsCompletelyBefore(first, second) || range_1.SourceRange.isSubsetOf(first, second))) {
791
+ return false;
792
+ }
793
+ const around = new Set(model_1.RNode.iterateParents(later, idMap));
794
+ return model_1.RNode.iterateParents(node, idMap).every(p => r_function_definition_1.RFunctionDefinition.is(p) ? around.has(p) : !LoopTypes.has(p.type) || !around.has(p));
795
+ }
598
796
  function declarationKey(object, field) {
599
797
  return `${object}\u0000${field}`;
600
798
  }
@@ -632,7 +830,7 @@ function classifyInput(id, dfg, config, fullDfg, packages) {
632
830
  }
633
831
  const ret = [];
634
832
  for (const arg of vtx.args) {
635
- const entry = c.classifyAt(graph_1.FunctionArgument.getReference(arg));
833
+ const entry = c.classifyArgument(vtx, graph_1.FunctionArgument.getReference(arg));
636
834
  if (entry === undefined) {
637
835
  continue;
638
836
  }
@@ -12,6 +12,7 @@ const log_1 = require("../util/log");
12
12
  const init_1 = require("./init");
13
13
  const convert_values_1 = require("./lang-4.x/convert-values");
14
14
  const retriever_1 = require("./retriever");
15
+ const secure_mode_1 = require("../util/secure-mode");
15
16
  const executorLog = log_1.log.getSubLogger({ name: 'RShellExecutor' });
16
17
  /**
17
18
  * This is a synchronous alternative to the {@link RShell}.
@@ -69,6 +70,7 @@ class RShellExecutor {
69
70
  run(command, returnErr = false) {
70
71
  command += ';base::quit()';
71
72
  (0, log_1.expensiveTrace)(executorLog, () => `> ${JSON.stringify(command)}`);
73
+ secure_mode_1.SecureMode.guard('starting R', this.options.pathToRExecutable);
72
74
  const returns = (0, child_process_1.spawnSync)(this.options.pathToRExecutable, this.options.commandLineOptions, {
73
75
  env: this.options.env,
74
76
  cwd: this.options.cwd,
package/r-bridge/shell.js CHANGED
@@ -48,6 +48,7 @@ const fs_1 = __importDefault(require("fs"));
48
48
  const init_1 = require("./init");
49
49
  const convert_values_1 = require("./lang-4.x/convert-values");
50
50
  const retriever_1 = require("./retriever");
51
+ const secure_mode_1 = require("../util/secure-mode");
51
52
  exports.DEFAULT_OUTPUT_COLLECTOR_CONFIGURATION = {
52
53
  from: 'stdout',
53
54
  postamble: `🐧${'-'.repeat(5)}🐧`,
@@ -302,6 +303,7 @@ class RShellSession {
302
303
  collectionTimeout;
303
304
  requestQueue = Promise.resolve();
304
305
  constructor(options, log) {
306
+ secure_mode_1.SecureMode.guard('starting R', options.pathToRExecutable);
305
307
  this.bareSession = (0, child_process_1.spawn)(options.pathToRExecutable, options.commandLineOptions, {
306
308
  env: options.env,
307
309
  cwd: options.cwd,
@@ -95,7 +95,6 @@ exports.Enrichments = {
95
95
  ast: await data.normalize()
96
96
  },
97
97
  enrichElement: async (e, s, analyzer, args, prev) => {
98
- // we don't resolve aliases here yet!
99
98
  const content = { targets: [] };
100
99
  const shared = s.enrichmentContent(Enrichment.CallTargets);
101
100
  const df = shared?.dfg ?? await analyzer.dataflow();
@@ -134,8 +133,11 @@ exports.Enrichments = {
134
133
  return qualifyIdentifier([o], node_id_1.NodeId.recoverName(o.id, n.idMap)) ?? String(o.id);
135
134
  }
136
135
  return { node: n.idMap.get(o.id) };
137
- case 3 /* OriginType.BuiltInFunctionOrigin */:
138
- return qualifyIdentifier([o], o.fn.name);
136
+ case 3 /* OriginType.BuiltInFunctionOrigin */: {
137
+ /* an alias (`s <- system; s()`) calls the built-in it is linked to rather than its own name */
138
+ const linked = node_id_1.NodeId.isBuiltIn(o.proc) ? node_id_1.NodeId.toPkgFn(o.proc)?.[1] ?? node_id_1.NodeId.fromBuiltIn(o.proc) : undefined;
139
+ return qualifyIdentifier([o], linked === undefined || linked === identifier_1.Identifier.getName(o.fn.name) ? o.fn.name : linked);
140
+ }
139
141
  default:
140
142
  return undefined;
141
143
  }
@@ -18,6 +18,7 @@ const slice_direction_1 = require("../../util/slice-direction");
18
18
  const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
19
19
  const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
20
20
  const r_expression_list_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
21
+ const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
21
22
  exports.slicerLogger = log_1.log.getSubLogger({ name: 'slicer' });
22
23
  /**
23
24
  * Computes the node ids to include in a static slice, starting from the given seed ids.
@@ -57,9 +58,7 @@ function staticSlice(options) {
57
58
  // retrieve the minimum nesting of all nodes to only add control dependencies if they are "part" of the current execution
58
59
  minNesting = Math.min(minNesting, idMap.get(startId)?.info.nest ?? minNesting);
59
60
  sliceSeedIds.add(startId);
60
- if (trackCallees) {
61
- openBodiesAround(startId);
62
- }
61
+ openBodiesAround(startId);
63
62
  }
64
63
  /* include all the implicit side effects that we have to consider as we are unable to narrow them down */
65
64
  for (const id of graph.unknownSideEffects) {
@@ -91,7 +90,7 @@ function staticSlice(options) {
91
90
  const strictlyEnclosing = model_1.RNode.strictlyEnclosingFunction(id, idMap);
92
91
  if (!enclosingHandled.has(strictlyEnclosing)) {
93
92
  enclosingHandled.add(strictlyEnclosing);
94
- definitionWithHolders(strictlyEnclosing, idMap, graph).forEach(outer => enqueue(outer, emptyEnv, basePrint));
93
+ definitionWithHolders(strictlyEnclosing, idMap, graph, trackCallees ? undefined : openedBodies).forEach(outer => enqueue(outer, emptyEnv, basePrint));
95
94
  }
96
95
  // includeCallees: note the enclosing function definition (if any) so its callees can be considered once the body slice is complete
97
96
  if (trackCallees) {
@@ -100,9 +99,11 @@ function staticSlice(options) {
100
99
  pendingCalleeBoundaries.set(enclosingFnDef, [baseEnvironment, baseEnvFingerprint]);
101
100
  }
102
101
  }
103
- /* control dependencies count only in a different call or at least at the nesting of the seeds */
102
+ /* control dependencies count only in a different call or at least at the nesting of the seeds; a read or a constant
103
+ is the same value whether or not its promise is forced, only what runs within one depends on its call */
104
104
  const topLevel = graph.isRoot(id) || sliceSeedIds.has(id);
105
- for (const cd of currentVertex.cds?.filter(({ id }) => !queue.hasId(id)) ?? []) {
105
+ const plain = vertex_1.DfgVertex.isUse(currentVertex) || vertex_1.DfgVertex.isValue(currentVertex);
106
+ for (const cd of currentVertex.cds?.filter(cd => !(plain && cd.byPromise) && !queue.hasId(cd.id)) ?? []) {
106
107
  if (!topLevel || (idMap.get(cd.id)?.info.nest ?? 0) >= minNesting) {
107
108
  queue.add(cd.id, baseEnvironment, baseEnvFingerprint, false);
108
109
  }
@@ -181,15 +182,19 @@ function outputWithinCallees(seeds, graph) {
181
182
  }
182
183
  return found;
183
184
  }
184
- /** The function `definition` and what holds it, up to its statement, as a body only runs as part of its definition. */
185
- function definitionWithHolders(definition, idMap, graph) {
185
+ /**
186
+ * The function `definition` and what holds it, up to its statement, as a body only runs as part of its definition.
187
+ * The `opened` bodies the slice starts in stop at an argument holding them or handed to a call of them: that call is a caller.
188
+ */
189
+ function definitionWithHolders(definition, idMap, graph, opened) {
186
190
  const definitionNode = definition === undefined ? undefined : idMap.get(definition);
187
191
  if (definitionNode === undefined) {
188
192
  return [];
189
193
  }
190
194
  const outer = [definitionNode.info.id];
191
195
  for (const node of model_1.RNode.iterateParents(definitionNode, idMap)) {
192
- if (r_function_definition_1.RFunctionDefinition.is(node) || (r_expression_list_1.RExpressionList.is(node) && node.grouping?.[0].lexeme !== '(')) {
196
+ if (r_function_definition_1.RFunctionDefinition.is(node) || (r_expression_list_1.RExpressionList.is(node) && node.grouping?.[0].lexeme !== '(')
197
+ || (opened !== undefined && r_argument_1.RArgument.is(node) && (opened.has(definitionNode.info.id) || (0, frame_reflection_1.edgeTargets)(graph, node.info.parent ?? '', edge_1.EdgeType.Calls).some(fn => opened.has(fn))))) {
193
198
  break;
194
199
  }
195
200
  if (graph.hasVertex(node.info.id)) {
package/util/files.d.ts CHANGED
@@ -47,6 +47,12 @@ export declare function readLineByLine(filePath: string, onLine: (line: Buffer,
47
47
  * See {@link readLineByLine} for an asynchronous version.
48
48
  */
49
49
  export declare function readLineByLineSync(filePath: string, onLine: (line: Buffer, lineNumber: number) => void, maxLines?: number): boolean;
50
+ /**
51
+ * Joins `base` with a single path segment taken from an untrusted source (e.g., a file name, release tag, or hash read
52
+ * from a downloaded or project-supplied file), refusing every segment that could name anything outside `base`.
53
+ * @throws if the segment is empty, `.` or `..`, or contains a path separator or NUL
54
+ */
55
+ export declare function joinUntrustedSegment(base: string, segment: string): string;
50
56
  /**
51
57
  * Chops off the last part of the given directory path after a path separator, essentially returning the path's parent directory.
52
58
  * If an absolute path is passed, the returned path is also absolute.
package/util/files.js CHANGED
@@ -42,6 +42,7 @@ exports.getAllFilesSync = getAllFilesSync;
42
42
  exports.allRFiles = allRFiles;
43
43
  exports.readLineByLine = readLineByLine;
44
44
  exports.readLineByLineSync = readLineByLineSync;
45
+ exports.joinUntrustedSegment = joinUntrustedSegment;
45
46
  exports.getParentDirectory = getParentDirectory;
46
47
  exports.commonDirectory = commonDirectory;
47
48
  exports.relativeTo = relativeTo;
@@ -190,6 +191,17 @@ function readLineByLineSync(filePath, onLine, maxLines = Infinity) {
190
191
  }
191
192
  return true;
192
193
  }
194
+ /**
195
+ * Joins `base` with a single path segment taken from an untrusted source (e.g., a file name, release tag, or hash read
196
+ * from a downloaded or project-supplied file), refusing every segment that could name anything outside `base`.
197
+ * @throws if the segment is empty, `.` or `..`, or contains a path separator or NUL
198
+ */
199
+ function joinUntrustedSegment(base, segment) {
200
+ if (segment === '' || segment === '.' || segment === '..' || /[/\\\0]/.test(segment) || path_1.default.isAbsolute(segment)) {
201
+ throw new Error(`Refusing the untrusted path segment ${JSON.stringify(segment)}`);
202
+ }
203
+ return path_1.default.join(base, segment);
204
+ }
193
205
  /**
194
206
  * Chops off the last part of the given directory path after a path separator, essentially returning the path's parent directory.
195
207
  * If an absolute path is passed, the returned path is also absolute.