@eagleoutice/flowr 2.17.0 → 2.17.1

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 (67) hide show
  1. package/README.md +8 -8
  2. package/config.d.ts +32 -0
  3. package/config.js +22 -2
  4. package/dataflow/environments/built-in-props.d.ts +16 -2
  5. package/dataflow/environments/built-in-props.js +23 -3
  6. package/dataflow/environments/built-in.js +13 -3
  7. package/dataflow/environments/default-builtin-config.d.ts +268 -7
  8. package/dataflow/environments/default-builtin-config.js +72 -13
  9. package/dataflow/environments/identifier.d.ts +7 -1
  10. package/dataflow/extractor.js +49 -14
  11. package/dataflow/fn/function-semantics.d.ts +1 -0
  12. package/linter/rules/network-functions.js +10 -2
  13. package/linter/rules/unused-import.js +11 -1
  14. package/package.json +1 -1
  15. package/project/cache/flowr-analyzer-cache.d.ts +4 -0
  16. package/project/cache/flowr-analyzer-cache.js +11 -0
  17. package/project/context/flowr-analyzer-dependencies-context.d.ts +3 -0
  18. package/project/context/flowr-analyzer-dependencies-context.js +6 -0
  19. package/project/context/flowr-file.d.ts +2 -2
  20. package/project/context/flowr-file.js +2 -2
  21. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +39 -4
  22. package/project/plugins/file-plugins/files/flowr-manifest-files.js +134 -30
  23. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +1 -1
  24. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +7 -0
  25. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +14 -1
  26. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
  27. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
  28. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +18 -5
  29. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +43 -15
  30. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +12 -0
  31. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -2
  32. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +58 -0
  33. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +237 -0
  34. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +8 -0
  35. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +8 -0
  36. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +7 -0
  37. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +24 -18
  38. package/project/plugins/plugin-registry.d.ts +5 -4
  39. package/project/plugins/plugin-registry.js +6 -0
  40. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
  41. package/project/sigdb/decode.js +13 -3
  42. package/project/sigdb/memory-source.d.ts +6 -4
  43. package/project/sigdb/memory-source.js +6 -5
  44. package/project/sigdb/on-demand/fetch.d.ts +18 -0
  45. package/project/sigdb/on-demand/fetch.js +127 -0
  46. package/project/sigdb/on-demand/package-sources.d.ts +40 -0
  47. package/project/sigdb/on-demand/package-sources.js +263 -0
  48. package/project/sigdb/on-demand/recoverer.d.ts +40 -0
  49. package/project/sigdb/on-demand/recoverer.js +169 -0
  50. package/project/sigdb/on-demand/remote-sources.d.ts +72 -0
  51. package/project/sigdb/on-demand/remote-sources.js +132 -0
  52. package/project/sigdb/on-demand/tar.d.ts +19 -0
  53. package/project/sigdb/on-demand/tar.js +119 -0
  54. package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +5 -0
  55. package/queries/catalog/dependencies-query/function-info/derived-functions.js +17 -1
  56. package/queries/catalog/dependencies-query/function-info/read-functions.js +3 -1
  57. package/queries/catalog/dependencies-query/function-info/write-functions.js +11 -1
  58. package/r-bridge/data/data.d.ts +29 -0
  59. package/r-bridge/data/data.js +23 -0
  60. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +4 -0
  61. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +8 -0
  62. package/taint-analysis/predefined/secret-analysis.js +7 -2
  63. package/taint-analysis/taint-mapping.d.ts +5 -2
  64. package/taint-analysis/taint-mapping.js +17 -6
  65. package/util/flowr-version.d.ts +1 -1
  66. package/util/flowr-version.js +2 -2
  67. package/util/r-version.js +4 -2
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Where an on-demand signature source looks for the source of a package no database knows: CRAN, Bioconductor,
3
+ * and GitHub repositories, each as an {@link OnDemandSource}. A plugin may hand in sources of its own (an
4
+ * r-universe, a company mirror) next to these.
5
+ */
6
+ /** A package to recover, with what the analyzed project says about where it comes from. */
7
+ export interface PackageRequest {
8
+ readonly name: string;
9
+ /** the version the project pins, if any */
10
+ readonly version?: string;
11
+ /** the GitHub repository the project installs it from, `owner/repo[/subdir][@ref]` */
12
+ readonly github?: string;
13
+ }
14
+ /** One archive that may hold the package source. */
15
+ export interface PackageArchive {
16
+ /** a `.tar.gz` (or plain `.tar`) of the package source */
17
+ readonly url: string;
18
+ /** what the recovered package says it came from, like `cran` or `github:masurp/ggmirt` */
19
+ readonly origin: string;
20
+ /** the directory of the package within the archive, for a repository holding more than the package */
21
+ readonly subdir?: string;
22
+ /**
23
+ * only worth a try once no source has the package for sure: a mirror of every package that ever was on CRAN
24
+ * also holds the ancient copy of one that moved to Bioconductor (`limma`)
25
+ */
26
+ readonly fallback?: true;
27
+ }
28
+ /** Downloads `url`, `undefined` if the server does not have it. Throws on every other failure. */
29
+ export type FetchBytes = (url: string, maxBytes: number) => Promise<Buffer | undefined>;
30
+ /** A place to look for package sources. */
31
+ export interface OnDemandSource {
32
+ /** the name the configuration lists it under (`solver.sigdb.onDemand.sources`) */
33
+ readonly name: string;
34
+ /** the archives that may hold the package, most likely first, none if this source cannot have it */
35
+ archives(request: PackageRequest, fetch: FetchBytes): Promise<readonly PackageArchive[]>;
36
+ }
37
+ /** what a source may be configured with, see `solver.sigdb.onDemand` */
38
+ export interface OnDemandSourceOptions {
39
+ /** the CRAN `src/contrib/` to fetch tarballs from */
40
+ readonly cranMirror?: string;
41
+ /** the Bioconductor host */
42
+ readonly bioconductorMirror?: string;
43
+ /** the Bioconductor release (`release`, `devel`, or a number like `3.20`) */
44
+ readonly bioconductorRelease?: string;
45
+ /** whether to use the read-only GitHub mirrors of CRAN (`cran/<pkg>`) and Bioconductor (`bioc/<pkg>`), which keep every version as a tag */
46
+ readonly githubMirrors?: boolean;
47
+ }
48
+ /** A GitHub remote as `remotes`/`pak` write it: `owner/repo`, optionally `/subdir`, `@ref`, `#pr`, or a `github::` prefix. */
49
+ export declare function parseGitHubRemote(remote: string): {
50
+ owner: string;
51
+ repo: string;
52
+ subdir?: string;
53
+ ref?: string;
54
+ } | undefined;
55
+ /** A package name R accepts, which is all that may go into a URL built from one. */
56
+ export declare function isPackageName(name: string): boolean;
57
+ /** The repository a project names for the package, or nothing. */
58
+ export declare const GitHubSource: OnDemandSource;
59
+ /**
60
+ * CRAN: a pinned version from the GitHub mirror or CRAN itself (current or archived), else the current version
61
+ * the CRAN index lists. A package CRAN no longer lists is a {@link PackageArchive#fallback} from the mirror.
62
+ */
63
+ export declare function cranSource(options?: OnDemandSourceOptions): OnDemandSource;
64
+ /** the `Package`/`Version` pairs of a `PACKAGES` index */
65
+ export declare function parsePackagesIndex(index: string): Map<string, string>;
66
+ /**
67
+ * Bioconductor: the release tarball the repository index lists, else the GitHub mirror. A Bioconductor release
68
+ * only keeps its current version of a package, so an older pinned one falls back to the mirror's newest.
69
+ */
70
+ export declare function bioconductorSource(options?: OnDemandSourceOptions): OnDemandSource;
71
+ /** The sources flowR knows by name, configured with `options`. */
72
+ export declare function builtInOnDemandSources(options?: OnDemandSourceOptions): ReadonlyMap<string, OnDemandSource>;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GitHubSource = void 0;
7
+ exports.parseGitHubRemote = parseGitHubRemote;
8
+ exports.isPackageName = isPackageName;
9
+ exports.cranSource = cranSource;
10
+ exports.parsePackagesIndex = parsePackagesIndex;
11
+ exports.bioconductorSource = bioconductorSource;
12
+ exports.builtInOnDemandSources = builtInOnDemandSources;
13
+ const zlib_1 = __importDefault(require("zlib"));
14
+ const GitHubArchive = (owner, repo, ref) => `https://codeload.github.com/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/tar.gz/${ref.split('/').map(encodeURIComponent).join('/')}`;
15
+ /** A GitHub remote as `remotes`/`pak` write it: `owner/repo`, optionally `/subdir`, `@ref`, `#pr`, or a `github::` prefix. */
16
+ function parseGitHubRemote(remote) {
17
+ const match = /^(?:github::)?([A-Za-z0-9-]+)\/([A-Za-z0-9._-]+)((?:\/[A-Za-z0-9._-]+)*)(?:@([A-Za-z0-9._/-]+)|#(\d+))?$/.exec(remote.trim());
18
+ /* no step may leave the repository (`..`) or name a hidden file */
19
+ if (match === null || [match[2], ...(match[3] ?? '').split('/'), ...(match[4] ?? '').split('/')].some(p => p === '..' || p === '.' || p.startsWith('.') && p.length > 0)) {
20
+ return undefined;
21
+ }
22
+ const [, owner, repo, subdir, ref, pr] = match;
23
+ return {
24
+ owner,
25
+ repo: repo.replace(/\.git$/, ''),
26
+ subdir: subdir ? subdir.slice(1) : undefined,
27
+ ref: pr ? `refs/pull/${pr}/head` : ref
28
+ };
29
+ }
30
+ /** A package name R accepts, which is all that may go into a URL built from one. */
31
+ function isPackageName(name) {
32
+ return /^[A-Za-z][A-Za-z0-9.]*[A-Za-z0-9]$/.test(name);
33
+ }
34
+ /** a version as it may go into a URL */
35
+ function isVersion(version) {
36
+ return version !== undefined && /^[0-9][0-9.-]*$/.test(version);
37
+ }
38
+ /** The repository a project names for the package, or nothing. */
39
+ exports.GitHubSource = {
40
+ name: 'github',
41
+ archives(request) {
42
+ const remote = request.github === undefined ? undefined : parseGitHubRemote(request.github);
43
+ if (remote === undefined) {
44
+ return Promise.resolve([]);
45
+ }
46
+ return Promise.resolve([{ url: GitHubArchive(remote.owner, remote.repo, remote.ref ?? 'HEAD'), origin: `github:${remote.owner}/${remote.repo}`, subdir: remote.subdir }]);
47
+ }
48
+ };
49
+ /** the `PACKAGES` index at `url` (fetched once), empty if it cannot be had */
50
+ function packagesIndex(url, fetch, cache) {
51
+ let index = cache.get(url);
52
+ if (index === undefined) {
53
+ index = fetch(url, 64 * 1024 * 1024)
54
+ .then(b => b === undefined ? new Map() : parsePackagesIndex((b[0] === 0x1f && b[1] === 0x8b ? zlib_1.default.gunzipSync(b) : b).toString('utf8')))
55
+ .catch(() => new Map());
56
+ cache.set(url, index);
57
+ }
58
+ return index;
59
+ }
60
+ /**
61
+ * CRAN: a pinned version from the GitHub mirror or CRAN itself (current or archived), else the current version
62
+ * the CRAN index lists. A package CRAN no longer lists is a {@link PackageArchive#fallback} from the mirror.
63
+ */
64
+ function cranSource(options = {}) {
65
+ const mirror = (options.cranMirror ?? 'https://cloud.r-project.org/src/contrib/').replace(/\/?$/, '/');
66
+ const github = options.githubMirrors !== false;
67
+ const indices = new Map();
68
+ const ofVersion = (name, version) => {
69
+ const file = `${name}_${version}.tar.gz`;
70
+ return [
71
+ ...github ? [{ url: GitHubArchive('cran', name, `refs/tags/${version}`), origin: 'cran' }] : [],
72
+ { url: `${mirror}${file}`, origin: 'cran' },
73
+ { url: `${mirror}Archive/${name}/${file}`, origin: 'cran' }
74
+ ];
75
+ };
76
+ return {
77
+ name: 'cran',
78
+ async archives({ name, version }, fetch) {
79
+ if (isVersion(version)) {
80
+ return ofVersion(name, version);
81
+ }
82
+ const current = (await packagesIndex(`${mirror}PACKAGES.gz`, fetch, indices)).get(name);
83
+ if (current !== undefined && isVersion(current)) {
84
+ return ofVersion(name, current);
85
+ }
86
+ return github ? [{ url: GitHubArchive('cran', name, 'HEAD'), origin: 'cran', fallback: true }] : [];
87
+ }
88
+ };
89
+ }
90
+ /** the Bioconductor repositories a package may live in */
91
+ const BioconductorRepositories = ['bioc', 'data/annotation', 'data/experiment', 'workflows', 'books'];
92
+ /** the `Package`/`Version` pairs of a `PACKAGES` index */
93
+ function parsePackagesIndex(index) {
94
+ const versions = new Map();
95
+ for (const entry of index.split(/\r?\n\s*\r?\n/)) {
96
+ const pkg = /^Package:\s*(\S+)/m.exec(entry)?.[1];
97
+ const version = /^Version:\s*(\S+)/m.exec(entry)?.[1];
98
+ if (pkg !== undefined && version !== undefined) {
99
+ versions.set(pkg, version);
100
+ }
101
+ }
102
+ return versions;
103
+ }
104
+ /**
105
+ * Bioconductor: the release tarball the repository index lists, else the GitHub mirror. A Bioconductor release
106
+ * only keeps its current version of a package, so an older pinned one falls back to the mirror's newest.
107
+ */
108
+ function bioconductorSource(options = {}) {
109
+ const host = (options.bioconductorMirror ?? 'https://bioconductor.org').replace(/\/$/, '');
110
+ const release = options.bioconductorRelease ?? 'release';
111
+ const indices = new Map();
112
+ return {
113
+ name: 'bioconductor',
114
+ async archives({ name }, fetch) {
115
+ for (const repo of BioconductorRepositories) {
116
+ const version = (await packagesIndex(`${host}/packages/${release}/${repo}/src/contrib/PACKAGES`, fetch, indices)).get(name);
117
+ if (version !== undefined && isVersion(version)) {
118
+ return [
119
+ { url: `${host}/packages/${release}/${repo}/src/contrib/${name}_${version}.tar.gz`, origin: 'bioconductor' },
120
+ ...options.githubMirrors !== false ? [{ url: GitHubArchive('bioc', name, 'HEAD'), origin: 'bioconductor' }] : []
121
+ ];
122
+ }
123
+ }
124
+ return options.githubMirrors !== false ? [{ url: GitHubArchive('bioc', name, 'HEAD'), origin: 'bioconductor', fallback: true }] : [];
125
+ }
126
+ };
127
+ }
128
+ /** The sources flowR knows by name, configured with `options`. */
129
+ function builtInOnDemandSources(options = {}) {
130
+ return new Map([exports.GitHubSource, cranSource(options), bioconductorSource(options)].map(s => [s.name, s]));
131
+ }
132
+ //# sourceMappingURL=remote-sources.js.map
@@ -0,0 +1,19 @@
1
+ /** How much an archive may unpack to, so a hostile or broken one cannot exhaust the memory. */
2
+ export interface TarLimits {
3
+ /** the most bytes the (decompressed) archive may hold */
4
+ readonly maxArchiveBytes: number;
5
+ /** the most bytes a single kept file may hold, a bigger one is skipped */
6
+ readonly maxFileBytes: number;
7
+ /** the most files to keep */
8
+ readonly maxFiles: number;
9
+ }
10
+ export declare const DefaultTarLimits: TarLimits;
11
+ /** the error for an archive that is not a tar (or gzip'ed tar) flowR can read */
12
+ export declare class TarError extends Error {
13
+ constructor(message: string);
14
+ }
15
+ /**
16
+ * The regular files of a tar archive, gzip'ed or not, whose path below the top directory `keep` accepts,
17
+ * all held in memory: nothing is written to disk, so no entry can reach outside of where it belongs.
18
+ */
19
+ export declare function readTarEntries(archive: Buffer, keep: (path: string) => boolean, limits?: TarLimits): Map<string, Buffer>;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TarError = exports.DefaultTarLimits = void 0;
7
+ exports.readTarEntries = readTarEntries;
8
+ const zlib_1 = __importDefault(require("zlib"));
9
+ exports.DefaultTarLimits = { maxArchiveBytes: 128 * 1024 * 1024, maxFileBytes: 8 * 1024 * 1024, maxFiles: 5000 };
10
+ /** the error for an archive that is not a tar (or gzip'ed tar) flowR can read */
11
+ class TarError extends Error {
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = 'TarError';
15
+ }
16
+ }
17
+ exports.TarError = TarError;
18
+ const Block = 512;
19
+ function field(header, offset, length) {
20
+ const raw = header.subarray(offset, offset + length);
21
+ const end = raw.indexOf(0);
22
+ return raw.subarray(0, end < 0 ? raw.length : end).toString('utf8');
23
+ }
24
+ function octal(header, offset, length) {
25
+ /* GNU tar stores big sizes in base-256, marked by the high bit of the first byte */
26
+ if ((header[offset] & 0x80) !== 0) {
27
+ let value = 0;
28
+ for (let i = offset + 1; i < offset + length; i++) {
29
+ value = value * 256 + header[i];
30
+ }
31
+ return value;
32
+ }
33
+ const text = field(header, offset, length).trim();
34
+ const value = text.length === 0 ? 0 : parseInt(text, 8);
35
+ if (!Number.isFinite(value) || value < 0) {
36
+ throw new TarError(`invalid number "${text}" in a tar header`);
37
+ }
38
+ return value;
39
+ }
40
+ /** the `path` record of a pax extended header, which overrides the name of the entry after it */
41
+ function paxPath(data) {
42
+ let at = 0;
43
+ while (at < data.length) {
44
+ const space = data.indexOf(0x20, at);
45
+ if (space < 0) {
46
+ break;
47
+ }
48
+ const length = parseInt(data.subarray(at, space).toString('ascii'), 10);
49
+ if (!Number.isFinite(length) || length <= 0) {
50
+ break;
51
+ }
52
+ const record = data.subarray(space + 1, at + length - 1).toString('utf8');
53
+ if (record.startsWith('path=')) {
54
+ return record.slice(5);
55
+ }
56
+ at += length;
57
+ }
58
+ return undefined;
59
+ }
60
+ /** the path without the directory every entry of a package tarball sits in (`ggmirt-HEAD/R/a.R` becomes `R/a.R`), `undefined` for one leaving it */
61
+ function relativeEntryPath(name) {
62
+ const parts = name.replaceAll('\\', '/').split('/').filter(p => p.length > 0 && p !== '.');
63
+ if (parts.length < 2 || parts.includes('..') || name.startsWith('/')) {
64
+ return undefined;
65
+ }
66
+ return parts.slice(1).join('/');
67
+ }
68
+ /**
69
+ * The regular files of a tar archive, gzip'ed or not, whose path below the top directory `keep` accepts,
70
+ * all held in memory: nothing is written to disk, so no entry can reach outside of where it belongs.
71
+ */
72
+ function readTarEntries(archive, keep, limits = exports.DefaultTarLimits) {
73
+ let tar = archive;
74
+ if (archive.length >= 2 && archive[0] === 0x1f && archive[1] === 0x8b) {
75
+ try {
76
+ tar = zlib_1.default.gunzipSync(archive, { maxOutputLength: limits.maxArchiveBytes });
77
+ }
78
+ catch (e) {
79
+ throw new TarError(`cannot decompress the archive: ${e.message}`);
80
+ }
81
+ }
82
+ const files = new Map();
83
+ let longName;
84
+ for (let at = 0; at + Block <= tar.length;) {
85
+ const header = tar.subarray(at, at + Block);
86
+ if (header.every(b => b === 0)) {
87
+ break;
88
+ }
89
+ const size = octal(header, 124, 12);
90
+ const type = String.fromCharCode(header[156] || 0x30);
91
+ const start = at + Block;
92
+ if (start + size > tar.length) {
93
+ throw new TarError('the archive ends within an entry');
94
+ }
95
+ const data = tar.subarray(start, start + size);
96
+ at = start + Math.ceil(size / Block) * Block;
97
+ if (type === 'L' || type === 'x') {
98
+ longName = type === 'L' ? field(data, 0, data.length) : paxPath(data) ?? longName;
99
+ continue;
100
+ }
101
+ const magic = field(header, 257, 6);
102
+ const prefix = magic.startsWith('ustar') ? field(header, 345, 155) : '';
103
+ const name = longName ?? (prefix ? `${prefix}/${field(header, 0, 100)}` : field(header, 0, 100));
104
+ longName = undefined;
105
+ if (type !== '0' && type !== '\0' && type !== '7') {
106
+ continue;
107
+ }
108
+ const relative = relativeEntryPath(name);
109
+ if (relative === undefined || size > limits.maxFileBytes || !keep(relative)) {
110
+ continue;
111
+ }
112
+ if (files.size >= limits.maxFiles) {
113
+ throw new TarError(`the archive holds more than ${limits.maxFiles} wanted files`);
114
+ }
115
+ files.set(relative, Buffer.from(data));
116
+ }
117
+ return files;
118
+ }
119
+ //# sourceMappingURL=tar.js.map
@@ -9,3 +9,8 @@ import type { BuiltInDefinitions } from '../../../../dataflow/environments/built
9
9
  * wrote them down.
10
10
  */
11
11
  export declare function functionInfosFromProps(props: PropSelector, except: readonly FunctionInfo[], definitions: BuiltInDefinitions): FunctionInfo[];
12
+ /**
13
+ * The entries of `entries` for built-ins telling the files they read from the ones they write ({@link FnSig.resources}),
14
+ * like `unzip(zipfile, exdir)`, which are entries of both categories, each with its own argument.
15
+ */
16
+ export declare function readingAndWritingApart(entries: readonly FunctionInfo[], definitions: BuiltInDefinitions): ReadonlySet<FunctionInfo>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.functionInfosFromProps = functionInfosFromProps;
4
+ exports.readingAndWritingApart = readingAndWritingApart;
4
5
  const function_semantics_1 = require("../../../../dataflow/fn/function-semantics");
5
6
  const built_in_props_1 = require("../../../../dataflow/environments/built-in-props");
6
7
  const query_fn_props_1 = require("../../../../dataflow/environments/query-fn-props");
@@ -29,12 +30,13 @@ function functionInfosFromProps(props, except, definitions) {
29
30
  /* a bare name speaks for every package: an entry written down without one, and whatever a link points at */
30
31
  const takenEverywhere = new Set(except.flatMap(f => [...f.package === undefined ? [f.name] : [], ...linkTargets(f)]));
31
32
  const found = [];
33
+ const written = Array.isArray(props) ? props.includes(built_in_props_1.SemanticCallTag.Writes) : props === built_in_props_1.SemanticCallTag.Writes;
32
34
  for (const d of definitions) {
33
35
  const info = d.type !== 'constant' ? d.config : undefined;
34
36
  if (info?.sig === undefined || !function_semantics_1.FunctionSemantics.call.props.hasAny(info) || !function_semantics_1.FunctionSemantics.call.props.hasAll(info, props)) {
35
37
  continue;
36
38
  }
37
- const argIdx = info.sig.findIndex(([, p]) => (p & built_in_props_1.ArgProp.Resource) !== 0);
39
+ const argIdx = built_in_props_1.FnSig.resources(info.sig, written).findIndex(([, p]) => (p & built_in_props_1.ArgProp.Resource) !== 0);
38
40
  if (argIdx < 0) {
39
41
  continue;
40
42
  }
@@ -49,4 +51,18 @@ function functionInfosFromProps(props, except, definitions) {
49
51
  }
50
52
  return found;
51
53
  }
54
+ /**
55
+ * The entries of `entries` for built-ins telling the files they read from the ones they write ({@link FnSig.resources}),
56
+ * like `unzip(zipfile, exdir)`, which are entries of both categories, each with its own argument.
57
+ */
58
+ function readingAndWritingApart(entries, definitions) {
59
+ const apart = new Set();
60
+ for (const d of definitions) {
61
+ const sig = d.type !== 'constant' ? d.config?.sig : undefined;
62
+ if (sig !== undefined && built_in_props_1.FnSig.resources(sig, true) !== sig) {
63
+ (0, query_fn_props_1.builtInNames)(d).forEach(id => apart.add(identifier_1.Identifier.toString(id)));
64
+ }
65
+ }
66
+ return new Set(entries.filter(f => apart.has(writtenAs(f))));
67
+ }
52
68
  //# sourceMappingURL=derived-functions.js.map
@@ -46,8 +46,10 @@ const ReadFunctionsWithMore = [
46
46
  ];
47
47
  /** The read entries the given built-in definitions imply, together with the ones written down here. */
48
48
  function computeReadFunctions(definitions) {
49
+ /* copying reads the file it copies */
50
+ const apart = (0, derived_functions_1.readingAndWritingApart)(other_path_functions_1.OtherPathFunctions, definitions);
49
51
  return [
50
- ...(0, derived_functions_1.functionInfosFromProps)([built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Reads], [...ReadFunctionsWithMore, ...other_path_functions_1.OtherPathFunctions, ...source_functions_1.SourceFunctions], definitions),
52
+ ...(0, derived_functions_1.functionInfosFromProps)([built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Reads], [...ReadFunctionsWithMore, ...other_path_functions_1.OtherPathFunctions.filter(f => !apart.has(f)), ...source_functions_1.SourceFunctions], definitions),
51
53
  ...ReadFunctionsWithMore
52
54
  ];
53
55
  }
@@ -15,6 +15,8 @@ const OutputRedirects = [
15
15
  const WriteFunctionsWithMore = [
16
16
  { package: 'base', name: 'save.image', argIdx: 0, argName: 'file', resolveValue: true, defaultValue: '.RData' },
17
17
  { package: 'utils', name: 'write.csv', argIdx: 1, argName: 'file', resolveValue: true },
18
+ /* the write happens in the `GET` it configures, which the dataflow cannot tell, so only this category knows it */
19
+ { package: 'httr', name: 'write_disk', argIdx: 0, argName: 'path', resolveValue: true },
18
20
  /* without a `plot`, it saves `last_plot()` */
19
21
  { package: 'ggplot2', name: 'ggsave', argIdx: 0, argName: 'filename', resolveValue: true, linkTo: [default_builtin_config_1.LinkToLastGgPlot] },
20
22
  {
@@ -53,6 +55,13 @@ const WriteFunctionsWithMore = [
53
55
  { package: 'base', name: 'file.symlink', argIdx: 1, argName: 'to', resolveValue: true },
54
56
  { package: 'base', name: 'file.link', argIdx: 1, argName: 'to', resolveValue: true },
55
57
  { package: 'utils', name: 'download.file', argIdx: 1, argName: 'destfile', resolveValue: true },
58
+ /* an archive unpacks into the working directory unless told otherwise */
59
+ { package: 'utils', name: 'unzip', argIdx: 5, argName: 'exdir', resolveValue: true, defaultValue: '.', invisible: true },
60
+ { package: 'utils', name: 'untar', argIdx: 3, argName: 'exdir', resolveValue: true, defaultValue: '.', invisible: true },
61
+ { package: 'zip', name: 'unzip', argIdx: 4, argName: 'exdir', resolveValue: true, defaultValue: '.', invisible: true },
62
+ { package: 'archive', name: 'archive_extract', argIdx: 1, argName: 'dir', resolveValue: true, defaultValue: '.', invisible: true },
63
+ /* the name the file has with the extension added or dropped, `Unknown` of the query format, which imports this module */
64
+ ...['gzip', 'gunzip', 'bzip2', 'bunzip2', 'compressFile', 'decompressFile'].map(name => ({ package: 'R.utils', name, argIdx: 1, argName: 'destname', resolveValue: true, defaultValue: 'unknown', invisible: true })),
56
65
  { package: 'base', name: 'file', argIdx: 0, argName: 'description', resolveValue: true, ignoreIf: 'mode-only-read', additionalArgs: { mode: { argIdx: 1, argName: 'open', resolveValue: true } } },
57
66
  { package: 'base', name: 'url', argIdx: 0, argName: 'description', resolveValue: true, ignoreIf: 'mode-only-read', additionalArgs: { mode: { argIdx: 1, argName: 'open', resolveValue: true } } },
58
67
  { package: 'grDevices', name: 'jpeg', argIdx: 0, argName: 'filename', resolveValue: true },
@@ -97,8 +106,9 @@ const WriteFunctionsWithMore = [
97
106
  ];
98
107
  /** The write entries the given built-in definitions imply, together with the ones written down here. */
99
108
  function computeWriteFunctions(definitions, read = (0, read_functions_1.computeReadFunctions)(definitions)) {
109
+ const apart = (0, derived_functions_1.readingAndWritingApart)(read, definitions);
100
110
  return [
101
- ...(0, derived_functions_1.functionInfosFromProps)([built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Writes], [...WriteFunctionsWithMore, ...other_path_functions_1.OtherPathFunctions, ...read], definitions),
111
+ ...(0, derived_functions_1.functionInfosFromProps)([built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Writes], [...WriteFunctionsWithMore, ...other_path_functions_1.OtherPathFunctions, ...read.filter(f => !apart.has(f))], definitions),
102
112
  ...WriteFunctionsWithMore
103
113
  ];
104
114
  }
@@ -1560,6 +1560,18 @@ export declare const flowrCapabilities: {
1560
1560
  readonly name: "uvr";
1561
1561
  readonly href: "https://github.com/nbafrank/uvr";
1562
1562
  }];
1563
+ }, {
1564
+ readonly name: "rig";
1565
+ readonly id: "version-manager-rig";
1566
+ readonly supported: "fully";
1567
+ readonly description: "_Read the configuration of [rig](https://rig.r-lib.org/proj-guide.html) projects and scripts._ Parses `rproj.toml`, the inline `# /// script` block a script declares its dependencies in, and the resolved `rproj.lock` or `<script>.R.lock`.";
1568
+ readonly url: [{
1569
+ name: string;
1570
+ href: string;
1571
+ }, {
1572
+ readonly name: "rig";
1573
+ readonly href: "https://rig.r-lib.org/scripts.html";
1574
+ }];
1563
1575
  }, {
1564
1576
  readonly name: "Installed Library";
1565
1577
  readonly id: "project-library";
@@ -1569,6 +1581,16 @@ export declare const flowrCapabilities: {
1569
1581
  name: string;
1570
1582
  href: string;
1571
1583
  }];
1584
+ }, {
1585
+ readonly name: "On-Demand Package Sources";
1586
+ readonly id: "project-on-demand-sources";
1587
+ readonly supported: "partially";
1588
+ readonly description: "_Fetch the source of a package no signature database knows when the code uses it, from CRAN, Bioconductor, or GitHub (`solver.sigdb.onDemand`)._ The repository comes from an `install_github`-style call, the `Remotes` of the `DESCRIPTION`, or the configuration. The exports come from the `NAMESPACE` (an `exportPattern` matched against the names the code defines) and the formals from the functions the `R/` files define at the top level, cached per package so a later analysis works offline. A fetched package counts as untrusted: its code is parsed, never run, only `https` to public hosts (or the configured mirrors) is used, what it states is cut down to names, formals, and a version, and it cannot take over a function that matters to security (`system`, `eval`, file and network calls), so those keep being found. Only a trusted configuration can switch this on. Function bodies are not analyzed, and a package loaded under a name only known at run time is not fetched.";
1589
+ readonly example: string;
1590
+ readonly url: [{
1591
+ name: string;
1592
+ href: string;
1593
+ }];
1572
1594
  }];
1573
1595
  }, {
1574
1596
  readonly name: "Startup and Discovery";
@@ -1648,6 +1670,13 @@ export declare const flowrCapabilities: {
1648
1670
  name: string;
1649
1671
  href: string;
1650
1672
  }];
1673
+ }, {
1674
+ readonly name: "File Dependencies";
1675
+ readonly id: "file-dependencies";
1676
+ readonly code: readonly ["file.copy", "unzip", "untar", "zip", "archive::archive_extract", "R.utils::gunzip"];
1677
+ readonly supported: "partially";
1678
+ readonly description: "_A file read after a call that wrote it, also when the call copies, moves, packs, or unpacks it._ A read of a file links to the earlier writes of a file of the same name, and calls like `file.copy(from, to)` or `unzip(zipfile, exdir)` read the files of some arguments and write those of others, so `read.csv(\"data/b.csv\")` after `unzip(\"a.zip\", exdir = \"data\")` keeps the `unzip` and whatever wrote `a.zip`. What an archive holds is unknown, so unpacking one counts as writing any file, and a read of a file nothing named before reads every such write. Paths are compared by name, not against the working directory.";
1679
+ readonly example: string;
1651
1680
  }, {
1652
1681
  readonly name: "Foreign Function Interface";
1653
1682
  readonly id: "foreign-function-interface";
@@ -1362,12 +1362,27 @@ ${await (0, doc_dfg_1.printDfGraphForCode)(parser, code, { simplified: true, tim
1362
1362
  description: '_Read the configuration of [uvr](https://github.com/nbafrank/uvr), an R project manager modelled on uv._ Parses `uvr.toml` and the `uvr.lock` beside it.',
1363
1363
  url: [Plugin('src/project/plugins/file-plugins/files/flowr-manifest-files.ts'), { name: 'uvr', href: 'https://github.com/nbafrank/uvr' }]
1364
1364
  },
1365
+ {
1366
+ name: 'rig',
1367
+ id: 'version-manager-rig',
1368
+ supported: 'fully',
1369
+ description: '_Read the configuration of [rig](https://rig.r-lib.org/proj-guide.html) projects and scripts._ Parses `rproj.toml`, the inline `# /// script` block a script declares its dependencies in, and the resolved `rproj.lock` or `<script>.R.lock`.',
1370
+ url: [Plugin('src/project/plugins/file-plugins/files/flowr-manifest-files.ts'), { name: 'rig', href: 'https://rig.r-lib.org/scripts.html' }]
1371
+ },
1365
1372
  {
1366
1373
  name: 'Installed Library',
1367
1374
  id: 'project-library',
1368
1375
  supported: 'partially',
1369
1376
  description: '_Read the package library a project installs into (`renv/library`, `packrat/lib`, or the platform library)._ Their code is not read.',
1370
1377
  url: [Plugin('src/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.ts')]
1378
+ },
1379
+ {
1380
+ name: 'On-Demand Package Sources',
1381
+ id: 'project-on-demand-sources',
1382
+ supported: 'partially',
1383
+ description: '_Fetch the source of a package no signature database knows when the code uses it, from CRAN, Bioconductor, or GitHub (`solver.sigdb.onDemand`)._ The repository comes from an `install_github`-style call, the `Remotes` of the `DESCRIPTION`, or the configuration. The exports come from the `NAMESPACE` (an `exportPattern` matched against the names the code defines) and the formals from the functions the `R/` files define at the top level, cached per package so a later analysis works offline. A fetched package counts as untrusted: its code is parsed, never run, only `https` to public hosts (or the configured mirrors) is used, what it states is cut down to names, formals, and a version, and it cannot take over a function that matters to security (`system`, `eval`, file and network calls), so those keep being found. Only a trusted configuration can switch this on. Function bodies are not analyzed, and a package loaded under a name only known at run time is not fetched.',
1384
+ example: (0, doc_code_1.codeBlock)('r', 'remotes::install_github("masurp/ggmirt")\nlibrary(ggmirt)\ntracePlot(fit, theta_range = c(-3, 3))'),
1385
+ url: [Plugin('src/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.ts')]
1371
1386
  }
1372
1387
  ]
1373
1388
  },
@@ -1446,6 +1461,14 @@ ${await (0, doc_dfg_1.printDfGraphForCode)(parser, code, { simplified: true, tim
1446
1461
  example: (0, doc_code_1.codeBlock)('r', 'd <- read.csv("in.csv")\nwrite.csv(d, "out.csv")'),
1447
1462
  url: [RLang('Operating system access')]
1448
1463
  },
1464
+ {
1465
+ name: 'File Dependencies',
1466
+ id: 'file-dependencies',
1467
+ code: ['file.copy', 'unzip', 'untar', 'zip', 'archive::archive_extract', 'R.utils::gunzip'],
1468
+ supported: 'partially',
1469
+ description: '_A file read after a call that wrote it, also when the call copies, moves, packs, or unpacks it._ A read of a file links to the earlier writes of a file of the same name, and calls like `file.copy(from, to)` or `unzip(zipfile, exdir)` read the files of some arguments and write those of others, so `read.csv("data/b.csv")` after `unzip("a.zip", exdir = "data")` keeps the `unzip` and whatever wrote `a.zip`. What an archive holds is unknown, so unpacking one counts as writing any file, and a read of a file nothing named before reads every such write. Paths are compared by name, not against the working directory.',
1470
+ example: (0, doc_code_1.codeBlock)('r', 'download.file("https://example.org/a.zip", "a.zip")\nunzip("a.zip", exdir = "data")\nd <- read.csv("data/b.csv")')
1471
+ },
1449
1472
  {
1450
1473
  name: 'Foreign Function Interface',
1451
1474
  id: 'foreign-function-interface',
@@ -29,6 +29,10 @@ export declare class TreeSitterExecutor implements SyncParser<Parser.Tree> {
29
29
  parse(request: RParseRequest & {
30
30
  filePath?: string;
31
31
  }, ctx: FlowrAnalyzerContext): Parser.Tree;
32
+ /** Parses code that belongs to no analysis, like the sources of a package, without incremental reparsing. */
33
+ parseCode(code: string): Parser.Tree;
34
+ /** Whether {@link initTreeSitter} has loaded the R grammar, which every parser needs. */
35
+ static isInitialized(): boolean;
32
36
  createQuery(source: string): Query;
33
37
  query(source: Query | string, ...tree: readonly Parser.Tree[]): QueryCapture[];
34
38
  close(): void;
@@ -98,6 +98,14 @@ class TreeSitterExecutor {
98
98
  previousTree.edit(reparseInfo.editRegion);
99
99
  return this.parser.parse(sourceCode, previousTree);
100
100
  }
101
+ /** Parses code that belongs to no analysis, like the sources of a package, without incremental reparsing. */
102
+ parseCode(code) {
103
+ return this.parser.parse(code);
104
+ }
105
+ /** Whether {@link initTreeSitter} has loaded the R grammar, which every parser needs. */
106
+ static isInitialized() {
107
+ return TreeSitterExecutor.language !== undefined;
108
+ }
101
109
  createQuery(source) {
102
110
  return this.parser.getLanguage().query(source);
103
111
  }
@@ -49,6 +49,8 @@ var SecretSinkClass;
49
49
  SecretSinkClass["Llm"] = "llm";
50
50
  })(SecretSinkClass || (exports.SecretSinkClass = SecretSinkClass = {}));
51
51
  const index = query_fn_props_1.BuiltInIndex.default();
52
+ /** the calls fetching from the network into a file, like `download.file` */
53
+ const downloads = new Set(index.withAll([built_in_props_1.SemanticCallTag.Network, built_in_props_1.SemanticCallTag.Reads, built_in_props_1.SemanticCallTag.Writes]).map(f => identifier_1.Identifier.toString(f)));
52
54
  /** functions by package, as `pkg: f g; other: h`, with `$` for methods */
53
55
  const fns = (spec) => spec.split(';').flatMap(group => {
54
56
  const [pkg, names] = group.split(':').map(p => p.trim());
@@ -78,7 +80,8 @@ exports.DefaultSecretSinks = [
78
80
  ...identifier_1.Identifier.fromAll('futile.logger', logLevels.map(l => `flog.${l}`)),
79
81
  ...fns('base: stop packageStartupMessage; rlang: inform abort; cli: cli_alert cli_alert_info cli_alert_success cli_alert_warning cli_alert_danger cli_inform cli_warn cli_abort cli_text; clipr: write_clip')
80
82
  ] },
81
- { class: SecretSinkClass.Files, fns: [...index.withAll([built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Writes]), ...fns('utils: write.csv write.csv2 write.table; base: writeBin; DBI: dbWriteTable dbAppendTable; pins: pin_write; googlesheets4: sheet_write write_sheet sheet_append; aws.s3: s3saveRDS put_object')] },
83
+ /* a download writes what it fetched rather than its arguments, which reach the network (a sink of their own) */
84
+ { class: SecretSinkClass.Files, fns: [...index.withAll([built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Writes]).filter(f => !downloads.has(identifier_1.Identifier.toString(f))), ...fns('utils: write.csv write.csv2 write.table; base: writeBin; DBI: dbWriteTable dbAppendTable; pins: pin_write; googlesheets4: sheet_write write_sheet sheet_append; aws.s3: s3saveRDS put_object')] },
82
85
  { class: SecretSinkClass.Process, fns: [...index.with(built_in_props_1.SemanticCallTag.Process), ...fns('utils: browseURL')] },
83
86
  { class: SecretSinkClass.Llm, fns: fns('ellmer: chat chat_openai chat_anthropic chat_claude chat_gemini chat_google_gemini chat_ollama chat_mistral chat_groq chat_azure_openai chat_bedrock; openai: create_chat_completion create_completion; $: chat stream chat_async stream_async chat_structured set_system_prompt') }
84
87
  ];
@@ -122,7 +125,9 @@ function createSecretAnalysis({ credentialNamePattern = exports.CredentialNamePa
122
125
  ...sources
123
126
  ],
124
127
  taint: exports.Secret
125
- }, ...(0, builtin_index_bridge_1.argValueMappingFromBuiltInIndex)(built_in_props_1.FileInputProps, built_in_props_1.ArgProp.Resource, fileTaint))
128
+ },
129
+ /* a call that also writes (a copy, an unpack, a download) moves the content and returns a status or paths */
130
+ ...(0, builtin_index_bridge_1.argValueMappingFromBuiltInIndex)(built_in_props_1.FileInputProps, built_in_props_1.ArgProp.Resource, fileTaint, built_in_props_1.SemanticCallTag.Writes))
126
131
  .through({
127
132
  identifier: [
128
133
  ...fns('digest: digest sha1 hmac; openssl: sha1 sha256 sha512 md5 sha2; sodium: password_store hash sha256; base: nzchar is.na is.null nchar identical == != isTRUE isFALSE'),
@@ -3,8 +3,11 @@ import type { FunctionParameterLocation } from '../abstract-interpretation/data-
3
3
  import type { ArgProps, FnSig } from '../dataflow/environments/built-in-props';
4
4
  import { Identifier } from '../dataflow/environments/identifier';
5
5
  export declare class TaintMapper<Domain extends AnyAbstractDomain> {
6
- mapper: TaintMappingInternal<Domain>[];
7
- constructor(mapper?: TaintMappingInternal<Domain>[]);
6
+ readonly mapper: TaintMappingInternal<Domain>[];
7
+ /** the mappings by the name they map, in the order they were added; a mapping only ever applies to a call of its name */
8
+ private readonly byName;
9
+ constructor(mapper?: readonly TaintMappingInternal<Domain>[]);
10
+ private add;
8
11
  /**
9
12
  * Add one or more taint mapping rules to the mapper
10
13
  */