@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
package/config.js CHANGED
@@ -20,6 +20,15 @@ const project_kind_1 = require("./project/context/project-kind");
20
20
  const gas_1 = require("./gas");
21
21
  const input_types_1 = require("./queries/catalog/input-sources-query/input-types");
22
22
  const arrays_1 = require("./util/collections/arrays");
23
+ const secure_mode_1 = require("./util/secure-mode");
24
+ /** Marks an option that decides what flowR executes or loads, it is dropped from untrusted configs (see {@link FlowrConfig.fromFile}). */
25
+ function securitySensitive(schema) {
26
+ return schema.meta({ securitySensitive: true });
27
+ }
28
+ /** Marks an option holding regular expressions, which the {@link SecureMode} drops from every config (ReDoS). */
29
+ function regexOption(schema) {
30
+ return schema.meta({ regex: true });
31
+ }
23
32
  var VariableResolve;
24
33
  (function (VariableResolve) {
25
34
  /** Don't resolve constants at all */
@@ -415,7 +424,7 @@ exports.FlowrConfig = {
415
424
  classification: joi_1.default.object({
416
425
  shinyDescriptionTypes: joi_1.default.array().items(joi_1.default.string()).optional().description('DESCRIPTION Type: values that mark a shiny app.'),
417
426
  shinyEntryFiles: joi_1.default.array().items(joi_1.default.string()).optional().description('File names a shiny app is assembled from.'),
418
- shinyUsagePattern: joi_1.default.string().optional().description('Regex source evidencing shiny usage in an entry file.'),
427
+ shinyUsagePattern: regexOption(joi_1.default.string().optional()).description('Regex source evidencing shiny usage in an entry file.'),
419
428
  notebookExtensions: joi_1.default.array().items(joi_1.default.string()).optional().description('File extensions marking a notebook.')
420
429
  }).optional().description('Overrides for the signals flowR uses to classify the project kind.')
421
430
  }).description('Project specific configuration options.'),
@@ -434,12 +443,12 @@ exports.FlowrConfig = {
434
443
  .description('Overwrite (parts of) the configuration depending on the project kind flowR detects, e.g. to give a shiny app its implicit sources.'),
435
444
  engines: joi_1.default.array().items(joi_1.default.alternatives(joi_1.default.object({
436
445
  type: joi_1.default.string().required().valid('tree-sitter').description('Use the tree sitter engine.'),
437
- wasmPath: joi_1.default.string().optional().description('The path to the tree-sitter-r WASM binary to use. If this is undefined, this uses the default path.'),
438
- treeSitterWasmPath: joi_1.default.string().optional().description('The path to the tree-sitter WASM binary to use. If this is undefined, this uses the default path.'),
446
+ wasmPath: securitySensitive(joi_1.default.string().optional()).description('The path to the tree-sitter-r WASM binary to use. If this is undefined, this uses the default path.'),
447
+ treeSitterWasmPath: securitySensitive(joi_1.default.string().optional()).description('The path to the tree-sitter WASM binary to use. If this is undefined, this uses the default path.'),
439
448
  lax: joi_1.default.boolean().optional().description('Whether to use the lax parser for parsing R code (allowing for syntax errors). If this is undefined, the strict parser will be used.')
440
449
  }).description('The configuration for the tree sitter engine.'), joi_1.default.object({
441
450
  type: joi_1.default.string().required().valid('r-shell').description('Use the R shell engine.'),
442
- rPath: joi_1.default.string().optional().description('The path to the R executable to use. If this is undefined, this uses the default path.'),
451
+ rPath: securitySensitive(joi_1.default.string().optional()).description('The path to the R executable to use. If this is undefined, this uses the default path.'),
443
452
  pipeBind: joi_1.default.boolean().optional().description('Whether to enable R\'s experimental pipe-bind operator "=>" by setting _R_USE_PIPEBIND_ for the R session (default false); R itself keeps this off by default, as it is experimental and has never shipped in a release version of R.')
444
453
  }).description('The configuration for the R shell engine.'))).description('The engine or set of engines to use for interacting with R code. An empty array means all available engines will be used.'),
445
454
  defaultEngine: joi_1.default.string().optional().valid('tree-sitter', 'r-shell').description('The default engine to use for interacting with R code. If this is undefined, an arbitrary engine from the specified list will be used.'),
@@ -458,16 +467,16 @@ exports.FlowrConfig = {
458
467
  linkPackageCalls: joi_1.default.boolean().optional().description('Add a lightweight Reads edge from a resolved package call to its signature-database function vertex (default false).'),
459
468
  linkDescriptionDependencies: joi_1.default.boolean().optional().description('Eagerly attach the namespaces of the project\'s declared DESCRIPTION dependencies (Imports/Depends) so their exports resolve without an explicit library() (default false).'),
460
469
  warmInBackground: joi_1.default.boolean().optional().description('Decompress the hot shards (base + most-downloaded) in a background task on startup so the first library() lookup is warm (default false; for long-running servers/REPLs).'),
461
- additionalPaths: joi_1.default.array().items(joi_1.default.string()).optional().description('Extra directories or bundle/manifest files searched for signature databases (alongside the shipped default and $FLOWR_SIGDB_DIR); a downloaded full-history bundle placed here is mounted automatically.'),
462
- downloadRepo: joi_1.default.string().optional().description('GitHub owner/repo the full-history bundle is downloaded from via ":signature download" (default "flowr-analysis/flowr", release tag "sigdb-v<flowR-version>").'),
470
+ additionalPaths: securitySensitive(joi_1.default.array().items(joi_1.default.string()).optional()).description('Extra directories or bundle/manifest files searched for signature databases (alongside the shipped default and $FLOWR_SIGDB_DIR); a downloaded full-history bundle placed here is mounted automatically.'),
471
+ downloadRepo: securitySensitive(joi_1.default.string().optional()).description('GitHub owner/repo the full-history bundle is downloaded from via ":signature download" (default "flowr-analysis/flowr", release tag "sigdb-v<flowR-version>").'),
463
472
  autoSync: joi_1.default.boolean().optional().description('On startup, re-download shards whose committed sigdb.remote.json hash no longer matches the cache, in the background (default false; opt-in network sync after a git pull).'),
464
473
  installedLibrary: joi_1.default.object({
465
474
  enabled: joi_1.default.boolean().required().description('Recover packages no signature database knows from their installed copy (default false).'),
466
- paths: joi_1.default.array().items(joi_1.default.string()).optional().description('Library directories to search; when empty they are discovered from the environment and the project.'),
475
+ paths: securitySensitive(joi_1.default.array().items(joi_1.default.string()).optional()).description('Library directories to search; when empty they are discovered from the environment and the project.'),
467
476
  useEnvironment: joi_1.default.boolean().optional().description('Search the libraries R_LIBS_USER/R_LIBS/R_LIBS_SITE name (default true).'),
468
477
  useProjectLibrary: joi_1.default.boolean().optional().description('Search a project-local renv/packrat library (default true).'),
469
478
  maxDepth: joi_1.default.number().optional().description('How far to descend into the nested layout of a project-local library (default 3).'),
470
- packages: joi_1.default.array().items(joi_1.default.string()).optional().description('Only recover packages whose name matches one of these regular expressions; empty means any.')
479
+ packages: regexOption(joi_1.default.array().items(joi_1.default.string()).optional()).description('Only recover packages whose name matches one of these regular expressions; empty means any.')
471
480
  }).optional().description('Recovering packages no signature database knows from the copy installed on this machine.'),
472
481
  blobCacheBudgetMb: joi_1.default.number().min(0).optional().description('How many MiB of decoded package blobs every open bundle may hold together (default 16).'),
473
482
  versionSelection: joi_1.default.string().valid(...Object.values(VersionSelection)).optional().description('When a project constrains a dependency, resolve to the newest (default), oldest, or system-installed version satisfying it; system needs R and falls back to newest. Base-R packages always resolve against the assumed R version.'),
@@ -488,7 +497,7 @@ exports.FlowrConfig = {
488
497
  inferWorkingDirectory: joi_1.default.string().valid(...Object.values(InferWorkingDirectory)).description('Try to infer the working directory from the main or any script to analyze.'),
489
498
  searchPath: joi_1.default.array().items(joi_1.default.string()).description('Additionally search in these paths.'),
490
499
  repeatedSourceLimit: joi_1.default.number().optional().description('How often the same file can be sourced within a single run? Please be aware: in case of cyclic sources this may not reach a fixpoint so give this a sensible limit.'),
491
- applyReplacements: joi_1.default.array().items(joi_1.default.object()).description('Provide name replacements for loaded files'),
500
+ applyReplacements: regexOption(joi_1.default.array().items(joi_1.default.object())).description('Provide name replacements for loaded files'),
492
501
  assumeFilesExist: joi_1.default.boolean().optional().description('Assume a sourced file is always there, making what it defines certain instead of conditional on the source call.')
493
502
  }).optional().description('If lax source calls are active, flowR searches for sourced files much more freely, based on the configurations you give it. This option is only in effect if `ignoreSourceCalls` is set to false.'),
494
503
  slicer: joi_1.default.object({
@@ -560,9 +569,15 @@ exports.FlowrConfig = {
560
569
  /**
561
570
  * Parses the given JSON string as a flowR config file, returning the resulting config object if the parsing and validation were successful, or `undefined` if there was an error.
562
571
  */
563
- parse(jsonString) {
572
+ parse(jsonString, trusted = true) {
564
573
  try {
565
574
  const parsed = JSON.parse(jsonString);
575
+ const dropped = trusted && !secure_mode_1.SecureMode.isEnabled() ? [] : exports.FlowrConfig.dropUntrusted(parsed);
576
+ if (dropped.length > 0) {
577
+ console.warn(secure_mode_1.SecureMode.isEnabled()
578
+ ? `[flowR] Ignoring ${dropped.join(', ')}, the secure mode does not allow them in any config.`
579
+ : `[flowR] Ignoring ${dropped.join(', ')} from the project config, pass --config-file or --trust-config to use them.`);
580
+ }
566
581
  const validate = exports.FlowrConfig.Schema.validate(parsed);
567
582
  if (!validate.error) {
568
583
  // assign default values to all config options except for the specified ones
@@ -577,6 +592,23 @@ exports.FlowrConfig = {
577
592
  log_1.log.error(`Failed to parse config ${jsonString}: ${e.message}`);
578
593
  }
579
594
  },
595
+ /** Paths (`*` matching any key) of all {@link securitySensitive} options, also within `specializeConfig`. */
596
+ securitySensitivePaths() {
597
+ return taggedPaths('securitySensitive');
598
+ },
599
+ /** Paths of all {@link regexOption} options, see {@link FlowrConfig.securitySensitivePaths}. */
600
+ regexPaths() {
601
+ return taggedPaths('regex');
602
+ },
603
+ /** Removes all {@link FlowrConfig.securitySensitivePaths} from the raw config (in place), returns the removed paths. */
604
+ dropSecuritySensitive(raw) {
605
+ return exports.FlowrConfig.securitySensitivePaths().flatMap(p => dropPath(raw, p, ''));
606
+ },
607
+ /** Like {@link FlowrConfig.dropSecuritySensitive}, but in {@link SecureMode} also drops the {@link FlowrConfig.regexPaths}. */
608
+ dropUntrusted(raw) {
609
+ const dropped = exports.FlowrConfig.dropSecuritySensitive(raw);
610
+ return secure_mode_1.SecureMode.isEnabled() ? [...dropped, ...exports.FlowrConfig.regexPaths().flatMap(p => dropPath(raw, p, ''))] : dropped;
611
+ },
580
612
  /**
581
613
  * Creates a new flowr config that has the updated values.
582
614
  */
@@ -596,11 +628,15 @@ exports.FlowrConfig = {
596
628
  * Please note that you can also use this without a path parameter to
597
629
  * infer the config from flowR's default locations.
598
630
  * This is mostly useful for user-facing features.
631
+ * A relative `configFile` is searched for in the working directory and its parents. That file belongs to the analyzed
632
+ * project, so its {@link securitySensitive} options are dropped unless `trustProjectConfig` is set.
599
633
  */
600
- fromFile(configFile, configWorkingDirectory = process.cwd()) {
634
+ fromFile(configFile, configWorkingDirectory = process.cwd(), trustProjectConfig = false) {
601
635
  let config;
602
636
  try {
603
- config = loadConfigFromFile(configFile, configWorkingDirectory);
637
+ // the secure mode never searches for a project config
638
+ const searched = configFile !== undefined && !path_1.default.isAbsolute(configFile);
639
+ config = loadConfigFromFile(searched && secure_mode_1.SecureMode.isEnabled() ? undefined : configFile, configWorkingDirectory, trustProjectConfig);
604
640
  }
605
641
  catch (e) {
606
642
  log_1.log.error(`Failed to load config: ${e.message}`);
@@ -740,7 +776,48 @@ function persistSigDbPathToGlobalConfig(dbPath) {
740
776
  fs_1.default.writeFileSync(file, JSON.stringify(raw, null, '\t') + '\n');
741
777
  return file;
742
778
  }
743
- function loadConfigFromFile(configFile, workingDirectory) {
779
+ const taggedPathsCache = new Map();
780
+ function taggedPaths(meta) {
781
+ let paths = taggedPathsCache.get(meta);
782
+ if (paths === undefined) {
783
+ const base = collectTaggedPaths(exports.FlowrConfig.Schema.describe(), meta);
784
+ paths = [...base, ...base.map(p => ['specializeConfig', '*', ...p])];
785
+ taggedPathsCache.set(meta, paths);
786
+ }
787
+ return paths;
788
+ }
789
+ function collectTaggedPaths(d, meta, at = []) {
790
+ if (!d) {
791
+ return [];
792
+ }
793
+ else if (d.metas?.some(m => m[meta] === true)) {
794
+ return [[...at]];
795
+ }
796
+ return [
797
+ ...Object.entries(d.keys ?? {}).flatMap(([k, v]) => collectTaggedPaths(v, meta, [...at, k])),
798
+ ...(d.items ?? []).flatMap(i => collectTaggedPaths(i, meta, [...at, '*'])),
799
+ ...(d.matches ?? []).flatMap(m => collectTaggedPaths(m.schema, meta, at))
800
+ ];
801
+ }
802
+ function dropPath(obj, path, at) {
803
+ if (obj === null || typeof obj !== 'object' || path.length === 0) {
804
+ return [];
805
+ }
806
+ const [head, ...rest] = path;
807
+ const record = obj;
808
+ const dropped = [];
809
+ for (const key of head === '*' ? Object.keys(record) : Object.hasOwn(record, head) ? [head] : []) {
810
+ const next = at === '' ? key : `${at}.${key}`;
811
+ if (rest.length > 0) {
812
+ dropped.push(...dropPath(record[key], rest, next));
813
+ }
814
+ else if (Reflect.deleteProperty(record, key)) {
815
+ dropped.push(next);
816
+ }
817
+ }
818
+ return dropped;
819
+ }
820
+ function loadConfigFromFile(configFile, workingDirectory, trustProjectConfig) {
744
821
  if (configFile !== undefined) {
745
822
  if (path_1.default.isAbsolute(configFile) && fs_1.default.existsSync(configFile)) {
746
823
  log_1.log.trace(`Found config at ${configFile} (absolute)`);
@@ -755,7 +832,7 @@ function loadConfigFromFile(configFile, workingDirectory) {
755
832
  const configPath = path_1.default.join(searchPath, configFile);
756
833
  if (fs_1.default.existsSync(configPath)) {
757
834
  log_1.log.trace(`Found config at ${configPath}`);
758
- const ret = exports.FlowrConfig.parse(fs_1.default.readFileSync(configPath, { encoding: 'utf-8' }));
835
+ const ret = exports.FlowrConfig.parse(fs_1.default.readFileSync(configPath, { encoding: 'utf-8' }), trustProjectConfig);
759
836
  if (ret) {
760
837
  log_1.log.info(`Using config ${JSON.stringify(ret)}`);
761
838
  return ret;
@@ -137,10 +137,13 @@ export declare enum SemanticCallTag {
137
137
  Prints = "prints",
138
138
  /**
139
139
  * the result is bounded no matter what flows in: a count, an index, a logical, or one of the values of the
140
- * argument marked {@link ArgProp.Bounds}. So nothing an argument carries reaches the result, which is what
141
- * lets the input-sources query stop tracing at `length(x)` or `match.arg(arg, choices)`.
140
+ * argument marked {@link ArgProp.Bounds}. So no content of an argument reaches the result, which is what
141
+ * lets the input-sources query trace `match.arg(arg, choices)` to its `choices` alone; a count still
142
+ * depends on what it counts, so `length(readLines(f))` keeps its file input.
142
143
  */
143
144
  Narrows = "narrows-args",
145
+ /** cuts or replaces parts of a string (`gsub`, `substr`), so what an escaping function made of it no longer holds */
146
+ Edits = "edits-string",
144
147
  /** performs a statistical test, so its result is the test statistic a reader is meant to see (`t.test`, `anova`) */
145
148
  Statistics = "statistics",
146
149
  /** marked for removal, with a better alternative available, like `dplyr::funs` */
@@ -144,10 +144,13 @@ var SemanticCallTag;
144
144
  SemanticCallTag["Prints"] = "prints";
145
145
  /**
146
146
  * the result is bounded no matter what flows in: a count, an index, a logical, or one of the values of the
147
- * argument marked {@link ArgProp.Bounds}. So nothing an argument carries reaches the result, which is what
148
- * lets the input-sources query stop tracing at `length(x)` or `match.arg(arg, choices)`.
147
+ * argument marked {@link ArgProp.Bounds}. So no content of an argument reaches the result, which is what
148
+ * lets the input-sources query trace `match.arg(arg, choices)` to its `choices` alone; a count still
149
+ * depends on what it counts, so `length(readLines(f))` keeps its file input.
149
150
  */
150
151
  SemanticCallTag["Narrows"] = "narrows-args";
152
+ /** cuts or replaces parts of a string (`gsub`, `substr`), so what an escaping function made of it no longer holds */
153
+ SemanticCallTag["Edits"] = "edits-string";
151
154
  /** performs a statistical test, so its result is the test statistic a reader is meant to see (`t.test`, `anova`) */
152
155
  SemanticCallTag["Statistics"] = "statistics";
153
156
  /** marked for removal, with a better alternative available, like `dplyr::funs` */
@@ -197,7 +200,7 @@ exports.ExclusiveCallProps = [
197
200
  exports.InputProps = getPropMask([
198
201
  CallProp.NonDet | CallProp.Ambient | CallProp.Ffi | CallProp.Lang,
199
202
  SemanticCallTag.Random, SemanticCallTag.File, SemanticCallTag.TempFile, SemanticCallTag.Network, SemanticCallTag.Process,
200
- SemanticCallTag.User, SemanticCallTag.CommandLine
203
+ SemanticCallTag.User, SemanticCallTag.CommandLine, SemanticCallTag.LoadsPackage, SemanticCallTag.ChecksPackage
201
204
  ]);
202
205
  /**
203
206
  * The {@link CallProp} bits the signature database states itself, so {@link fnInfoFromSignature} can read them