@eagleoutice/flowr 2.10.4 → 2.10.6

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 (115) hide show
  1. package/README.md +31 -14
  2. package/abstract-interpretation/absint-visitor.d.ts +17 -22
  3. package/abstract-interpretation/absint-visitor.js +47 -48
  4. package/abstract-interpretation/data-frame/dataframe-domain.d.ts +0 -3
  5. package/abstract-interpretation/data-frame/shape-inference.d.ts +2 -1
  6. package/abstract-interpretation/data-frame/shape-inference.js +5 -4
  7. package/abstract-interpretation/domains/abstract-domain.d.ts +17 -16
  8. package/abstract-interpretation/domains/abstract-domain.js +25 -27
  9. package/abstract-interpretation/domains/bounded-set-domain.js +1 -1
  10. package/abstract-interpretation/domains/multi-value-state-domain.d.ts +32 -0
  11. package/abstract-interpretation/domains/multi-value-state-domain.js +60 -0
  12. package/abstract-interpretation/domains/partial-product-domain.d.ts +43 -0
  13. package/abstract-interpretation/domains/partial-product-domain.js +163 -0
  14. package/abstract-interpretation/domains/product-domain.d.ts +2 -29
  15. package/abstract-interpretation/domains/product-domain.js +6 -123
  16. package/abstract-interpretation/domains/set-range-domain.js +3 -3
  17. package/abstract-interpretation/domains/set-upper-bound-domain.js +1 -1
  18. package/abstract-interpretation/domains/singleton-domain.js +1 -1
  19. package/abstract-interpretation/domains/state-abstract-domain.d.ts +13 -28
  20. package/abstract-interpretation/domains/state-abstract-domain.js +16 -38
  21. package/abstract-interpretation/domains/state-domain-like.d.ts +36 -0
  22. package/abstract-interpretation/domains/state-domain-like.js +3 -0
  23. package/cli/flowr.js +11 -1
  24. package/config.d.ts +13 -0
  25. package/config.js +24 -3
  26. package/control-flow/basic-cfg-guided-visitor.d.ts +1 -1
  27. package/control-flow/semantic-cfg-guided-visitor.d.ts +4 -0
  28. package/control-flow/semantic-cfg-guided-visitor.js +23 -32
  29. package/dataflow/environments/built-in-proc-name.d.ts +7 -1
  30. package/dataflow/environments/built-in-proc-name.js +6 -0
  31. package/dataflow/environments/built-in.d.ts +6 -0
  32. package/dataflow/environments/built-in.js +6 -0
  33. package/dataflow/environments/default-builtin-config.d.ts +63 -1
  34. package/dataflow/environments/default-builtin-config.js +15 -4
  35. package/dataflow/environments/identifier.d.ts +14 -0
  36. package/dataflow/graph/vertex.d.ts +6 -0
  37. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -0
  38. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +6 -0
  39. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +99 -2
  40. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +13 -0
  41. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +48 -0
  42. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +75 -0
  43. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +196 -0
  44. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +2 -0
  45. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +38 -21
  46. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +5 -0
  47. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +27 -13
  48. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +14 -4
  49. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +27 -0
  50. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +97 -0
  51. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +23 -0
  52. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +90 -0
  53. package/documentation/doc-readme.js +13 -2
  54. package/documentation/doc-util/doc-types.d.ts +11 -2
  55. package/documentation/doc-util/doc-types.js +31 -9
  56. package/documentation/wiki-absint.d.ts +17 -2
  57. package/documentation/wiki-absint.js +83 -24
  58. package/documentation/wiki-analyzer.js +3 -4
  59. package/documentation/wiki-interface.js +22 -16
  60. package/documentation/wiki-mk/doc-context.d.ts +14 -1
  61. package/documentation/wiki-mk/doc-context.js +6 -0
  62. package/documentation/wiki-normalized-ast.d.ts +0 -9
  63. package/documentation/wiki-normalized-ast.js +9 -60
  64. package/linter/linter-rules.d.ts +4 -3
  65. package/linter/rules/problematic-inputs.d.ts +13 -7
  66. package/linter/rules/problematic-inputs.js +109 -60
  67. package/package.json +3 -3
  68. package/project/flowr-analyzer-builder.d.ts +6 -3
  69. package/project/flowr-analyzer-builder.js +12 -5
  70. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +4 -3
  71. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +17 -4
  72. package/project/plugins/flowr-analyzer-plugin.d.ts +1 -1
  73. package/project/plugins/flowr-analyzer-plugin.js +1 -1
  74. package/queries/catalog/dependencies-query/function-info/read-functions.js +2 -0
  75. package/queries/catalog/dependencies-query/function-info/write-functions.js +1 -0
  76. package/queries/catalog/input-sources-query/input-source-functions.d.ts +7 -0
  77. package/queries/catalog/input-sources-query/input-source-functions.js +56 -0
  78. package/queries/catalog/input-sources-query/input-sources-query-executor.d.ts +1 -1
  79. package/queries/catalog/input-sources-query/input-sources-query-executor.js +19 -53
  80. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +2 -1
  81. package/queries/catalog/input-sources-query/input-sources-query-format.js +28 -11
  82. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +21 -42
  83. package/queries/catalog/input-sources-query/simple-input-classifier.js +168 -104
  84. package/r-bridge/data/data.d.ts +28 -2
  85. package/r-bridge/data/data.js +34 -2
  86. package/r-bridge/lang-4.x/ast/model/model.d.ts +5 -6
  87. package/r-bridge/lang-4.x/ast/model/model.js +0 -1
  88. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +6 -6
  89. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +6 -6
  90. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +6 -6
  91. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +6 -6
  92. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +6 -6
  93. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +6 -6
  94. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +6 -6
  95. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +6 -6
  96. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +6 -6
  97. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +6 -6
  98. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +6 -6
  99. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +6 -6
  100. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +6 -6
  101. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +6 -6
  102. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +6 -6
  103. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +6 -6
  104. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +6 -6
  105. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +6 -6
  106. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +6 -6
  107. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +6 -6
  108. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +6 -6
  109. package/util/record.d.ts +18 -3
  110. package/util/record.js +22 -1
  111. package/util/version.js +1 -1
  112. package/abstract-interpretation/normalized-ast-fold.d.ts +0 -119
  113. package/abstract-interpretation/normalized-ast-fold.js +0 -181
  114. package/project/plugins/flowr-analyzer-plugin-defaults.d.ts +0 -5
  115. package/project/plugins/flowr-analyzer-plugin-defaults.js +0 -37
@@ -2,29 +2,34 @@ import { type LintingResult, LintingRuleCertainty } from '../linter-format';
2
2
  import type { MergeableRecord } from '../../util/objects';
3
3
  import { SourceLocation } from '../../util/range';
4
4
  import { LintingRuleTag } from '../linter-tags';
5
- import type { InputSources } from '../../queries/catalog/input-sources-query/simple-input-classifier';
6
- /**
7
- * Describes a linting result for a problematic eval usage, including the location of the eval call and the computed input sources that lead to it.
8
- */
5
+ import type { InputClassifierConfig, InputSources } from '../../queries/catalog/input-sources-query/simple-input-classifier';
6
+ export interface PipeCommandFunctionSpec {
7
+ pattern: string;
8
+ argIdx: number;
9
+ argName: string;
10
+ }
9
11
  export interface ProblematicInputsResult extends LintingResult {
10
12
  name: string;
11
13
  loc: SourceLocation;
12
14
  sources: InputSources;
15
+ pipeCommand?: string;
13
16
  }
14
17
  export interface ProblematicInputsConfig extends MergeableRecord {
15
18
  consider?: string | string[];
19
+ inputFns?: InputClassifierConfig;
20
+ pipeCommandFunctions?: PipeCommandFunctionSpec | PipeCommandFunctionSpec[];
16
21
  }
17
22
  export type ProblematicInputsMetadata = MergeableRecord;
18
23
  export declare const PROBLEMATIC_INPUTS: {
19
24
  readonly createSearch: (config: ProblematicInputsConfig) => import("../../search/flowr-search-builder").FlowrSearchBuilder<"from-query", [], import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>;
20
- readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, _config: ProblematicInputsConfig, data: {
25
+ readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, config: ProblematicInputsConfig, data: {
21
26
  normalize: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").NormalizedAst;
22
27
  dataflow: import("../../dataflow/info").DataflowInformation;
23
28
  cfg: import("../../control-flow/control-flow-graph").ControlFlowInformation;
24
29
  analyzer: import("../../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider;
25
30
  }) => Promise<{
26
31
  results: ProblematicInputsResult[];
27
- ".meta": ProblematicInputsMetadata;
32
+ '.meta': {};
28
33
  }>;
29
34
  readonly prettyPrint: {
30
35
  readonly query: (result: ProblematicInputsResult) => string;
@@ -32,11 +37,12 @@ export declare const PROBLEMATIC_INPUTS: {
32
37
  };
33
38
  readonly info: {
34
39
  readonly name: "Problematic inputs";
35
- readonly description: "Detects uses of configured dynamic calls (e.g. eval, system) whose inputs are not statically constant. Prints the computed input-sources for the call and flags usages that depend on non-constant/trusted inputs.";
40
+ readonly description: "Detects uses of dynamic calls (e.g. eval, system) with non-constant inputs, and graphics-device calls (pdf, postscript) where a filename starts with '|' indicating a pipe command injection.";
36
41
  readonly tags: readonly [LintingRuleTag.Security, LintingRuleTag.Smell, LintingRuleTag.Readability, LintingRuleTag.Performance];
37
42
  readonly certainty: LintingRuleCertainty.BestEffort;
38
43
  readonly defaultConfig: {
39
44
  readonly consider: readonly ["^eval$", "^system$", "^system2$", "^shell$"];
45
+ readonly pipeCommandFunctions: readonly PipeCommandFunctionSpec[];
40
46
  };
41
47
  };
42
48
  };
@@ -7,104 +7,153 @@ const range_1 = require("../../util/range");
7
7
  const linter_tags_1 = require("../linter-tags");
8
8
  const simple_input_classifier_1 = require("../../queries/catalog/input-sources-query/simple-input-classifier");
9
9
  const parse_1 = require("../../slicing/criterion/parse");
10
+ const graph_1 = require("../../dataflow/graph/graph");
10
11
  const defaultConsider = ['^eval$', '^system$', '^system2$', '^shell$'];
11
- function normalizeConsider(cfg) {
12
- if (cfg?.consider === undefined) {
13
- return Array.from(defaultConsider, s => new RegExp(s));
12
+ const defaultPipeCommandFunctions = [
13
+ { pattern: '^pdf$', argIdx: 0, argName: 'file' },
14
+ { pattern: '^postscript$', argIdx: 0, argName: 'file' }
15
+ ];
16
+ function normalizePatternList(cfg, defaults) {
17
+ if (cfg === undefined) {
18
+ return Array.from(defaults, s => new RegExp(s));
14
19
  }
15
- if (Array.isArray(cfg.consider)) {
16
- const arr = cfg.consider.length === 0 ? Array.from(defaultConsider) : cfg.consider;
17
- // deduplicate while preserving order
20
+ if (Array.isArray(cfg)) {
21
+ const arr = cfg.length === 0 ? Array.from(defaults) : cfg;
18
22
  return Array.from(new Set(arr), s => new RegExp(s));
19
23
  }
20
- return [new RegExp(cfg.consider)];
24
+ return [new RegExp(cfg)];
25
+ }
26
+ function normalizePipeSpecs(cfg) {
27
+ const raw = cfg === undefined ? defaultPipeCommandFunctions
28
+ : Array.isArray(cfg) ? (cfg.length === 0 ? defaultPipeCommandFunctions : cfg)
29
+ : [cfg];
30
+ return raw.map(s => ({ pattern: new RegExp(s.pattern), argIdx: s.argIdx, argName: s.argName }));
21
31
  }
22
- /**
23
- * Format a list of input sources either as a single-line string (inline) or a block.
24
- * - inline: returns a semicolon-separated single-line summary
25
- * - block: returns an array of lines (to be joined with newlines by the caller)
26
- */
27
32
  function formatInputSources(inputs, inline = true) {
28
33
  if (!inputs || inputs.length === 0) {
29
34
  return inline ? '' : [];
30
35
  }
31
- const formatOne = (s, inlineMode) => {
32
- const typeStr = '[' + s.types.join(',') + ']';
33
- const cdsStr = s.cds ? ', cds: [' + s.cds.join(',') + ']' : '';
34
- return inlineMode
35
- ? `${s.id} (type: ${typeStr}, trace: ${s.trace}${cdsStr})`
36
- : `- ${s.id}: type=${typeStr}, trace=${s.trace}${cdsStr}`;
36
+ const fmt = (s) => {
37
+ const t = '[' + s.types.join(',') + ']';
38
+ const c = s.cds ? ', cds: [' + s.cds.join(',') + ']' : '';
39
+ return inline
40
+ ? `${s.id} (type: ${t}, trace: ${s.trace}${c})`
41
+ : `- ${s.id}: type=${t}, trace=${s.trace}${c}`;
37
42
  };
38
- if (inline) {
39
- return inputs.map(s => formatOne(s, true)).join('; ');
40
- }
41
- return inputs.map(s => formatOne(s, false));
43
+ return inline ? inputs.map(fmt).join('; ') : inputs.map(fmt);
42
44
  }
43
- // small helpers to keep checks readable
44
45
  function hasUnknownSource(sources) {
45
46
  return sources.some(s => s.types.includes(simple_input_classifier_1.InputType.Unknown));
46
47
  }
47
48
  function isProblematicForAllowed(sources, allowed) {
48
49
  return sources.some(s => s.types.some(t => !allowed.includes(t)));
49
50
  }
51
+ function getPipeCommandValue(sources) {
52
+ for (const s of sources) {
53
+ if (typeof s.value === 'string' && s.value.startsWith('|')) {
54
+ return s.value;
55
+ }
56
+ }
57
+ return undefined;
58
+ }
59
+ function resolveFileArgId(vertex, argIdx, argName) {
60
+ const args = vertex?.args;
61
+ if (!args) {
62
+ return undefined;
63
+ }
64
+ let idx = args.findIndex(a => graph_1.FunctionArgument.isNamed(a) && a.name === argName);
65
+ if (idx < 0) {
66
+ idx = argIdx;
67
+ }
68
+ if (idx >= args.length) {
69
+ return undefined;
70
+ }
71
+ const arg = args[idx];
72
+ return graph_1.FunctionArgument.isEmpty(arg) ? undefined : graph_1.FunctionArgument.getReference(arg);
73
+ }
74
+ function checkPipeInjection(nid, loc, name, sources) {
75
+ const pipeCmd = getPipeCommandValue(sources);
76
+ if (pipeCmd !== undefined) {
77
+ return { involvedId: nid, certainty: linter_format_1.LintingResultCertainty.Certain, loc, name, sources, pipeCommand: pipeCmd };
78
+ }
79
+ if (hasUnknownSource(sources)) {
80
+ return { involvedId: nid, certainty: linter_format_1.LintingResultCertainty.Uncertain, loc, name, sources };
81
+ }
82
+ return undefined;
83
+ }
50
84
  exports.PROBLEMATIC_INPUTS = {
51
85
  createSearch: config => {
52
- const cfg = config;
53
- const considerArr = normalizeConsider(cfg);
54
- const queries = considerArr.map((name, i) => ({
55
- type: 'call-context',
56
- callName: name,
57
- callNameExact: false,
58
- subkind: `fn-${i}`
59
- }));
60
- return flowr_search_builder_1.Q.fromQuery(...queries);
86
+ const toQ = (name, subkind) => ({ type: 'call-context', callName: name, callNameExact: false, subkind });
87
+ return flowr_search_builder_1.Q.fromQuery(...normalizePatternList(config?.consider, defaultConsider).map((n, i) => toQ(n, `fn-${i}`)), ...normalizePipeSpecs(config?.pipeCommandFunctions).map((s, i) => toQ(s.pattern, `pipe-${i}`)));
61
88
  },
62
- processSearchResult: async (elements, _config, data) => {
89
+ processSearchResult: async (elements, config, data) => {
63
90
  const results = [];
91
+ const seen = new Set();
64
92
  const defaultAccept = [simple_input_classifier_1.InputType.Constant, simple_input_classifier_1.InputType.DerivedConstant];
93
+ const considerPats = normalizePatternList(config?.consider, defaultConsider);
94
+ const pipePats = normalizePipeSpecs(config?.pipeCommandFunctions);
65
95
  for (const element of elements.getElements()) {
66
96
  const nid = element.node.info.id;
67
- const criterion = parse_1.SlicingCriterion.fromId(nid);
68
- const q = { type: 'input-sources', criterion };
69
- const all = await data.analyzer.query([q]);
70
- const inputSourcesResult = all['input-sources'];
71
- const sources = inputSourcesResult?.results?.[criterion] ?? [];
72
- if (isProblematicForAllowed(sources, defaultAccept)) {
73
- const certainty = hasUnknownSource(sources) ? linter_format_1.LintingResultCertainty.Uncertain : linter_format_1.LintingResultCertainty.Certain;
74
- results.push({
75
- involvedId: nid,
76
- certainty,
77
- loc: range_1.SourceLocation.fromNode(element.node) ?? range_1.SourceLocation.invalid(),
78
- name: element.node.lexeme ?? '',
79
- sources
80
- });
97
+ if (seen.has(nid)) {
98
+ continue;
99
+ }
100
+ const name = element.node.lexeme ?? '';
101
+ const pipeSpec = pipePats.find(s => s.pattern.test(name));
102
+ const isConsider = pipeSpec === undefined && considerPats.some(p => p.test(name));
103
+ if (pipeSpec === undefined && !isConsider) {
104
+ continue;
105
+ }
106
+ const loc = range_1.SourceLocation.fromNode(element.node) ?? range_1.SourceLocation.invalid();
107
+ if (pipeSpec !== undefined) {
108
+ const vertex = data.dataflow.graph.getVertex(nid);
109
+ const fileArgId = resolveFileArgId(vertex, pipeSpec.argIdx, pipeSpec.argName);
110
+ if (fileArgId !== undefined) {
111
+ const criterion = parse_1.SlicingCriterion.fromId(fileArgId);
112
+ const all = await data.analyzer.query([{ type: 'input-sources', criterion, config: config.inputFns }]);
113
+ const sources = all['input-sources']?.results?.[criterion] ?? [];
114
+ const r = checkPipeInjection(nid, loc, name, sources);
115
+ if (r !== undefined) {
116
+ seen.add(nid);
117
+ results.push(r);
118
+ }
119
+ }
120
+ }
121
+ else {
122
+ const criterion = parse_1.SlicingCriterion.fromId(nid);
123
+ const all = await data.analyzer.query([{ type: 'input-sources', criterion, config: config.inputFns }]);
124
+ const sources = all['input-sources']?.results?.[criterion] ?? [];
125
+ if (isProblematicForAllowed(sources, defaultAccept)) {
126
+ seen.add(nid);
127
+ results.push({ involvedId: nid, certainty: hasUnknownSource(sources) ? linter_format_1.LintingResultCertainty.Uncertain : linter_format_1.LintingResultCertainty.Certain, loc, name, sources });
128
+ }
81
129
  }
82
130
  }
83
- return {
84
- results,
85
- '.meta': {}
86
- };
131
+ return { results, '.meta': {} };
87
132
  },
88
- /* helper to format input sources for pretty printing */
89
133
  prettyPrint: {
90
134
  [linter_format_1.LintingPrettyPrintContext.Query]: result => {
91
- const inputs = result.sources ?? [];
92
- const srcStr = formatInputSources(inputs, true);
93
- return 'Use of configured dynamic call at ' + range_1.SourceLocation.format(result.loc) + (srcStr ? '; inputs: ' + srcStr : '');
135
+ if (result.pipeCommand !== undefined) {
136
+ return `Pipe command injection via '${result.pipeCommand}' in call to ${result.name} at ${range_1.SourceLocation.format(result.loc)}`;
137
+ }
138
+ const src = formatInputSources(result.sources ?? [], true);
139
+ return 'Use of configured dynamic call at ' + range_1.SourceLocation.format(result.loc) + (src ? '; inputs: ' + src : '');
94
140
  },
95
141
  [linter_format_1.LintingPrettyPrintContext.Full]: result => {
96
- const inputs = result.sources ?? [];
97
- const srcLines = formatInputSources(inputs, false);
98
- return 'Use of configured dynamic call at ' + range_1.SourceLocation.format(result.loc) + ' is potentially problematic' + (srcLines.length ? '\nInputs:\n' + srcLines.join('\n') : '');
142
+ const lines = formatInputSources(result.sources ?? [], false);
143
+ const tail = lines.length ? '\nInputs:\n' + lines.join('\n') : '';
144
+ return result.pipeCommand !== undefined
145
+ ? `Pipe command injection: '${result.pipeCommand}' passed as filename to ${result.name} at ${range_1.SourceLocation.format(result.loc)}${tail}`
146
+ : 'Use of configured dynamic call at ' + range_1.SourceLocation.format(result.loc) + ' is potentially problematic' + tail;
99
147
  }
100
148
  },
101
149
  info: {
102
150
  name: 'Problematic inputs',
103
- description: 'Detects uses of configured dynamic calls (e.g. eval, system) whose inputs are not statically constant. Prints the computed input-sources for the call and flags usages that depend on non-constant/trusted inputs.',
151
+ description: 'Detects uses of dynamic calls (e.g. eval, system) with non-constant inputs, and graphics-device calls (pdf, postscript) where a filename starts with \'|\' indicating a pipe command injection.',
104
152
  tags: [linter_tags_1.LintingRuleTag.Security, linter_tags_1.LintingRuleTag.Smell, linter_tags_1.LintingRuleTag.Readability, linter_tags_1.LintingRuleTag.Performance],
105
153
  certainty: linter_format_1.LintingRuleCertainty.BestEffort,
106
154
  defaultConfig: {
107
- consider: defaultConsider
155
+ consider: defaultConsider,
156
+ pipeCommandFunctions: defaultPipeCommandFunctions
108
157
  }
109
158
  }
110
159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eagleoutice/flowr",
3
- "version": "2.10.4",
3
+ "version": "2.10.6",
4
4
  "description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {
@@ -170,7 +170,7 @@
170
170
  "@eagleoutice/eslint-config-flowr": "^1.0.40",
171
171
  "@eslint/eslintrc": "^3.3.3",
172
172
  "@eslint/js": "^9.39.2",
173
- "@j-ulrich/release-it-regex-bumper": "^5.3.0",
173
+ "@j-ulrich/release-it-regex-bumper": "^5.4.0",
174
174
  "@types/command-line-args": "^5.2.3",
175
175
  "@types/command-line-usage": "^5.0.4",
176
176
  "@types/commonmark": "^0.27.10",
@@ -188,7 +188,7 @@
188
188
  "eslint": "^9.39.2",
189
189
  "license-checker-rseidelsohn": "^4.4.2",
190
190
  "npm-run-all": "^4.1.5",
191
- "release-it": "^19.2.3",
191
+ "release-it": "^20.0.0",
192
192
  "ts-node": "^10.9.2",
193
193
  "typedoc": "^0.28.17",
194
194
  "typedoc-plugin-missing-exports": "^4.1.2",
@@ -34,11 +34,12 @@ export declare class FlowrAnalyzerBuilder {
34
34
  private parser?;
35
35
  private input?;
36
36
  private readonly plugins;
37
+ private readonly withDefaultPlugins;
37
38
  /**
38
39
  * Creates a new builder for the {@link FlowrAnalyzer}.
39
- * By default, the standard set of plugins as returned by {@link FlowrAnalyzerPluginDefaults} are registered.
40
+ * By default, the standard set of plugins as returned by {@link FlowrConfig#defaultPlugins} are registered.
40
41
  * @param withDefaultPlugins - Whether to register the default plugins upon creation. Default is `true`.
41
- * @see {@link FlowrAnalyzerPluginDefaults} - for the default plugin set.
42
+ * @see {@link FlowrDefaultPlugins} - for the default plugin set.
42
43
  * @see {@link FlowrAnalyzerBuilder#registerPlugins} - to add more plugins.
43
44
  * @see {@link FlowrAnalyzerBuilder#unregisterPlugins} - to remove plugins.
44
45
  */
@@ -53,6 +54,8 @@ export declare class FlowrAnalyzerBuilder {
53
54
  amendConfig(func: (config: DeepWritable<FlowrConfig>) => FlowrConfig | void): this;
54
55
  /**
55
56
  * Overwrite the configuration used by the resulting analyzer.
57
+ * This also unloads all default plugins and reloads them as set in the new config
58
+ * if the withDefaultPlugins flag was set in the constructor
56
59
  * @param config - The new configuration.
57
60
  */
58
61
  setConfig(config: FlowrConfig): this;
@@ -78,7 +81,7 @@ export declare class FlowrAnalyzerBuilder {
78
81
  setInput(input: Omit<NormalizeRequiredInput, 'context'>): this;
79
82
  /**
80
83
  * Register one or multiple additional plugins.
81
- * For the default plugin set, please refer to {@link FlowrAnalyzerPluginDefaults}, they can be registered
84
+ * For the default plugin set, please refer to {@link FlowrDefaultPlugins}, they can be registered
82
85
  * by passing `true` to the {@link FlowrAnalyzerBuilder} constructor.
83
86
  * @param plugin - One or multiple plugins to register.
84
87
  * @see {@link FlowrAnalyzerBuilder#unregisterPlugins} to remove plugins.
@@ -7,7 +7,6 @@ const engines_1 = require("../engines");
7
7
  const assert_1 = require("../util/assert");
8
8
  const flowr_analyzer_context_1 = require("./context/flowr-analyzer-context");
9
9
  const flowr_analyzer_cache_1 = require("./cache/flowr-analyzer-cache");
10
- const flowr_analyzer_plugin_defaults_1 = require("./plugins/flowr-analyzer-plugin-defaults");
11
10
  const plugin_registry_1 = require("./plugins/plugin-registry");
12
11
  /**
13
12
  * Builder for the {@link FlowrAnalyzer}, use it to configure all analysis aspects before creating the analyzer instance
@@ -37,17 +36,19 @@ class FlowrAnalyzerBuilder {
37
36
  parser;
38
37
  input;
39
38
  plugins = new Map();
39
+ withDefaultPlugins;
40
40
  /**
41
41
  * Creates a new builder for the {@link FlowrAnalyzer}.
42
- * By default, the standard set of plugins as returned by {@link FlowrAnalyzerPluginDefaults} are registered.
42
+ * By default, the standard set of plugins as returned by {@link FlowrConfig#defaultPlugins} are registered.
43
43
  * @param withDefaultPlugins - Whether to register the default plugins upon creation. Default is `true`.
44
- * @see {@link FlowrAnalyzerPluginDefaults} - for the default plugin set.
44
+ * @see {@link FlowrDefaultPlugins} - for the default plugin set.
45
45
  * @see {@link FlowrAnalyzerBuilder#registerPlugins} - to add more plugins.
46
46
  * @see {@link FlowrAnalyzerBuilder#unregisterPlugins} - to remove plugins.
47
47
  */
48
48
  constructor(withDefaultPlugins = true) {
49
+ this.withDefaultPlugins = withDefaultPlugins;
49
50
  if (withDefaultPlugins) {
50
- this.registerPlugins(...(0, flowr_analyzer_plugin_defaults_1.FlowrAnalyzerPluginDefaults)());
51
+ this.registerPlugins(...this.flowrConfig.defaultPlugins);
51
52
  }
52
53
  }
53
54
  /**
@@ -64,9 +65,15 @@ class FlowrAnalyzerBuilder {
64
65
  }
65
66
  /**
66
67
  * Overwrite the configuration used by the resulting analyzer.
68
+ * This also unloads all default plugins and reloads them as set in the new config
69
+ * if the withDefaultPlugins flag was set in the constructor
67
70
  * @param config - The new configuration.
68
71
  */
69
72
  setConfig(config) {
73
+ if (this.withDefaultPlugins) {
74
+ this.unregisterPlugins(...this.flowrConfig.defaultPlugins.map(p => Array.isArray(p) ? p[0] : p));
75
+ this.registerPlugins(...config.defaultPlugins);
76
+ }
70
77
  this.flowrConfig = config;
71
78
  return this;
72
79
  }
@@ -104,7 +111,7 @@ class FlowrAnalyzerBuilder {
104
111
  }
105
112
  /**
106
113
  * Register one or multiple additional plugins.
107
- * For the default plugin set, please refer to {@link FlowrAnalyzerPluginDefaults}, they can be registered
114
+ * For the default plugin set, please refer to {@link FlowrDefaultPlugins}, they can be registered
108
115
  * by passing `true` to the {@link FlowrAnalyzerBuilder} constructor.
109
116
  * @param plugin - One or multiple plugins to register.
110
117
  * @see {@link FlowrAnalyzerBuilder#unregisterPlugins} to remove plugins.
@@ -3,7 +3,7 @@ import { FlowrFile } from '../../../context/flowr-file';
3
3
  import { type Node } from 'commonmark';
4
4
  /**
5
5
  * This decorates a text file and parses its contents as a R Markdown file.
6
- * Finnaly, it provides access to the single cells, and all cells fused together as one R file.
6
+ * Finally, it provides access to the single cells, and all cells fused together as one R file.
7
7
  */
8
8
  export declare class FlowrRMarkdownFile extends FlowrFile<string> {
9
9
  private data?;
@@ -24,8 +24,9 @@ export declare class FlowrRMarkdownFile extends FlowrFile<string> {
24
24
  protected loadContent(): string;
25
25
  static from(file: FlowrFileProvider<string> | FlowrRMarkdownFile): FlowrRMarkdownFile;
26
26
  }
27
+ export type CodeBlockOptions = Map<string, string>;
27
28
  export interface CodeBlock {
28
- options: string;
29
+ options: CodeBlockOptions;
29
30
  code: string;
30
31
  }
31
32
  export type CodeBlockEx = CodeBlock & {
@@ -59,4 +60,4 @@ export declare function restoreBlocksWithoutMd(blocks: CodeBlockEx[], totalLines
59
60
  /**
60
61
  * Parses the options of an R code block from its header and content
61
62
  */
62
- export declare function parseCodeBlockOptions(header: string, content: string): string;
63
+ export declare function parseCodeBlockOptions(header: string, content: string): CodeBlockOptions;
@@ -15,7 +15,7 @@ const gray_matter_1 = __importDefault(require("gray-matter"));
15
15
  const log_1 = require("../../../../util/log");
16
16
  /**
17
17
  * This decorates a text file and parses its contents as a R Markdown file.
18
- * Finnaly, it provides access to the single cells, and all cells fused together as one R file.
18
+ * Finally, it provides access to the single cells, and all cells fused together as one R file.
19
19
  */
20
20
  class FlowrRMarkdownFile extends flowr_file_1.FlowrFile {
21
21
  data;
@@ -78,9 +78,14 @@ function parseRMarkdownFile(raw) {
78
78
  if (!isRCodeBlock(node)) {
79
79
  continue;
80
80
  }
81
+ const options = parseCodeBlockOptions(node.info, node.literal);
82
+ const engineOpt = options.get('engine');
83
+ if (engineOpt !== undefined && engineOpt.trim().toLowerCase() !== 'r') {
84
+ continue;
85
+ }
81
86
  blocks.push({
82
87
  code: node.literal,
83
- options: parseCodeBlockOptions(node.info, node.literal),
88
+ options: options,
84
89
  startpos: { line: node.sourcepos[0][0] + 1, col: 0 }
85
90
  });
86
91
  }
@@ -91,6 +96,7 @@ function parseRMarkdownFile(raw) {
91
96
  options: frontmatter?.data ?? {}
92
97
  };
93
98
  }
99
+ // We need the [\s,] part, otherwise {rust} would also match
94
100
  const RTagRegex = /{[rR](?:[\s,][^}]*)?}/;
95
101
  /**
96
102
  * Checks whether a CommonMark node is an R code block
@@ -123,6 +129,7 @@ function restoreBlocksWithoutMd(blocks, totalLines) {
123
129
  goToLine(totalLines + 1);
124
130
  return output;
125
131
  }
132
+ const OptionsRegex = /([\w_.-]*)\s*[:=]\s*["']?([^,"']*)/g;
126
133
  /**
127
134
  * Parses the options of an R code block from its header and content
128
135
  */
@@ -135,9 +142,15 @@ function parseCodeBlockOptions(header, content) {
135
142
  if (!line.trim().startsWith('#|')) {
136
143
  break;
137
144
  }
138
- const opt = line.substring(3);
145
+ const opt = line.substring(2).trim();
139
146
  opts += opts.length === 0 ? opt : `, ${opt}`;
140
147
  }
141
- return opts;
148
+ const parsedOptions = new Map();
149
+ for (const match of opts.matchAll(OptionsRegex)) {
150
+ if (match[1] && match[2] !== undefined) { // key must not be empty, but value can be empty string for example
151
+ parsedOptions.set(match[1], match[2]);
152
+ }
153
+ }
154
+ return parsedOptions;
142
155
  }
143
156
  //# sourceMappingURL=flowr-rmarkdown-file.js.map
@@ -73,7 +73,7 @@ export interface FlowrAnalyzerPluginInterface<In = unknown, Out = In> {
73
73
  * For example, if you want to create a plugin that determines the loading order of files, extend {@link FlowrAnalyzerLoadingOrderPlugin} instead.
74
74
  * These classes also provide sensible overrides of {@link FlowrAnalyzerPlugin.defaultPlugin} to be used when no plugin of this type is registered or triggered.
75
75
  *
76
- * For a collection of default plugins, see {@link FlowrAnalyzerPluginDefaults}.
76
+ * For a collection of default plugins, see {@link FlowrDefaultPlugins}.
77
77
  */
78
78
  export declare abstract class FlowrAnalyzerPlugin<In = unknown, Out extends AsyncOrSync<unknown> = In> implements FlowrAnalyzerPluginInterface<In, Out> {
79
79
  abstract readonly name: string;
@@ -53,7 +53,7 @@ const generalPluginLog = log_1.log.getSubLogger({ name: 'plugins' });
53
53
  * For example, if you want to create a plugin that determines the loading order of files, extend {@link FlowrAnalyzerLoadingOrderPlugin} instead.
54
54
  * These classes also provide sensible overrides of {@link FlowrAnalyzerPlugin.defaultPlugin} to be used when no plugin of this type is registered or triggered.
55
55
  *
56
- * For a collection of default plugins, see {@link FlowrAnalyzerPluginDefaults}.
56
+ * For a collection of default plugins, see {@link FlowrDefaultPlugins}.
57
57
  */
58
58
  class FlowrAnalyzerPlugin {
59
59
  /**
@@ -114,5 +114,7 @@ exports.ReadFunctions = [
114
114
  { package: 'openxlsx', name: 'loadWorkbook', argIdx: 0, argName: 'file', resolveValue: true },
115
115
  { package: 'readODS', name: 'read_ods', argIdx: 0, argName: 'path', resolveValue: true },
116
116
  { package: 'vroom', name: 'vroom', argIdx: 0, argName: 'file', resolveValue: true },
117
+ { package: 'compiler', name: 'loadcmp', argIdx: 0, argName: 'file', resolveValue: true },
118
+ { package: 'compiler', name: 'cmpfile', argIdx: 0, argName: 'infile', resolveValue: true }
117
119
  ];
118
120
  //# sourceMappingURL=read-functions.js.map
@@ -123,5 +123,6 @@ exports.WriteFunctions = [
123
123
  { package: 'rio', name: 'export', argIdx: 1, argName: 'file', resolveValue: true },
124
124
  { package: 'rio', name: 'export_list', argIdx: 1, argName: 'file', resolveValue: true },
125
125
  { package: 'magick', name: 'image_write', argIdx: 1, argName: 'path', resolveValue: true, ignoreIf: 'arg-missing' },
126
+ { package: 'compiler', name: 'cmpfile', argIdx: 1, argName: 'outfile', resolveValue: true }
126
127
  ];
127
128
  //# sourceMappingURL=write-functions.js.map
@@ -0,0 +1,7 @@
1
+ import type { Identifier } from '../../../dataflow/environments/identifier';
2
+ export declare const PureFunctions: Identifier[];
3
+ export declare const SystemFunctions: Identifier[];
4
+ export declare const FfiFunctions: Identifier[];
5
+ export declare const LangFunctions: Identifier[];
6
+ export declare const OptionsFunctions: Identifier[];
7
+ export declare const UserFunctions: Identifier[];
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserFunctions = exports.OptionsFunctions = exports.LangFunctions = exports.FfiFunctions = exports.SystemFunctions = exports.PureFunctions = void 0;
4
+ exports.PureFunctions = [
5
+ 'paste', 'paste0', 'parse', '+', '-', '*',
6
+ '/', '^', '%%', '%/%', '&', '|', '!', '&&', '||',
7
+ '<', '>', '<=', '>=', '==', '!=', ':',
8
+ 'abs', 'sign', 'sqrt', 'exp', 'log', 'log10', 'log2',
9
+ 'sin', 'cos', 'tan', 'asin', 'acos', 'atan',
10
+ 'length', 'nchar', 'dim', 'nrow', 'ncol',
11
+ 'c', 'list', 'data.frame',
12
+ 'ifelse', 'switch', 'factor', 'as.factor',
13
+ 'round', 'floor', 'ceiling', 'trunc',
14
+ 'substr', 'substring', 'strsplit',
15
+ 'min', 'max', 'range', 'sum', 'prod', 'mean', 'median', 'var', 'sd',
16
+ 'head', 'tail', 'seq', 'rep',
17
+ 'apply', 'lapply', 'sapply', 'vapply', 'tapply',
18
+ 'matrix', 'array',
19
+ 'rownames', 'colnames',
20
+ 'list.files', 'tolower', 'toupper', 'printf',
21
+ '<-', '->', '=', '<<-', '->>', 'assign', 'get',
22
+ '[', '[[', '$', 'length<-', 'dim<-', 'names<-', 'colnames<-', 'rownames<-',
23
+ 'as.character', 'as.numeric', 'as.logical', 'as.raw', 'as.list', 'as.data.frame', 'as.matrix', 'as.array',
24
+ 'identity', 'invisible', 'return', 'force', 'missing',
25
+ 'print', 'cat', 'message', 'warning', 'stop',
26
+ 'format', 'sprintf', 'formatC',
27
+ 'is.na', 'is.null', 'is.numeric', 'is.character',
28
+ 'which', 'match', 'order', 'sort', 'unique', 'duplicated', 'na.omit',
29
+ 'grep', 'grepl', 'sub', 'gsub', 'regexpr', 'gregexpr', 'regexec', 'regmatches',
30
+ 'as.integer', 'as.double', 'as.complex',
31
+ 'trimws', 'seq_len', 'seq_along', 'rep.int',
32
+ 'pmin', 'pmax', 'cumsum', 'cumprod', 'cummax', 'cummin', 'diff', 'signif',
33
+ 'table', 'prop.table', 'xtabs',
34
+ 'rbind', 'cbind', 't', 'crossprod', 'tcrossprod',
35
+ 'colSums', 'rowSums', 'colMeans', 'rowMeans',
36
+ 'solve', 'det', 'eigen',
37
+ 'is.factor', 'is.logical', 'is.vector', 'is.matrix', 'is.data.frame',
38
+ ];
39
+ exports.SystemFunctions = ['system', 'system2', 'pipe', 'shell', 'shell.exec'];
40
+ exports.FfiFunctions = ['.C', '.Call', '.Fortran', '.External', 'dyn.load', 'sourceCpp', 'getNativeSymbolInfo'];
41
+ exports.LangFunctions = [
42
+ 'substitute', 'quote', 'enquote', 'bquote',
43
+ 'call', 'as.call', 'expression', 'as.expression', // 'str2lang', 'str2expression',
44
+ 'as.name', 'as.symbol', 'alist', 'as.language', 'evalq',
45
+ 'expr', 'exprs', 'enexpr', 'enexprs', 'inject',
46
+ 'quo', 'quos', 'enquo', 'enquos', 'enquo0', 'enquos0',
47
+ 'sym', 'syms', 'ensym', 'ensyms'
48
+ ];
49
+ exports.OptionsFunctions = ['options', 'getOption', 'Sys.getenv'];
50
+ exports.UserFunctions = [
51
+ 'readline', 'scan', 'askYesNo',
52
+ 'file.choose', 'choose.files', 'choose.dir', 'menu', 'select.list', 'winDialogString', 'winDialog',
53
+ 'showPrompt', 'askForPassword', 'selectDirectory', 'selectFile',
54
+ 'dlgInput', 'dlgOpen',
55
+ ];
56
+ //# sourceMappingURL=input-source-functions.js.map
@@ -1,5 +1,5 @@
1
1
  import type { BasicQueryData } from '../../base-query-format';
2
- import type { InputSourcesQuery, InputSourcesQueryResult } from './input-sources-query-format';
2
+ import { type InputSourcesQuery, type InputSourcesQueryResult } from './input-sources-query-format';
3
3
  /**
4
4
  * Execute an input sources query
5
5
  */