@eagleoutice/flowr 2.16.7 → 2.17.0
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.
- package/README.md +16 -10
- package/abstract-interpretation/absint-inference.d.ts +17 -1
- package/abstract-interpretation/absint-inference.js +118 -3
- package/abstract-interpretation/data-frame/arguments.d.ts +11 -1
- package/abstract-interpretation/data-frame/arguments.js +12 -0
- package/abstract-interpretation/domains/lattice.d.ts +2 -0
- package/abstract-interpretation/domains/lattice.js +0 -6
- package/abstract-interpretation/domains/multi-value-state-domain.d.ts +2 -1
- package/abstract-interpretation/domains/multi-value-state-domain.js +7 -3
- package/abstract-interpretation/domains/partial-product-domain.js +2 -1
- package/abstract-interpretation/domains/state-abstract-domain.d.ts +6 -3
- package/abstract-interpretation/domains/state-abstract-domain.js +13 -7
- package/abstract-interpretation/domains/state-domain.d.ts +4 -0
- package/config.js +1 -1
- package/control-flow/useless-loop.js +10 -8
- package/data/r-primitives.generated.d.ts +1 -0
- package/data/r-primitives.generated.js +9 -0
- package/data/sigdb/sigdb.remote.json +110 -110
- package/dataflow/environments/identifier.d.ts +1 -1
- package/dataflow/environments/query-fn-props.d.ts +9 -3
- package/dataflow/environments/query-fn-props.js +13 -5
- package/dataflow/environments/reference-to-maybe.js +1 -6
- package/dataflow/fn/class-declaration.js +1 -8
- package/dataflow/graph/dataflowgraph-builder.d.ts +4 -4
- package/dataflow/graph/df-helper.d.ts +2 -0
- package/dataflow/graph/df-helper.js +7 -0
- package/dataflow/graph/graph.js +3 -10
- package/dataflow/graph/vertex.d.ts +1 -1
- package/dataflow/hooks.d.ts +1 -1
- package/dataflow/info.d.ts +3 -3
- package/dataflow/internal/linker.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +1 -7
- package/dataflow/processor.d.ts +1 -1
- package/documentation/wiki-linter.js +29 -0
- package/documentation/wiki-query.js +20 -1
- package/linter/linter-executor.js +2 -1
- package/linter/linter-rules.d.ts +65 -0
- package/linter/linter-rules.js +5 -1
- package/linter/rules/cmd-check/global-environment-modification.d.ts +14 -1
- package/linter/rules/cmd-check/global-environment-modification.js +15 -7
- package/linter/rules/no-leaked-credentials.d.ts +1 -0
- package/linter/rules/no-leaked-credentials.js +3 -3
- package/linter/rules/process-state-in-session.d.ts +71 -0
- package/linter/rules/process-state-in-session.js +267 -0
- package/linter/rules/secret-exfiltration.d.ts +80 -0
- package/linter/rules/secret-exfiltration.js +183 -0
- package/package.json +1 -1
- package/project/flowr-analyzer.d.ts +6 -0
- package/project/flowr-analyzer.js +4 -0
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +2 -0
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +22 -3
- package/project/sigdb/decompress.d.ts +4 -0
- package/project/sigdb/decompress.js +60 -25
- package/project/sigdb/manifest.d.ts +1 -1
- package/project/sigdb/manifest.js +2 -5
- package/project/sigdb/reader.js +15 -6
- package/project/sigdb/sigdb-download.d.ts +3 -7
- package/project/sigdb/sigdb-download.js +71 -72
- package/queries/catalog/taint-query/taint-query-executor.d.ts +7 -0
- package/queries/catalog/taint-query/taint-query-executor.js +30 -0
- package/queries/catalog/taint-query/taint-query-format.d.ts +29 -0
- package/queries/catalog/taint-query/taint-query-format.js +124 -0
- package/queries/query.d.ts +12 -1
- package/queries/query.js +2 -0
- package/taint-analysis/builder/domain.d.ts +14 -0
- package/taint-analysis/builder/domain.js +69 -0
- package/taint-analysis/builder/report-template.d.ts +50 -0
- package/taint-analysis/builder/report-template.js +46 -0
- package/taint-analysis/builder/taint-analysis-definition.d.ts +108 -0
- package/taint-analysis/builder/taint-analysis-definition.js +128 -0
- package/taint-analysis/builder/taint-analysis.d.ts +124 -0
- package/taint-analysis/builder/taint-analysis.js +93 -0
- package/taint-analysis/builtin-index-bridge.d.ts +20 -0
- package/taint-analysis/builtin-index-bridge.js +48 -0
- package/taint-analysis/eval/eval.d.ts +1 -0
- package/taint-analysis/eval/eval.js +124 -0
- package/taint-analysis/eval/instrumentation.d.ts +59 -0
- package/taint-analysis/eval/instrumentation.js +124 -0
- package/taint-analysis/finite-domain.d.ts +41 -0
- package/taint-analysis/finite-domain.js +118 -0
- package/taint-analysis/function-categories.d.ts +31 -0
- package/taint-analysis/function-categories.js +61 -0
- package/taint-analysis/logger.d.ts +1 -0
- package/taint-analysis/logger.js +6 -0
- package/taint-analysis/predefined/determinism.d.ts +6 -0
- package/taint-analysis/predefined/determinism.js +14 -0
- package/taint-analysis/predefined/normalization.d.ts +17 -0
- package/taint-analysis/predefined/normalization.js +150 -0
- package/taint-analysis/predefined/predefined.d.ts +12 -0
- package/taint-analysis/predefined/predefined.js +18 -0
- package/taint-analysis/predefined/randomness-analysis.d.ts +6 -0
- package/taint-analysis/predefined/randomness-analysis.js +124 -0
- package/taint-analysis/predefined/secret-analysis.d.ts +77 -0
- package/taint-analysis/predefined/secret-analysis.js +165 -0
- package/taint-analysis/predefined/security-analysis.d.ts +7 -0
- package/taint-analysis/predefined/security-analysis.js +91 -0
- package/taint-analysis/taint-mapping.d.ts +86 -0
- package/taint-analysis/taint-mapping.js +70 -0
- package/taint-analysis/taint-resolve.d.ts +26 -0
- package/taint-analysis/taint-resolve.js +86 -0
- package/taint-analysis/taint-visitor.d.ts +80 -0
- package/taint-analysis/taint-visitor.js +82 -0
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
|
@@ -25,7 +25,7 @@ export declare function selectDownloadVariants(names: Iterable<string>): string[
|
|
|
25
25
|
export interface SigDbDownloadOptions {
|
|
26
26
|
/** GitHub `owner/repo` (default `flowr-analysis/flowr`) */
|
|
27
27
|
readonly repo?: string;
|
|
28
|
-
/**
|
|
28
|
+
/** an explicit release (tag `<v>`, `v<v>`, or `sigdb-v<v>`), else the pointer's tag */
|
|
29
29
|
readonly version?: string;
|
|
30
30
|
/** progress callback (one line per step) */
|
|
31
31
|
readonly onProgress?: (msg: string) => void;
|
|
@@ -69,13 +69,9 @@ export declare const isManifestFile: (name: string) => boolean;
|
|
|
69
69
|
* Use the returned {@link SigDbDownloadResult.manifest}, or point `solver.sigdb.additionalPaths` at the dir.
|
|
70
70
|
*/
|
|
71
71
|
export declare function downloadFullSigDb(opts?: SigDbDownloadOptions): Promise<SigDbDownloadResult>;
|
|
72
|
-
/**
|
|
73
|
-
* The cache dir a {@link downloadFullSigDb} for the committed link file would populate, or `undefined` if no
|
|
74
|
-
* pointer is committed. Lets a caller mount an already-synced bundle via `solver.sigdb.additionalPaths` without
|
|
75
|
-
* hitting the network.
|
|
76
|
-
*/
|
|
72
|
+
/** the cache dir {@link downloadFullSigDb} populates, `undefined` if the pointer is broken */
|
|
77
73
|
export declare function syncedSigDbDir(): string | undefined;
|
|
78
|
-
/** the GitHub release
|
|
74
|
+
/** the GitHub release the pointer downloads from, `undefined` if it is broken */
|
|
79
75
|
export declare function sigDbRemoteRelease(): {
|
|
80
76
|
repo: string;
|
|
81
77
|
tag: string;
|
|
@@ -17,7 +17,7 @@ const https_1 = __importDefault(require("https"));
|
|
|
17
17
|
const crypto_1 = __importDefault(require("crypto"));
|
|
18
18
|
const decompress_1 = require("./decompress");
|
|
19
19
|
const codec_1 = require("./codec");
|
|
20
|
-
const
|
|
20
|
+
const sigdb_remote_json_1 = __importDefault(require("../../data/sigdb/sigdb.remote.json"));
|
|
21
21
|
const files_1 = require("../../util/files");
|
|
22
22
|
const secure_mode_1 = require("../../util/secure-mode");
|
|
23
23
|
/** the GitHub `owner/repo` the full-history bundle is published to (see `scripts/publish-sigdb.mjs`) */
|
|
@@ -93,7 +93,7 @@ const mb = (bytes) => `${(bytes / 1e6).toFixed(1)} MB`;
|
|
|
93
93
|
const rate = (bytes, ms) => `${(bytes / 1e6 / Math.max(ms / 1000, 0.001)).toFixed(1)} MB/s`;
|
|
94
94
|
/** Download `url` to `dest` via a temporary file, so a partial or corrupt file never lands there (checked against `sha256`, if given). */
|
|
95
95
|
async function downloadTo(url, dest, name, progress, expected) {
|
|
96
|
-
const part =
|
|
96
|
+
const part = (0, decompress_1.uniqueTempPath)(dest, 'part');
|
|
97
97
|
const start = Date.now();
|
|
98
98
|
try {
|
|
99
99
|
const res = await httpGet(url, 'application/octet-stream');
|
|
@@ -139,26 +139,19 @@ const sha256File = (p) => crypto_1.default.createHash('sha256').update(fs_1.defa
|
|
|
139
139
|
exports.sha256File = sha256File;
|
|
140
140
|
/** the committed link file naming every downloadable shard (base floor + CRAN sets); only this pointer is committed */
|
|
141
141
|
exports.SigDbRemoteFileName = 'sigdb.remote.json';
|
|
142
|
-
/**
|
|
143
|
-
function
|
|
142
|
+
/** the file `$FLOWR_SIGDB_REMOTE` names, else the committed link file (inlined at build time) */
|
|
143
|
+
function remotePointer() {
|
|
144
144
|
const override = process.env.FLOWR_SIGDB_REMOTE;
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
return override ? readPointerChecked(override) : checkedPointer(sigdb_remote_json_1.default, exports.SigDbRemoteFileName);
|
|
146
|
+
}
|
|
147
|
+
function tryRemotePointer() {
|
|
148
|
+
try {
|
|
149
|
+
return remotePointer();
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return undefined;
|
|
147
153
|
}
|
|
148
|
-
const candidates = [
|
|
149
|
-
// src/ and dist/src/ layouts (same depth); never the working directory, which may be the analyzed (untrusted) project
|
|
150
|
-
path_1.default.join(__dirname, '../../data/sigdb', exports.SigDbRemoteFileName),
|
|
151
|
-
];
|
|
152
|
-
return candidates.find(p => {
|
|
153
|
-
try {
|
|
154
|
-
return fs_1.default.existsSync(p);
|
|
155
|
-
}
|
|
156
|
-
catch {
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
154
|
}
|
|
161
|
-
const readPointer = (p) => JSON.parse(fs_1.default.readFileSync(p, 'utf8'));
|
|
162
155
|
/** the direct release-asset URL, which avoids the REST API rate limit; `$FLOWR_SIGDB_MIRROR` replaces the host */
|
|
163
156
|
const assetUrl = (repo, tag, name) => `${process.env.FLOWR_SIGDB_MIRROR ?? 'https://github.com'}/${repo}/releases/download/${tag}/${encodeURIComponent(name)}`;
|
|
164
157
|
/** runtime-decodable variant extensions, most-preferred first, ending in plain (`''`) as a last resort */
|
|
@@ -293,17 +286,19 @@ async function syncFiles(tag, repo, planned, opts) {
|
|
|
293
286
|
}
|
|
294
287
|
return { tag, dir, manifest: pickManifest(files), files, downloaded, bytes, ms, stale };
|
|
295
288
|
}
|
|
296
|
-
/** read the committed link file, naming it in the error when it is broken */
|
|
297
289
|
function readPointerChecked(p) {
|
|
298
290
|
let remote;
|
|
299
291
|
try {
|
|
300
|
-
remote =
|
|
292
|
+
remote = JSON.parse(fs_1.default.readFileSync(p, 'utf8'));
|
|
301
293
|
}
|
|
302
294
|
catch (e) {
|
|
303
295
|
throw new Error(`cannot read the signature database link file ${p}: ${e.message}`, { cause: e });
|
|
304
296
|
}
|
|
305
|
-
|
|
306
|
-
|
|
297
|
+
return checkedPointer(remote, p);
|
|
298
|
+
}
|
|
299
|
+
function checkedPointer(remote, origin) {
|
|
300
|
+
if (typeof remote?.tag !== 'string' || typeof remote.shards !== 'object' || remote.shards === null) {
|
|
301
|
+
throw new Error(`the signature database link file ${origin} names no tag or shards`);
|
|
307
302
|
}
|
|
308
303
|
return remote;
|
|
309
304
|
}
|
|
@@ -313,69 +308,73 @@ function readPointerChecked(p) {
|
|
|
313
308
|
* Use the returned {@link SigDbDownloadResult.manifest}, or point `solver.sigdb.additionalPaths` at the dir.
|
|
314
309
|
*/
|
|
315
310
|
async function downloadFullSigDb(opts = {}) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (pointerPath) {
|
|
319
|
-
const remote = readPointerChecked(pointerPath);
|
|
320
|
-
const repo = opts.repo ?? remote.repo ?? DefaultRepo;
|
|
321
|
-
// one variant per logical shard/dictionary -- the best this runtime can decompress (never both codecs)
|
|
322
|
-
const planned = selectDownloadVariants(Object.keys(remote.shards)).map(name => ({
|
|
323
|
-
name, url: assetUrl(repo, remote.tag, name), expected: remote.shards[name]
|
|
324
|
-
}));
|
|
325
|
-
return syncFiles(remote.tag, repo, planned, opts);
|
|
311
|
+
if (opts.version !== undefined) {
|
|
312
|
+
return downloadRelease(opts.version, opts);
|
|
326
313
|
}
|
|
327
|
-
|
|
314
|
+
const remote = remotePointer();
|
|
315
|
+
const repo = opts.repo ?? remote.repo ?? DefaultRepo;
|
|
316
|
+
// one variant per shard, the best codec this runtime supports
|
|
317
|
+
const planned = selectDownloadVariants(Object.keys(remote.shards)).map(name => ({
|
|
318
|
+
name, url: assetUrl(repo, remote.tag, name), expected: remote.shards[name]
|
|
319
|
+
}));
|
|
320
|
+
return syncFiles(remote.tag, repo, planned, opts);
|
|
321
|
+
}
|
|
322
|
+
function releaseTagCandidates(version) {
|
|
323
|
+
const bare = version.replace(/^(sigdb-)?v/, '');
|
|
324
|
+
return [...new Set([version, `v${bare}`, `sigdb-v${bare}`])];
|
|
325
|
+
}
|
|
326
|
+
async function downloadRelease(version, opts) {
|
|
327
|
+
const progress = opts.onProgress ?? (() => { });
|
|
328
328
|
const repo = opts.repo ?? DefaultRepo;
|
|
329
|
-
const
|
|
330
|
-
const tag
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
329
|
+
const tried = [];
|
|
330
|
+
for (const tag of releaseTagCandidates(version)) {
|
|
331
|
+
progress(`listing release ${tag} of ${repo}`);
|
|
332
|
+
let release;
|
|
333
|
+
try {
|
|
334
|
+
release = await withRetries(`listing ${tag}`, () => readJson(`https://api.github.com/repos/${repo}/releases/tags/${tag}`), progress);
|
|
335
|
+
}
|
|
336
|
+
catch (e) {
|
|
337
|
+
if (!(e instanceof HttpError) || e.retryable) {
|
|
338
|
+
throw e;
|
|
339
|
+
}
|
|
340
|
+
tried.push(`${tag}: ${e.message}`);
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
const assets = (release.assets ?? [])
|
|
344
|
+
.filter(a => a.name.endsWith('.br') || a.name.endsWith('.zst') || a.name.endsWith('.manifest.json'));
|
|
345
|
+
if (assets.length === 0) {
|
|
346
|
+
tried.push(`${tag}: no signature-database assets`);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
const byName = new Map(assets.map(a => [a.name, a]));
|
|
350
|
+
const planned = selectDownloadVariants(byName.keys()).map(name => {
|
|
351
|
+
const a = byName.get(name);
|
|
352
|
+
return { name, url: a.browser_download_url, size: a.size };
|
|
353
|
+
});
|
|
354
|
+
return syncFiles(tag, repo, planned, opts);
|
|
337
355
|
}
|
|
338
|
-
|
|
339
|
-
const planned = selectDownloadVariants(byName.keys()).map(name => {
|
|
340
|
-
const a = byName.get(name);
|
|
341
|
-
return { name, url: a.browser_download_url, size: a.size };
|
|
342
|
-
});
|
|
343
|
-
return syncFiles(tag, repo, planned, opts);
|
|
356
|
+
throw new Error(`no signature database release for ${version} in ${repo} (${tried.join('; ')})`);
|
|
344
357
|
}
|
|
345
|
-
/**
|
|
346
|
-
* The cache dir a {@link downloadFullSigDb} for the committed link file would populate, or `undefined` if no
|
|
347
|
-
* pointer is committed. Lets a caller mount an already-synced bundle via `solver.sigdb.additionalPaths` without
|
|
348
|
-
* hitting the network.
|
|
349
|
-
*/
|
|
358
|
+
/** the cache dir {@link downloadFullSigDb} populates, `undefined` if the pointer is broken */
|
|
350
359
|
function syncedSigDbDir() {
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
return undefined;
|
|
354
|
-
}
|
|
355
|
-
return path_1.default.join((0, decompress_1.sigDbCacheDir)(), 'bundles', readPointer(pointerPath).tag);
|
|
360
|
+
const remote = tryRemotePointer();
|
|
361
|
+
return remote && path_1.default.join((0, decompress_1.sigDbCacheDir)(), 'bundles', remote.tag);
|
|
356
362
|
}
|
|
357
|
-
/** the GitHub release
|
|
363
|
+
/** the GitHub release the pointer downloads from, `undefined` if it is broken */
|
|
358
364
|
function sigDbRemoteRelease() {
|
|
359
|
-
const
|
|
360
|
-
if (!
|
|
361
|
-
return undefined;
|
|
362
|
-
}
|
|
363
|
-
try {
|
|
364
|
-
const remote = readPointer(pointerPath);
|
|
365
|
-
const repo = remote.repo ?? DefaultRepo;
|
|
366
|
-
return { repo, tag: remote.tag, url: `https://github.com/${repo}/releases/tag/${remote.tag}` };
|
|
367
|
-
}
|
|
368
|
-
catch {
|
|
365
|
+
const remote = tryRemotePointer();
|
|
366
|
+
if (!remote) {
|
|
369
367
|
return undefined;
|
|
370
368
|
}
|
|
369
|
+
const repo = remote.repo ?? DefaultRepo;
|
|
370
|
+
return { repo, tag: remote.tag, url: `https://github.com/${repo}/releases/tag/${remote.tag}` };
|
|
371
371
|
}
|
|
372
372
|
function withSelectedShards(f) {
|
|
373
|
-
const
|
|
374
|
-
if (!
|
|
373
|
+
const remote = tryRemotePointer();
|
|
374
|
+
if (!remote) {
|
|
375
375
|
return false;
|
|
376
376
|
}
|
|
377
377
|
try {
|
|
378
|
-
const remote = readPointer(pointerPath);
|
|
379
378
|
return f(remote, path_1.default.join((0, decompress_1.sigDbCacheDir)(undefined, false), 'bundles', remote.tag), selectDownloadVariants(Object.keys(remote.shards)));
|
|
380
379
|
}
|
|
381
380
|
catch {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BasicQueryData } from '../../base-query-format';
|
|
2
|
+
import type { TaintQuery, TaintQueryResult } from './taint-query-format';
|
|
3
|
+
import type { AllPredefinedTaintAnalysisNames } from '../../../taint-analysis/predefined/predefined';
|
|
4
|
+
/**
|
|
5
|
+
* Executes the given taint queries using the provided analyzer.
|
|
6
|
+
*/
|
|
7
|
+
export declare function executeTaintQuery({ analyzer }: BasicQueryData, queries: readonly TaintQuery[]): Promise<TaintQueryResult<AllPredefinedTaintAnalysisNames>>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeTaintQuery = executeTaintQuery;
|
|
4
|
+
const log_1 = require("../../../util/log");
|
|
5
|
+
/**
|
|
6
|
+
* Executes the given taint queries using the provided analyzer.
|
|
7
|
+
*/
|
|
8
|
+
async function executeTaintQuery({ analyzer }, queries) {
|
|
9
|
+
const flattened = queries.flatMap(q => q.defs);
|
|
10
|
+
const start = Date.now();
|
|
11
|
+
if (flattened.length === 0) {
|
|
12
|
+
log_1.log.warn('Missing taint query definition');
|
|
13
|
+
return {
|
|
14
|
+
results: new Map(),
|
|
15
|
+
'.meta': {
|
|
16
|
+
timing: Date.now() - start
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const analysis = analyzer
|
|
21
|
+
.taint()
|
|
22
|
+
.addPredefined(...flattened);
|
|
23
|
+
return {
|
|
24
|
+
results: await analysis.run(),
|
|
25
|
+
'.meta': {
|
|
26
|
+
timing: Date.now() - start
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=taint-query-executor.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BaseQueryFormat, BaseQueryResult } from '../../base-query-format';
|
|
2
|
+
import type { ReplOutput } from '../../../cli/repl/commands/repl-main';
|
|
3
|
+
import type { FlowrConfig } from '../../../config';
|
|
4
|
+
import type { ParsedQueryLine } from '../../query';
|
|
5
|
+
import Joi from 'joi';
|
|
6
|
+
import { executeTaintQuery } from './taint-query-executor';
|
|
7
|
+
import type { AnyPredefinedTaintAnalysisName } from '../../../taint-analysis/predefined/predefined';
|
|
8
|
+
import type { CommandCompletions } from '../../../cli/repl/core';
|
|
9
|
+
import type { TaintInferenceResult } from '../../../taint-analysis/builder/taint-analysis';
|
|
10
|
+
export interface TaintQuery extends BaseQueryFormat {
|
|
11
|
+
readonly type: 'taint';
|
|
12
|
+
readonly defs: AnyPredefinedTaintAnalysisName[];
|
|
13
|
+
}
|
|
14
|
+
export interface TaintQueryResult<Analyses extends string[]> extends BaseQueryResult {
|
|
15
|
+
readonly results: Map<Analyses[number], TaintInferenceResult>;
|
|
16
|
+
}
|
|
17
|
+
declare function taintQueryCompleter(line: readonly string[], startingNewArg: boolean, _config: FlowrConfig): CommandCompletions;
|
|
18
|
+
declare function taintQueryLineParser(output: ReplOutput, line: readonly string[], _config: FlowrConfig): ParsedQueryLine<'taint'>;
|
|
19
|
+
export declare const TaintQueryDefinition: {
|
|
20
|
+
readonly title: "Taint Analysis Query";
|
|
21
|
+
readonly executor: typeof executeTaintQuery;
|
|
22
|
+
readonly asciiSummarizer: (formatter: import("../../../util/text/ansi").OutputFormatter, _analyzer: import("../../..").ReadonlyFlowrAnalysisProvider<import("../../..").KnownParser>, queryResults: BaseQueryResult, resultStrings: string[]) => true;
|
|
23
|
+
readonly jsonFormatter: (queryResults: BaseQueryResult) => object;
|
|
24
|
+
readonly completer: typeof taintQueryCompleter;
|
|
25
|
+
readonly fromLine: typeof taintQueryLineParser;
|
|
26
|
+
readonly schema: Joi.ObjectSchema<any>;
|
|
27
|
+
readonly flattenInvolvedNodes: () => never[];
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
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.TaintQueryDefinition = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const taint_query_executor_1 = require("./taint-query-executor");
|
|
9
|
+
const predefined_1 = require("../../../taint-analysis/predefined/predefined");
|
|
10
|
+
const lattice_1 = require("../../../abstract-interpretation/domains/lattice");
|
|
11
|
+
const ansi_1 = require("../../../util/text/ansi");
|
|
12
|
+
const time_1 = require("../../../util/text/time");
|
|
13
|
+
const retriever_1 = require("../../../r-bridge/retriever");
|
|
14
|
+
const prefix = 'definitions:';
|
|
15
|
+
function taintQueryCompleter(line, startingNewArg, _config) {
|
|
16
|
+
const prefixNotPresent = line.length == 0 || (line.length == 1 && line[0].length < prefix.length);
|
|
17
|
+
const notFinished = line.length == 1 && line[0].startsWith(prefix) && !startingNewArg;
|
|
18
|
+
const endOfOptions = line.length == 1 && startingNewArg || line.length == 2;
|
|
19
|
+
if (prefixNotPresent) {
|
|
20
|
+
return { completions: [`${prefix}`] };
|
|
21
|
+
}
|
|
22
|
+
else if (endOfOptions) {
|
|
23
|
+
return { completions: [retriever_1.fileProtocol] };
|
|
24
|
+
}
|
|
25
|
+
else if (notFinished) {
|
|
26
|
+
const withoutPrefix = line[0].slice(prefix.length);
|
|
27
|
+
const used = withoutPrefix.split(',').map(r => r.trim());
|
|
28
|
+
const all = Object.keys(predefined_1.predefinedTaintAnalyses);
|
|
29
|
+
const unused = all.filter(r => !used.includes(r));
|
|
30
|
+
const last = used[used.length - 1];
|
|
31
|
+
const lastUnfinished = !all.includes(last);
|
|
32
|
+
if (lastUnfinished) {
|
|
33
|
+
// Return all strings that have not been added yet
|
|
34
|
+
return { completions: unused, argumentPart: last };
|
|
35
|
+
}
|
|
36
|
+
else if (unused.length > 0) {
|
|
37
|
+
// Add a comma, if the current last string is complete
|
|
38
|
+
return { completions: [','], argumentPart: '' };
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// All strings are used, complete with a space
|
|
42
|
+
return { completions: [' '], argumentPart: '' };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { completions: [] };
|
|
46
|
+
}
|
|
47
|
+
function defsInInput(defsPart) {
|
|
48
|
+
return defsPart
|
|
49
|
+
.reduce((acc, name) => {
|
|
50
|
+
name = name.trim();
|
|
51
|
+
if (name in predefined_1.predefinedTaintAnalyses) {
|
|
52
|
+
acc.valid.push(name);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
acc.invalid.push(name);
|
|
56
|
+
}
|
|
57
|
+
return acc;
|
|
58
|
+
}, { valid: [], invalid: [] });
|
|
59
|
+
}
|
|
60
|
+
function taintQueryLineParser(output, line, _config) {
|
|
61
|
+
let defs = [];
|
|
62
|
+
let input = undefined;
|
|
63
|
+
if (line.length > 0 && line[0].startsWith(prefix)) {
|
|
64
|
+
const defsPart = line[0].slice(prefix.length).split(',');
|
|
65
|
+
const parseResult = defsInInput(defsPart);
|
|
66
|
+
if (parseResult.invalid.length > 0) {
|
|
67
|
+
output.stderr(`Unknown taint definition names: ${parseResult.invalid.map(r => (0, ansi_1.bold)(r, output.formatter)).join(', ')}`
|
|
68
|
+
+ `\nKnown taint definitions are: ${Object.keys(predefined_1.predefinedTaintAnalyses).map(r => (0, ansi_1.bold)(r, output.formatter)).join(', ')}`);
|
|
69
|
+
}
|
|
70
|
+
defs = parseResult.valid;
|
|
71
|
+
input = line[1];
|
|
72
|
+
}
|
|
73
|
+
else if (line.length > 0) {
|
|
74
|
+
input = line[0];
|
|
75
|
+
}
|
|
76
|
+
return { query: [{ type: 'taint', defs: defs }], rCode: input };
|
|
77
|
+
}
|
|
78
|
+
exports.TaintQueryDefinition = {
|
|
79
|
+
title: 'Taint Analysis Query',
|
|
80
|
+
executor: taint_query_executor_1.executeTaintQuery,
|
|
81
|
+
asciiSummarizer: (formatter, _analyzer, queryResults, resultStrings) => {
|
|
82
|
+
const out = queryResults;
|
|
83
|
+
const state = out.results.entries().toArray();
|
|
84
|
+
resultStrings.push(`Query: ${(0, ansi_1.bold)('taint', formatter)} (${(0, time_1.printAsMs)(out['.meta'].timing, 0)})`);
|
|
85
|
+
for (const [name, result] of state) {
|
|
86
|
+
resultStrings.push(` ╰ **${name}**:`);
|
|
87
|
+
const lift = result.domains.value;
|
|
88
|
+
if (result.findings.length > 0) {
|
|
89
|
+
if (result.msg !== undefined) {
|
|
90
|
+
resultStrings.push(` ╰ ${result.msg}:`);
|
|
91
|
+
}
|
|
92
|
+
resultStrings.push(...result.findings.map(finding => ` ╰ ${finding.msg !== undefined ? `${finding.msg} ` : ''}`));
|
|
93
|
+
}
|
|
94
|
+
if (lift === lattice_1.Bottom) {
|
|
95
|
+
resultStrings.push(` ╰ state: ${lattice_1.BottomSymbol}`);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
resultStrings.push(...lift.entries().take(20)
|
|
99
|
+
.map(([key, domain]) => ` ╰ ${key}: ${domain?.toString()}`));
|
|
100
|
+
if (resultStrings.length > 20) {
|
|
101
|
+
resultStrings.push(' ╰ ... (see JSON)');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
},
|
|
106
|
+
jsonFormatter: (queryResults) => {
|
|
107
|
+
const { results, ...out } = queryResults;
|
|
108
|
+
const json = new Map(Array.from(results, ([name, { domains, msg, findings }]) => [name, {
|
|
109
|
+
domains: domains.value === lattice_1.Bottom ? domains.value.description : Object.fromEntries(domains.value.entries().map(([key, domain]) => [key, domain?.toJSON() ?? null])),
|
|
110
|
+
msg,
|
|
111
|
+
findings,
|
|
112
|
+
}]));
|
|
113
|
+
const result = { results: json, ...out };
|
|
114
|
+
return result;
|
|
115
|
+
},
|
|
116
|
+
completer: taintQueryCompleter,
|
|
117
|
+
fromLine: taintQueryLineParser,
|
|
118
|
+
schema: joi_1.default.object({
|
|
119
|
+
type: joi_1.default.string().valid('taint').required().description('The type of the query.'),
|
|
120
|
+
defs: joi_1.default.array().description('The taint analyses to run.')
|
|
121
|
+
}).description('The taint query conducts taint analyses and returns their results.'),
|
|
122
|
+
flattenInvolvedNodes: () => []
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=taint-query-format.js.map
|
package/queries/query.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ import type { DoesCallQuery } from './catalog/does-call-query/does-call-query-fo
|
|
|
36
36
|
import type { InspectExceptionQuery } from './catalog/inspect-exceptions-query/inspect-exception-query-format';
|
|
37
37
|
import type { InputSourcesQuery } from './catalog/input-sources-query/input-sources-query-format';
|
|
38
38
|
import type { ProvenanceQuery } from './catalog/provenance-query/provenance-query-format';
|
|
39
|
+
import type { TaintQuery } from './catalog/taint-query/taint-query-format';
|
|
39
40
|
import type { LintingResult, LintingResultCertainty } from '../linter/linter-format';
|
|
40
41
|
import { type DiceQuery } from './catalog/dice-query/dice-query-format';
|
|
41
42
|
import { type GuessDepVersionsQuery } from './catalog/guess-dep-versions-query/guess-dep-versions-query-format';
|
|
@@ -44,7 +45,7 @@ import { type FunctionInfoQuery } from './catalog/function-info-query/function-i
|
|
|
44
45
|
/**
|
|
45
46
|
* These are all queries that can be executed from within flowR
|
|
46
47
|
*/
|
|
47
|
-
export type Query = CallContextQuery | ConfigQuery | SearchQuery | DataflowQuery | DoesCallQuery | CallGraphQuery | ControlFlowQuery | DataflowLensQuery | FilesQuery | AbsintQuery | NormalizedAstQuery | IdMapQuery | DataflowClusterQuery | StaticSliceQuery | DependenciesQuery | LocationMapQuery | HappensBeforeQuery | InspectExceptionQuery | InspectHigherOrderQuery | InspectRecursionQuery | InspectFnPropsQuery | ResolveValueQuery | ProjectQuery | SignatureQuery | OriginQuery | LinterQuery | ProvenanceQuery | InputSourcesQuery | DiceQuery | GuessDepVersionsQuery | FunctionInfoQuery;
|
|
48
|
+
export type Query = CallContextQuery | ConfigQuery | SearchQuery | DataflowQuery | DoesCallQuery | CallGraphQuery | ControlFlowQuery | DataflowLensQuery | FilesQuery | AbsintQuery | NormalizedAstQuery | IdMapQuery | DataflowClusterQuery | StaticSliceQuery | DependenciesQuery | LocationMapQuery | HappensBeforeQuery | InspectExceptionQuery | InspectHigherOrderQuery | InspectRecursionQuery | InspectFnPropsQuery | ResolveValueQuery | ProjectQuery | SignatureQuery | OriginQuery | LinterQuery | ProvenanceQuery | InputSourcesQuery | TaintQuery | DiceQuery | GuessDepVersionsQuery | FunctionInfoQuery;
|
|
48
49
|
export type QueryArgumentsWithType<QueryType extends BaseQueryFormat['type']> = Query & {
|
|
49
50
|
type: QueryType;
|
|
50
51
|
};
|
|
@@ -145,6 +146,16 @@ export declare const SupportedQueries: {
|
|
|
145
146
|
readonly schema: Joi.ObjectSchema<any>;
|
|
146
147
|
readonly flattenInvolvedNodes: (queryResults: BaseQueryResult) => NodeId[];
|
|
147
148
|
};
|
|
149
|
+
readonly taint: {
|
|
150
|
+
readonly title: "Taint Analysis Query";
|
|
151
|
+
readonly executor: typeof import("./catalog/taint-query/taint-query-executor").executeTaintQuery;
|
|
152
|
+
readonly asciiSummarizer: (formatter: OutputFormatter, _analyzer: ReadonlyFlowrAnalysisProvider<import("..").KnownParser>, queryResults: BaseQueryResult, resultStrings: string[]) => true;
|
|
153
|
+
readonly jsonFormatter: (queryResults: BaseQueryResult) => object;
|
|
154
|
+
readonly completer: (line: readonly string[], startingNewArg: boolean, _config: FlowrConfig) => CommandCompletions;
|
|
155
|
+
readonly fromLine: (output: ReplOutput, line: readonly string[], _config: FlowrConfig) => ParsedQueryLine<"taint">;
|
|
156
|
+
readonly schema: Joi.ObjectSchema<any>;
|
|
157
|
+
readonly flattenInvolvedNodes: () => never[];
|
|
158
|
+
};
|
|
148
159
|
readonly files: {
|
|
149
160
|
readonly title: "Files Query";
|
|
150
161
|
readonly executor: typeof import("./catalog/files-query/files-query-executor").executeFileQuery;
|
package/queries/query.js
CHANGED
|
@@ -46,6 +46,7 @@ const does_call_query_format_1 = require("./catalog/does-call-query/does-call-qu
|
|
|
46
46
|
const inspect_exception_query_format_1 = require("./catalog/inspect-exceptions-query/inspect-exception-query-format");
|
|
47
47
|
const input_sources_query_format_1 = require("./catalog/input-sources-query/input-sources-query-format");
|
|
48
48
|
const provenance_query_format_1 = require("./catalog/provenance-query/provenance-query-format");
|
|
49
|
+
const taint_query_format_1 = require("./catalog/taint-query/taint-query-format");
|
|
49
50
|
const dice_query_format_1 = require("./catalog/dice-query/dice-query-format");
|
|
50
51
|
const guess_dep_versions_query_format_1 = require("./catalog/guess-dep-versions-query/guess-dep-versions-query-format");
|
|
51
52
|
const absint_query_format_1 = require("./catalog/absint-query/absint-query-format");
|
|
@@ -59,6 +60,7 @@ exports.SupportedQueries = {
|
|
|
59
60
|
'does-call': does_call_query_format_1.DoesCallQueryDefinition,
|
|
60
61
|
'dataflow-lens': dataflow_lens_query_format_1.DataflowLensQueryDefinition,
|
|
61
62
|
'absint': absint_query_format_1.AbsintQueryDefinition,
|
|
63
|
+
'taint': taint_query_format_1.TaintQueryDefinition,
|
|
62
64
|
'files': files_query_format_1.FilesQueryDefinition,
|
|
63
65
|
'id-map': id_map_query_format_1.IdMapQueryDefinition,
|
|
64
66
|
'normalized-ast': normalized_ast_query_format_1.NormalizedAstQueryDefinition,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LatticeElements } from '../finite-domain';
|
|
2
|
+
import { FiniteDomain } from '../finite-domain';
|
|
3
|
+
export declare class FiniteDomainBuilder<Top extends symbol, Bottom extends symbol, Elements extends LatticeElements<Top, Bottom> = [Top, Bottom]> {
|
|
4
|
+
private readonly elements;
|
|
5
|
+
private readonly leqMap;
|
|
6
|
+
private _top;
|
|
7
|
+
private _bottom;
|
|
8
|
+
private addElements;
|
|
9
|
+
setTop(element: Top): this;
|
|
10
|
+
setBottom(element: Bottom): this;
|
|
11
|
+
addLeqOrder(from: Elements[number], to: Elements[number] | Elements[number][]): this;
|
|
12
|
+
private buildConfig;
|
|
13
|
+
build(initialElement?: Elements[number]): FiniteDomain<Top, Bottom, Elements>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FiniteDomainBuilder = void 0;
|
|
4
|
+
const lattice_1 = require("../../abstract-interpretation/domains/lattice");
|
|
5
|
+
const finite_domain_1 = require("../finite-domain");
|
|
6
|
+
const assert_1 = require("../../util/assert");
|
|
7
|
+
class FiniteDomainBuilder {
|
|
8
|
+
elements = new Set();
|
|
9
|
+
leqMap = new Map();
|
|
10
|
+
_top;
|
|
11
|
+
_bottom;
|
|
12
|
+
addElements(...elements) {
|
|
13
|
+
for (const element of elements) {
|
|
14
|
+
if (!this.elements.has(element)) {
|
|
15
|
+
this.elements.add(element);
|
|
16
|
+
}
|
|
17
|
+
if (!this.leqMap.has(element)) {
|
|
18
|
+
this.leqMap.set(element, new Set());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
setTop(element) {
|
|
23
|
+
this._top = element;
|
|
24
|
+
this.addElements(element);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
setBottom(element) {
|
|
28
|
+
this._bottom = element;
|
|
29
|
+
this.addElements(element);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
addLeqOrder(from, to) {
|
|
33
|
+
this.addElements(from, ...(Array.isArray(to) ? to : [to]));
|
|
34
|
+
if (!this.elements.has(from)) {
|
|
35
|
+
throw new Error(`Source element not registered: ${String(from)}`);
|
|
36
|
+
}
|
|
37
|
+
if (!Array.isArray(to)) {
|
|
38
|
+
to = [to];
|
|
39
|
+
}
|
|
40
|
+
const successors = this.leqMap.get(from);
|
|
41
|
+
(0, assert_1.guard)(successors, 'Internal error: A successor set should always exist');
|
|
42
|
+
for (const t of to) {
|
|
43
|
+
if (!this.elements.has(t)) {
|
|
44
|
+
throw new Error(`Target element not registered: ${String(t)}`);
|
|
45
|
+
}
|
|
46
|
+
successors.add(t);
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
buildConfig() {
|
|
51
|
+
if (!this._top) {
|
|
52
|
+
this.setTop(lattice_1.Top);
|
|
53
|
+
}
|
|
54
|
+
if (!this._bottom) {
|
|
55
|
+
this.setBottom(lattice_1.Bottom);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
top: this._top,
|
|
59
|
+
bottom: this._bottom,
|
|
60
|
+
elements: new Set(this.elements),
|
|
61
|
+
leq: new Map(this.leqMap),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
build(initialElement) {
|
|
65
|
+
return new finite_domain_1.FiniteDomain(initialElement ?? this._top, this.buildConfig());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.FiniteDomainBuilder = FiniteDomainBuilder;
|
|
69
|
+
//# sourceMappingURL=domain.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
2
|
+
import type { RNode } from '../../r-bridge/lang-4.x/ast/model/model';
|
|
3
|
+
import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
4
|
+
import type { SourceLocation } from '../../util/range';
|
|
5
|
+
/** Per-finding context handed to a {@link ReportTemplate}. */
|
|
6
|
+
export interface FindingContext {
|
|
7
|
+
/** The name of the taint analysis */
|
|
8
|
+
readonly name: string;
|
|
9
|
+
/** The AST node ID that reached Bottom */
|
|
10
|
+
readonly nodeId: NodeId;
|
|
11
|
+
/** The resolved AST node, if present in the id map */
|
|
12
|
+
readonly node?: RNode<ParentInformation>;
|
|
13
|
+
/** The source location of the node, if resolvable */
|
|
14
|
+
readonly loc?: SourceLocation;
|
|
15
|
+
/** The formatted source location, if resolvable */
|
|
16
|
+
readonly locString?: string;
|
|
17
|
+
/** 1-based start line of the finding, if known */
|
|
18
|
+
readonly line?: number;
|
|
19
|
+
/** 1-based start column of the finding, if known */
|
|
20
|
+
readonly column?: number;
|
|
21
|
+
/** The source file of the finding, if known */
|
|
22
|
+
readonly file?: string;
|
|
23
|
+
/** The node's lexeme, if known */
|
|
24
|
+
readonly lexeme?: string;
|
|
25
|
+
/** The called function's name, if the node resolves to a named call */
|
|
26
|
+
readonly functionName?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A report message: either a constant string, or a function rendering a message per {@link FindingContext|finding}.
|
|
30
|
+
*/
|
|
31
|
+
export type ReportTemplate = string | ((finding: FindingContext) => string);
|
|
32
|
+
/**
|
|
33
|
+
* Convenience accessor rendering the offending token of a finding: the called function's name when the
|
|
34
|
+
* finding node resolves to a named call, otherwise the node's lexeme.
|
|
35
|
+
*/
|
|
36
|
+
export declare const findingToken: (finding: FindingContext) => string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Assembles the {@link FindingContext} for a single finding from its node id and resolved node/location.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildFindingContext(name: string, nodeId: NodeId, node: RNode<ParentInformation> | undefined, loc: SourceLocation | undefined): FindingContext;
|
|
41
|
+
/**
|
|
42
|
+
* Renders a {@link ReportTemplate} for a given {@link FindingContext}.
|
|
43
|
+
* Constant strings are returned verbatim.
|
|
44
|
+
*/
|
|
45
|
+
export declare function renderReport(report: ReportTemplate, ctx: FindingContext): string;
|
|
46
|
+
/**
|
|
47
|
+
* The default report template which appends the function name or lexeme and line number of the finding to the explanatory string.
|
|
48
|
+
* @param s - Human-readable explanation of the finding
|
|
49
|
+
*/
|
|
50
|
+
export declare function defaultReportTemplate(s: string): (f: FindingContext) => string;
|