@eagleoutice/flowr 2.16.8 → 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.
- 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.d.ts +32 -0
- package/config.js +23 -3
- 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/built-in-props.d.ts +16 -2
- package/dataflow/environments/built-in-props.js +23 -3
- package/dataflow/environments/built-in.js +13 -3
- package/dataflow/environments/default-builtin-config.d.ts +268 -7
- package/dataflow/environments/default-builtin-config.js +72 -13
- package/dataflow/environments/identifier.d.ts +7 -1
- package/dataflow/environments/query-fn-props.d.ts +9 -3
- package/dataflow/environments/query-fn-props.js +13 -5
- package/dataflow/extractor.js +49 -14
- package/dataflow/fn/class-declaration.js +1 -8
- package/dataflow/fn/function-semantics.d.ts +1 -0
- package/dataflow/graph/df-helper.d.ts +2 -0
- package/dataflow/graph/df-helper.js +7 -0
- 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/network-functions.js +10 -2
- 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/linter/rules/unused-import.js +11 -1
- package/package.json +1 -1
- package/project/cache/flowr-analyzer-cache.d.ts +4 -0
- package/project/cache/flowr-analyzer-cache.js +11 -0
- package/project/context/flowr-analyzer-dependencies-context.d.ts +3 -0
- package/project/context/flowr-analyzer-dependencies-context.js +6 -0
- package/project/context/flowr-file.d.ts +2 -2
- package/project/context/flowr-file.js +2 -2
- package/project/flowr-analyzer.d.ts +6 -0
- package/project/flowr-analyzer.js +4 -0
- package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +39 -4
- package/project/plugins/file-plugins/files/flowr-manifest-files.js +134 -30
- 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/plugins/file-plugins/files/flowr-rmarkdown-file.js +1 -1
- package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +7 -0
- package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +14 -1
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +18 -5
- package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +43 -15
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +12 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +58 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +237 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +8 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +8 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +7 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +24 -18
- package/project/plugins/plugin-registry.d.ts +5 -4
- package/project/plugins/plugin-registry.js +6 -0
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
- package/project/sigdb/decode.js +13 -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/memory-source.d.ts +6 -4
- package/project/sigdb/memory-source.js +6 -5
- package/project/sigdb/on-demand/fetch.d.ts +18 -0
- package/project/sigdb/on-demand/fetch.js +127 -0
- package/project/sigdb/on-demand/package-sources.d.ts +40 -0
- package/project/sigdb/on-demand/package-sources.js +263 -0
- package/project/sigdb/on-demand/recoverer.d.ts +40 -0
- package/project/sigdb/on-demand/recoverer.js +169 -0
- package/project/sigdb/on-demand/remote-sources.d.ts +72 -0
- package/project/sigdb/on-demand/remote-sources.js +132 -0
- package/project/sigdb/on-demand/tar.d.ts +19 -0
- package/project/sigdb/on-demand/tar.js +119 -0
- 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/dependencies-query/function-info/derived-functions.d.ts +5 -0
- package/queries/catalog/dependencies-query/function-info/derived-functions.js +17 -1
- package/queries/catalog/dependencies-query/function-info/read-functions.js +3 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +11 -1
- 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/r-bridge/data/data.d.ts +29 -0
- package/r-bridge/data/data.js +23 -0
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +4 -0
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +8 -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 +170 -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 +89 -0
- package/taint-analysis/taint-mapping.js +81 -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
- package/util/r-version.js +4 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { AbsintVisitorConfiguration } from '../../abstract-interpretation/absint-inference';
|
|
2
|
+
import { TaintInterpreter, type TaintProduct, type TaintVisitorConfiguration } from '../taint-visitor';
|
|
3
|
+
import { StateAbstractDomain } from '../../abstract-interpretation/domains/state-abstract-domain';
|
|
4
|
+
import type { ProductReduction } from '../../abstract-interpretation/domains/partial-product-domain';
|
|
5
|
+
import type { AnyAbstractDomain } from '../../abstract-interpretation/domains/abstract-domain';
|
|
6
|
+
import type { ReportTemplate } from './report-template';
|
|
7
|
+
import type { TaintFnCategory } from '../function-categories';
|
|
8
|
+
import type { TaintMapping, TaintConditionFunction } from '../taint-mapping';
|
|
9
|
+
import { TaintMapper } from '../taint-mapping';
|
|
10
|
+
export type TaintAnalysisName<Definition> = Definition extends RunnableTaintAnalysisDefinition<infer Name> ? Name : never;
|
|
11
|
+
/**
|
|
12
|
+
* The common interface of all (runnable) taint analysis definitions, i.e. single {@link TaintAnalysisDefinition|definitions}
|
|
13
|
+
* and {@link CompositeTaintAnalysisDefinition|composite definitions}. A runnable definition knows its name, an optional
|
|
14
|
+
* report message, and how to create the abstract interpretation visitor that conducts the analysis.
|
|
15
|
+
*/
|
|
16
|
+
export interface RunnableTaintAnalysisDefinition<Name extends string = string> {
|
|
17
|
+
/** The unique name of the taint analysis. */
|
|
18
|
+
readonly name: Name;
|
|
19
|
+
/** The optional message reported when the analysis produces a finding. */
|
|
20
|
+
readonly msg?: ReportTemplate;
|
|
21
|
+
/** Creates the abstract interpreter that conducts the taint analysis for the given configuration. */
|
|
22
|
+
createVisitor(config: TaintVisitorConfiguration, fnCategories?: TaintFnCategory[]): TaintInterpreter;
|
|
23
|
+
/** The result state of `interpreter` (created by {@link createVisitor}) for this analysis. */
|
|
24
|
+
resultState(interpreter: TaintInterpreter): StateAbstractDomain<AnyAbstractDomain>;
|
|
25
|
+
}
|
|
26
|
+
/** Options for composing multiple taint analyses into a {@link CompositeTaintAnalysisDefinition}. */
|
|
27
|
+
export interface ComposeOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Optional reductions turning the direct product into a reduced product.
|
|
30
|
+
* Each reduction may refine the inferred taints of the component analyses based on each other.
|
|
31
|
+
*/
|
|
32
|
+
reductions?: readonly ProductReduction<TaintProduct>[];
|
|
33
|
+
/** The optional message reported when the composite analysis produces a finding. */
|
|
34
|
+
report?: ReportTemplate;
|
|
35
|
+
}
|
|
36
|
+
export interface TaintAnalysisReportStage<Name extends string = string, Domain extends AnyAbstractDomain = AnyAbstractDomain> extends TaintAnalysisToStage<Name, Domain> {
|
|
37
|
+
/** Set the message reported when the analysis produces a finding. */
|
|
38
|
+
report(msg: ReportTemplate): TaintAnalysisDefinition<Name, Domain>;
|
|
39
|
+
}
|
|
40
|
+
export interface TaintAnalysisToStage<Name extends string = string, Domain extends AnyAbstractDomain = AnyAbstractDomain> extends TaintAnalysisThroughStage<Name, Domain> {
|
|
41
|
+
/** Add sink rules signaling findings by yielding Bottom. */
|
|
42
|
+
to(...fnMapping: TaintMapping<Domain>[]): TaintAnalysisReportStage<Name, Domain>;
|
|
43
|
+
}
|
|
44
|
+
export interface TaintAnalysisThroughStage<Name extends string = string, Domain extends AnyAbstractDomain = AnyAbstractDomain> extends TaintAnalysisFromStage<Name, Domain> {
|
|
45
|
+
/** Add propagator or sanitizer rules that determine the resulting taint of matching calls. */
|
|
46
|
+
through(...fnMapping: TaintMapping<Domain>[]): TaintAnalysisToStage<Name, Domain>;
|
|
47
|
+
}
|
|
48
|
+
export interface TaintAnalysisFromStage<Name extends string = string, Domain extends AnyAbstractDomain = AnyAbstractDomain> {
|
|
49
|
+
/** Add propagator or sanitizer rules that determine the resulting taint of matching calls. */
|
|
50
|
+
from(...fnMapping: TaintMapping<Domain>[]): TaintAnalysisThroughStage<Name, Domain>;
|
|
51
|
+
/** Add rules for function categories (i.e. sets of functions from {@link BuiltInIndex} fulfilling certain properties) */
|
|
52
|
+
on(category: TaintFnCategory, handler?: TaintConditionFunction<AnyAbstractDomain>): TaintAnalysisFromStage<Name, Domain>;
|
|
53
|
+
/** Shortcut when no transformers, sinks, and/or a report message should be defined */
|
|
54
|
+
getPartialDefinition(): TaintAnalysisDefinition<Name, Domain>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Fluent builder class for defining new taint analyses.
|
|
58
|
+
* Use {@link TaintAnalysisDefinition.create} to obtain an instance;
|
|
59
|
+
* The methods {@link TaintAnalysis.from}, {@link TaintAnalysis.through},
|
|
60
|
+
* {@link TaintAnalysis.to}, and {@link TaintAnalysis.report} have to be called in order.
|
|
61
|
+
*/
|
|
62
|
+
export declare class TaintAnalysisDefinition<Name extends string = string, Domain extends AnyAbstractDomain = AnyAbstractDomain, Config extends AbsintVisitorConfiguration = AbsintVisitorConfiguration> implements TaintAnalysisReportStage<Name, Domain> {
|
|
63
|
+
readonly domain: Domain;
|
|
64
|
+
mapper: TaintMapper<Domain>;
|
|
65
|
+
categories: TaintFnCategory[];
|
|
66
|
+
name: Name;
|
|
67
|
+
config: Config | undefined;
|
|
68
|
+
private _msg;
|
|
69
|
+
get msg(): ReportTemplate | undefined;
|
|
70
|
+
private constructor();
|
|
71
|
+
/**
|
|
72
|
+
* Create a new taint analysis builder. {@link run} is unreachable on the result until at least
|
|
73
|
+
* one of {@link add}, {@link addComposite}, or {@link addPredefined} has been called on it.
|
|
74
|
+
*/
|
|
75
|
+
static create<Name extends string = string, Domain extends AnyAbstractDomain = AnyAbstractDomain, Config extends AbsintVisitorConfiguration = AbsintVisitorConfiguration>(name: Name, domain: Domain, config?: Config): TaintAnalysisFromStage<Name, Domain>;
|
|
76
|
+
on(category: TaintFnCategory, handler?: TaintConditionFunction<AnyAbstractDomain>): this;
|
|
77
|
+
from(...fnMapping: TaintMapping<Domain>[]): TaintAnalysisThroughStage<Name, Domain>;
|
|
78
|
+
through(...fnMapping: TaintMapping<Domain>[]): TaintAnalysisToStage<Name, Domain>;
|
|
79
|
+
to(...fnMapping: TaintMapping<Domain>[]): TaintAnalysisReportStage<Name, Domain>;
|
|
80
|
+
report(msg: ReportTemplate): this;
|
|
81
|
+
createVisitor(config: TaintVisitorConfiguration, fnCategories?: TaintFnCategory[]): TaintInterpreter;
|
|
82
|
+
/** The end state of this single analysis, holding its own taint lattice values rather than a product of them. */
|
|
83
|
+
resultState(interpreter: TaintInterpreter): StateAbstractDomain<Domain>;
|
|
84
|
+
getPartialDefinition(): this;
|
|
85
|
+
/**
|
|
86
|
+
* Composes at least two taint analysis definitions into a single composite taint analysis.
|
|
87
|
+
* The component analyses are evaluated simultaneously during a single control-flow traversal and their taints are
|
|
88
|
+
* combined into a product of the lattice values per each CFG node (see {@link TaintInterpreter}).
|
|
89
|
+
* @param name - The unique name of the resulting composite taint analysis
|
|
90
|
+
* @param definitions - The component taint analysis definitions to compose (must have unique names)
|
|
91
|
+
* @param options - Optional reductions (for a reduced product) and a report message
|
|
92
|
+
*/
|
|
93
|
+
static compose<Name extends string>(name: Name, definitions: readonly TaintAnalysisDefinition[], options?: ComposeOptions): CompositeTaintAnalysisDefinition<Name>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A composite taint analysis definition combining multiple {@link TaintAnalysisDefinition|component analyses} into a
|
|
97
|
+
* product (or reduced product) taint analysis. Create instances via {@link TaintAnalysisDefinition.compose}.
|
|
98
|
+
*/
|
|
99
|
+
export declare class CompositeTaintAnalysisDefinition<Name extends string> implements RunnableTaintAnalysisDefinition<Name> {
|
|
100
|
+
readonly name: Name;
|
|
101
|
+
readonly definitions: readonly TaintAnalysisDefinition[];
|
|
102
|
+
readonly reductions: readonly ProductReduction<TaintProduct>[];
|
|
103
|
+
msg: ReportTemplate | undefined;
|
|
104
|
+
constructor(name: Name, definitions: readonly TaintAnalysisDefinition[], options?: ComposeOptions);
|
|
105
|
+
report(msg: ReportTemplate): this;
|
|
106
|
+
createVisitor({ fnCallHook: _hook, ...config }: TaintVisitorConfiguration, _fnCategories?: TaintFnCategory[]): TaintInterpreter;
|
|
107
|
+
resultState(interpreter: TaintInterpreter): StateAbstractDomain<AnyAbstractDomain>;
|
|
108
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CompositeTaintAnalysisDefinition = exports.TaintAnalysisDefinition = void 0;
|
|
4
|
+
const taint_visitor_1 = require("../taint-visitor");
|
|
5
|
+
const assert_1 = require("../../util/assert");
|
|
6
|
+
const state_abstract_domain_1 = require("../../abstract-interpretation/domains/state-abstract-domain");
|
|
7
|
+
const function_categories_1 = require("../function-categories");
|
|
8
|
+
const taint_mapping_1 = require("../taint-mapping");
|
|
9
|
+
/**
|
|
10
|
+
* Fluent builder class for defining new taint analyses.
|
|
11
|
+
* Use {@link TaintAnalysisDefinition.create} to obtain an instance;
|
|
12
|
+
* The methods {@link TaintAnalysis.from}, {@link TaintAnalysis.through},
|
|
13
|
+
* {@link TaintAnalysis.to}, and {@link TaintAnalysis.report} have to be called in order.
|
|
14
|
+
*/
|
|
15
|
+
class TaintAnalysisDefinition {
|
|
16
|
+
domain;
|
|
17
|
+
mapper;
|
|
18
|
+
categories = [];
|
|
19
|
+
name;
|
|
20
|
+
config;
|
|
21
|
+
_msg;
|
|
22
|
+
get msg() {
|
|
23
|
+
return this._msg;
|
|
24
|
+
}
|
|
25
|
+
constructor(name, domain, config) {
|
|
26
|
+
this.name = name;
|
|
27
|
+
this.domain = domain;
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.mapper = new taint_mapping_1.TaintMapper();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a new taint analysis builder. {@link run} is unreachable on the result until at least
|
|
33
|
+
* one of {@link add}, {@link addComposite}, or {@link addPredefined} has been called on it.
|
|
34
|
+
*/
|
|
35
|
+
static create(name, domain, config) {
|
|
36
|
+
return new TaintAnalysisDefinition(name, domain, config);
|
|
37
|
+
}
|
|
38
|
+
on(category, handler) {
|
|
39
|
+
(0, assert_1.guard)(handler || category.handler, 'No handler set for given function category');
|
|
40
|
+
this.categories.push({ ...category, handler: handler ?? category.handler });
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
from(...fnMapping) {
|
|
44
|
+
this.mapper.pushMapping(fnMapping.map(m => ({ ...m, role: taint_mapping_1.TaintRole.Source })));
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
through(...fnMapping) {
|
|
48
|
+
this.mapper.pushMapping(fnMapping.map(m => ({ ...m, role: taint_mapping_1.TaintRole.Transformer })));
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
to(...fnMapping) {
|
|
52
|
+
this.mapper.pushMapping(fnMapping.map(m => ({ ...m, role: taint_mapping_1.TaintRole.Sink })));
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
report(msg) {
|
|
56
|
+
this._msg = msg;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
createVisitor(config, fnCategories = []) {
|
|
60
|
+
const completeMapper = this.mapper.clone();
|
|
61
|
+
// Add mappings from function categories.
|
|
62
|
+
// Categories added to the individual analysis take precedence over passed categories.
|
|
63
|
+
const finalFnCategories = [...this.categories, ...fnCategories];
|
|
64
|
+
for (const category of finalFnCategories) {
|
|
65
|
+
const resolved = (0, function_categories_1.resolveCategoryToTaintMappings)(category);
|
|
66
|
+
completeMapper.pushMappingIfNotExists(resolved);
|
|
67
|
+
}
|
|
68
|
+
return new taint_visitor_1.TaintInterpreter([{ name: this.name, domain: this.domain, mapper: completeMapper }], { ...this.config, ...config });
|
|
69
|
+
}
|
|
70
|
+
/** The end state of this single analysis, holding its own taint lattice values rather than a product of them. */
|
|
71
|
+
resultState(interpreter) {
|
|
72
|
+
const end = interpreter.getEndState();
|
|
73
|
+
return end.isBottom()
|
|
74
|
+
? state_abstract_domain_1.StateAbstractDomain.bottom(this.domain, false)
|
|
75
|
+
: new state_abstract_domain_1.StateAbstractDomain(new Map(end.entries(this.name)), this.domain, false);
|
|
76
|
+
}
|
|
77
|
+
getPartialDefinition() {
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Composes at least two taint analysis definitions into a single composite taint analysis.
|
|
82
|
+
* The component analyses are evaluated simultaneously during a single control-flow traversal and their taints are
|
|
83
|
+
* combined into a product of the lattice values per each CFG node (see {@link TaintInterpreter}).
|
|
84
|
+
* @param name - The unique name of the resulting composite taint analysis
|
|
85
|
+
* @param definitions - The component taint analysis definitions to compose (must have unique names)
|
|
86
|
+
* @param options - Optional reductions (for a reduced product) and a report message
|
|
87
|
+
*/
|
|
88
|
+
static compose(name, definitions, options) {
|
|
89
|
+
return new CompositeTaintAnalysisDefinition(name, definitions, options);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.TaintAnalysisDefinition = TaintAnalysisDefinition;
|
|
93
|
+
/**
|
|
94
|
+
* A composite taint analysis definition combining multiple {@link TaintAnalysisDefinition|component analyses} into a
|
|
95
|
+
* product (or reduced product) taint analysis. Create instances via {@link TaintAnalysisDefinition.compose}.
|
|
96
|
+
*/
|
|
97
|
+
class CompositeTaintAnalysisDefinition {
|
|
98
|
+
name;
|
|
99
|
+
definitions;
|
|
100
|
+
reductions;
|
|
101
|
+
msg;
|
|
102
|
+
constructor(name, definitions, options) {
|
|
103
|
+
(0, assert_1.guard)(definitions.length >= 2, 'A composite taint analysis must combine at least two taint analysis definitions');
|
|
104
|
+
const names = definitions.map(def => def.name);
|
|
105
|
+
(0, assert_1.guard)(new Set(names).size === names.length, 'A composite taint analysis requires unique component analysis names');
|
|
106
|
+
this.name = name;
|
|
107
|
+
this.definitions = definitions;
|
|
108
|
+
this.reductions = options?.reductions ?? [];
|
|
109
|
+
this.msg = options?.report;
|
|
110
|
+
}
|
|
111
|
+
report(msg) {
|
|
112
|
+
this.msg = msg;
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
createVisitor({ fnCallHook: _hook, ...config }, _fnCategories) {
|
|
116
|
+
const components = this.definitions.map(def => ({
|
|
117
|
+
name: def.name,
|
|
118
|
+
domain: def.domain,
|
|
119
|
+
mapper: def.mapper,
|
|
120
|
+
}));
|
|
121
|
+
return new taint_visitor_1.TaintInterpreter(components, config, this.reductions);
|
|
122
|
+
}
|
|
123
|
+
resultState(interpreter) {
|
|
124
|
+
return interpreter.getEndState();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.CompositeTaintAnalysisDefinition = CompositeTaintAnalysisDefinition;
|
|
128
|
+
//# sourceMappingURL=taint-analysis-definition.js.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
|
|
2
|
+
import type { CompositeTaintAnalysisDefinition, TaintAnalysisDefinition } from './taint-analysis-definition';
|
|
3
|
+
import type { AnyPredefinedTaintAnalysisName } from '../predefined/predefined';
|
|
4
|
+
import type { StateAbstractDomain } from '../../abstract-interpretation/domains/state-abstract-domain';
|
|
5
|
+
import type { AnyAbstractDomain } from '../../abstract-interpretation/domains/abstract-domain';
|
|
6
|
+
import type { ArgTaintProjector, TaintCallNode } from '../taint-visitor';
|
|
7
|
+
import type { DataflowGraph } from '../../dataflow/graph/graph';
|
|
8
|
+
import type { DataflowGraphVertexFunctionCall } from '../../dataflow/graph/vertex';
|
|
9
|
+
import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
|
|
10
|
+
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
11
|
+
import { SourceLocation } from '../../util/range';
|
|
12
|
+
import type { TaintConditionFunction, TaintRole } from '../taint-mapping';
|
|
13
|
+
import type { TaintFnCategory } from '../function-categories';
|
|
14
|
+
/**
|
|
15
|
+
* Information passed to a {@link FnCallHook} for each function call visited during taint analysis.
|
|
16
|
+
*/
|
|
17
|
+
export interface FnCallHookInfo {
|
|
18
|
+
/** The name of the taint analysis */
|
|
19
|
+
name: string;
|
|
20
|
+
/** The role of the matched mapping (source/propagator/sink), or `undefined` for unmapped calls */
|
|
21
|
+
role: TaintRole | undefined;
|
|
22
|
+
/** Name of the {@link TaintFnCategory} the matched mapping stems from, or `undefined` if it was defined manually */
|
|
23
|
+
category?: string;
|
|
24
|
+
/** The AST node representing the function call */
|
|
25
|
+
node: TaintCallNode;
|
|
26
|
+
/** Whether the function call had an explicit mapping */
|
|
27
|
+
wasMapped: boolean;
|
|
28
|
+
/** The abstract domain value at this point (the outgoing/resolved taint) */
|
|
29
|
+
value: AnyAbstractDomain;
|
|
30
|
+
/** Resolves the incoming taint of any argument node at this call, regardless of mapping rules */
|
|
31
|
+
projectArg: ArgTaintProjector;
|
|
32
|
+
/** The data flow graph vertex of the function call */
|
|
33
|
+
call: DataflowGraphVertexFunctionCall;
|
|
34
|
+
/** The data flow graph (e.g. for resolving the call's arguments) */
|
|
35
|
+
dfg: DataflowGraph;
|
|
36
|
+
/** The analysis context (e.g. for resolving argument values) */
|
|
37
|
+
ctx: ReadOnlyFlowrAnalyzerContext;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Callback hook invoked when a function call is visited during taint analysis.
|
|
41
|
+
*/
|
|
42
|
+
export type FnCallHook = (info: FnCallHookInfo) => void;
|
|
43
|
+
/**
|
|
44
|
+
* A single finding produced by a taint analysis, i.e. an AST node whose inferred taint reached Bottom (e.g. a sink call).
|
|
45
|
+
*/
|
|
46
|
+
export interface TaintFinding {
|
|
47
|
+
/** The AST node ID that reached Bottom */
|
|
48
|
+
nodeId: NodeId;
|
|
49
|
+
/** The source location of the AST node, if it could be resolved */
|
|
50
|
+
loc?: SourceLocation;
|
|
51
|
+
/** The rendered report message for this finding, set only when the analysis uses a per-finding {@link ReportTemplate} */
|
|
52
|
+
msg?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Result of running a taint analysis, containing the final abstract domain state and any findings.
|
|
56
|
+
*/
|
|
57
|
+
export interface TaintInferenceResult {
|
|
58
|
+
/** The final abstract domain state after running the taint analysis visitor */
|
|
59
|
+
domains: StateAbstractDomain<AnyAbstractDomain>;
|
|
60
|
+
/** The message describing the findings */
|
|
61
|
+
msg?: string;
|
|
62
|
+
/** The findings produced by the analysis, i.e. one per AST node whose inferred taint reached Bottom */
|
|
63
|
+
findings: TaintFinding[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Builder stage of a taint analysis, before any analysis definition has been added.
|
|
67
|
+
* {@link RunnableTaintAnalysis.run} only becomes available once
|
|
68
|
+
* {@link add}, {@link addComposite}, or {@link addPredefined} has been called.
|
|
69
|
+
*/
|
|
70
|
+
export interface TaintAnalysisBuilder<Defs extends readonly string[]> {
|
|
71
|
+
/**
|
|
72
|
+
* Add rules for function categories (i.e. sets of functions from {@link BuiltInIndex} fulfilling certain properties).
|
|
73
|
+
* These rules are applied to all added analyses.
|
|
74
|
+
*/
|
|
75
|
+
on(category: TaintFnCategory, handler?: TaintConditionFunction<AnyAbstractDomain>): this;
|
|
76
|
+
/**
|
|
77
|
+
* Add a callback hook that is invoked for each function call mapping during taint analysis.
|
|
78
|
+
*/
|
|
79
|
+
withHook(fnCallHook: FnCallHook): this;
|
|
80
|
+
/**
|
|
81
|
+
* Add a predefined taint analysis by name.
|
|
82
|
+
*/
|
|
83
|
+
addPredefined<Name extends AnyPredefinedTaintAnalysisName>(...names: Name[]): RunnableTaintAnalysis<readonly [...Defs, Name]>;
|
|
84
|
+
/**
|
|
85
|
+
* Add a custom taint analysis definition.
|
|
86
|
+
*/
|
|
87
|
+
add<Name extends string>(...defs: TaintAnalysisDefinition<Name>[]): RunnableTaintAnalysis<readonly [...Defs, Name]>;
|
|
88
|
+
/**
|
|
89
|
+
* Add a composite taint analysis that combines multiple taint analyses into a product of their lattice values.
|
|
90
|
+
* @see {@link TaintAnalysisDefinition.compose} to create a composite taint analysis definition.
|
|
91
|
+
*/
|
|
92
|
+
addComposite<Name extends string>(...defs: CompositeTaintAnalysisDefinition<Name>[]): RunnableTaintAnalysis<readonly [...Defs, Name]>;
|
|
93
|
+
}
|
|
94
|
+
export interface RunnableTaintAnalysis<Defs extends readonly string[]> extends TaintAnalysisBuilder<Defs> {
|
|
95
|
+
run(analyzer?: ReadonlyFlowrAnalysisProvider): Promise<Map<Defs[number], TaintInferenceResult>>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Fluent builder class for conducting taint analyses.
|
|
99
|
+
* Please prefer using the {@link FlowrAnalyzer.taint} method to create a taint analysis.
|
|
100
|
+
* Use {@link TaintAnalysis.create} to obtain an instance; {@link TaintAnalysis.run} is only reachable
|
|
101
|
+
* after at least one of {@link add}, {@link addComposite}, or {@link addPredefined} has been called.
|
|
102
|
+
*/
|
|
103
|
+
export declare class TaintAnalysis<Defs extends readonly string[] = []> implements RunnableTaintAnalysis<Defs> {
|
|
104
|
+
private readonly analyzer?;
|
|
105
|
+
private readonly defs;
|
|
106
|
+
private readonly categories;
|
|
107
|
+
private fnCallHook;
|
|
108
|
+
private constructor();
|
|
109
|
+
/**
|
|
110
|
+
* Create a new taint analysis builder. {@link run} is unreachable on the result until at least
|
|
111
|
+
* one of {@link add}, {@link addComposite}, or {@link addPredefined} has been called on it.
|
|
112
|
+
*/
|
|
113
|
+
static create<Defs extends readonly string[] = []>(analyzer?: ReadonlyFlowrAnalysisProvider): TaintAnalysisBuilder<Defs>;
|
|
114
|
+
on(category: TaintFnCategory, handler?: TaintConditionFunction<AnyAbstractDomain>): this;
|
|
115
|
+
withHook(fnCallHook: FnCallHook): this;
|
|
116
|
+
addPredefined<Name extends AnyPredefinedTaintAnalysisName>(...names: Name[]): RunnableTaintAnalysis<readonly [...Defs, Name]>;
|
|
117
|
+
add<Name extends string>(...defs: TaintAnalysisDefinition<Name>[]): RunnableTaintAnalysis<readonly [...Defs, Name]>;
|
|
118
|
+
addComposite<Name extends string>(...defs: CompositeTaintAnalysisDefinition<Name>[]): RunnableTaintAnalysis<readonly [...Defs, Name]>;
|
|
119
|
+
/**
|
|
120
|
+
* Run one or multiple taint analyses.
|
|
121
|
+
*/
|
|
122
|
+
run(analyzer?: ReadonlyFlowrAnalysisProvider | undefined): Promise<Map<Defs[number], TaintInferenceResult>>;
|
|
123
|
+
private wrapFnCallHook;
|
|
124
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaintAnalysis = void 0;
|
|
4
|
+
const predefined_1 = require("../predefined/predefined");
|
|
5
|
+
const range_1 = require("../../util/range");
|
|
6
|
+
const assert_1 = require("../../util/assert");
|
|
7
|
+
const report_template_1 = require("./report-template");
|
|
8
|
+
/**
|
|
9
|
+
* Fluent builder class for conducting taint analyses.
|
|
10
|
+
* Please prefer using the {@link FlowrAnalyzer.taint} method to create a taint analysis.
|
|
11
|
+
* Use {@link TaintAnalysis.create} to obtain an instance; {@link TaintAnalysis.run} is only reachable
|
|
12
|
+
* after at least one of {@link add}, {@link addComposite}, or {@link addPredefined} has been called.
|
|
13
|
+
*/
|
|
14
|
+
class TaintAnalysis {
|
|
15
|
+
analyzer;
|
|
16
|
+
defs = [];
|
|
17
|
+
categories = [];
|
|
18
|
+
fnCallHook;
|
|
19
|
+
constructor(analyzer) {
|
|
20
|
+
this.analyzer = analyzer;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a new taint analysis builder. {@link run} is unreachable on the result until at least
|
|
24
|
+
* one of {@link add}, {@link addComposite}, or {@link addPredefined} has been called on it.
|
|
25
|
+
*/
|
|
26
|
+
static create(analyzer) {
|
|
27
|
+
return new TaintAnalysis(analyzer);
|
|
28
|
+
}
|
|
29
|
+
on(category, handler) {
|
|
30
|
+
(0, assert_1.guard)(handler || category.handler, 'No handler set for given function category');
|
|
31
|
+
this.categories.push({ ...category, handler: handler ?? category.handler });
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
withHook(fnCallHook) {
|
|
35
|
+
this.fnCallHook = fnCallHook;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
addPredefined(...names) {
|
|
39
|
+
for (const name of names) {
|
|
40
|
+
this.defs.push(predefined_1.predefinedTaintAnalyses[name]);
|
|
41
|
+
}
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
add(...defs) {
|
|
45
|
+
this.defs.push(...defs);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
addComposite(...defs) {
|
|
49
|
+
this.defs.push(...defs);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Run one or multiple taint analyses.
|
|
54
|
+
*/
|
|
55
|
+
async run(analyzer = this.analyzer) {
|
|
56
|
+
(0, assert_1.guard)((0, assert_1.isNotUndefined)(analyzer), 'No analyzer has been set');
|
|
57
|
+
const results = new Map();
|
|
58
|
+
const dfg = (await analyzer.dataflow()).graph;
|
|
59
|
+
const ctx = analyzer.inspectContext();
|
|
60
|
+
for (const def of this.defs) {
|
|
61
|
+
const baseConfig = {
|
|
62
|
+
controlFlow: await analyzer.controlflow(),
|
|
63
|
+
ctx: ctx,
|
|
64
|
+
dfg: dfg,
|
|
65
|
+
normalizedAst: await analyzer.normalize(),
|
|
66
|
+
fnCallHook: this.wrapFnCallHook(this.fnCallHook, def.name, dfg, ctx),
|
|
67
|
+
};
|
|
68
|
+
const interpreter = def.createVisitor(baseConfig, this.categories);
|
|
69
|
+
interpreter.start();
|
|
70
|
+
const endState = def.resultState(interpreter);
|
|
71
|
+
const report = def.msg;
|
|
72
|
+
const idMap = baseConfig.normalizedAst.idMap;
|
|
73
|
+
const findings = report === undefined ? [] : endState.getBottomNodes().map(nodeId => {
|
|
74
|
+
const node = idMap.get(nodeId);
|
|
75
|
+
const loc = range_1.SourceLocation.fromNode(node);
|
|
76
|
+
return typeof report === 'function'
|
|
77
|
+
? { nodeId, loc, msg: (0, report_template_1.renderReport)(report, (0, report_template_1.buildFindingContext)(def.name, nodeId, node, loc)) }
|
|
78
|
+
: { nodeId, loc };
|
|
79
|
+
});
|
|
80
|
+
// If the report message is a constant string, save it only once
|
|
81
|
+
const msg = typeof report === 'string' ? report : undefined;
|
|
82
|
+
results.set(def.name, { domains: endState, msg, findings });
|
|
83
|
+
}
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
wrapFnCallHook(fn, name, dfg, ctx) {
|
|
87
|
+
return fn
|
|
88
|
+
? ({ node, value, wasMapped, projectArg, call, role, category }) => fn({ name, node, value, wasMapped, projectArg, call, dfg, ctx, role, category })
|
|
89
|
+
: () => { };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.TaintAnalysis = TaintAnalysis;
|
|
93
|
+
//# sourceMappingURL=taint-analysis.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AnyAbstractDomain } from '../abstract-interpretation/domains/abstract-domain';
|
|
2
|
+
import type { ArgProp, PropSelector } from '../dataflow/environments/built-in-props';
|
|
3
|
+
import type { TaintConditionFunction, TaintConditionMapping } from './taint-mapping';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a taint mapping rule for each function that matches the given {@link PropSelector} and whose signature
|
|
6
|
+
* has at least one parameter fulfilling {@link ArgProp}.
|
|
7
|
+
* @param props - The properties the function has to fulfill
|
|
8
|
+
* @param argProps - The properties at least one argument has to fulfill
|
|
9
|
+
* @param conditionFn - The taint condition function to apply to matching function calls
|
|
10
|
+
*/
|
|
11
|
+
export declare function taintMappingFromBuiltInIndex<Domain extends AnyAbstractDomain>(props: PropSelector, argProps: ArgProp, conditionFn: TaintConditionFunction<Domain>): TaintConditionMapping<Domain>[];
|
|
12
|
+
/**
|
|
13
|
+
* Like {@link taintMappingFromBuiltInIndex}, but resolves the {@link ArgProp} parameters as arguments for the {@link conditionFn}.
|
|
14
|
+
* I.e. their position and name are read from each function's signature instead of being hard-coded.
|
|
15
|
+
* @param props - The properties the function has to fulfill (all of them)
|
|
16
|
+
* @param argProps - The properties at least one argument has to fulfill
|
|
17
|
+
* @param conditionFn - The taint condition function to apply to matching function calls
|
|
18
|
+
* @param excluding - Drop functions that also carry any of these properties
|
|
19
|
+
*/
|
|
20
|
+
export declare function argValueMappingFromBuiltInIndex<Domain extends AnyAbstractDomain>(props: PropSelector, argProps: ArgProp, conditionFn: TaintConditionFunction<Domain>, excluding?: PropSelector): TaintConditionMapping<Domain>[];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.taintMappingFromBuiltInIndex = taintMappingFromBuiltInIndex;
|
|
4
|
+
exports.argValueMappingFromBuiltInIndex = argValueMappingFromBuiltInIndex;
|
|
5
|
+
const query_fn_props_1 = require("../dataflow/environments/query-fn-props");
|
|
6
|
+
const assert_1 = require("../util/assert");
|
|
7
|
+
/**
|
|
8
|
+
* Creates a taint mapping rule for each function that matches the given {@link PropSelector} and whose signature
|
|
9
|
+
* has at least one parameter fulfilling {@link ArgProp}.
|
|
10
|
+
* @param props - The properties the function has to fulfill
|
|
11
|
+
* @param argProps - The properties at least one argument has to fulfill
|
|
12
|
+
* @param conditionFn - The taint condition function to apply to matching function calls
|
|
13
|
+
*/
|
|
14
|
+
function taintMappingFromBuiltInIndex(props, argProps, conditionFn) {
|
|
15
|
+
const identifiers = query_fn_props_1.BuiltInIndex.default().with(props);
|
|
16
|
+
const mappings = identifiers.map(i => {
|
|
17
|
+
const sig = query_fn_props_1.BuiltInIndex.default().get(i)?.sig;
|
|
18
|
+
if (!sig || !sig.some(([, p]) => (p & argProps) !== 0)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
identifier: i,
|
|
23
|
+
condition: {
|
|
24
|
+
argSignature: { sig, props: argProps },
|
|
25
|
+
conditionFn
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
return mappings.filter(assert_1.isNotUndefined);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Like {@link taintMappingFromBuiltInIndex}, but resolves the {@link ArgProp} parameters as arguments for the {@link conditionFn}.
|
|
33
|
+
* I.e. their position and name are read from each function's signature instead of being hard-coded.
|
|
34
|
+
* @param props - The properties the function has to fulfill (all of them)
|
|
35
|
+
* @param argProps - The properties at least one argument has to fulfill
|
|
36
|
+
* @param conditionFn - The taint condition function to apply to matching function calls
|
|
37
|
+
* @param excluding - Drop functions that also carry any of these properties
|
|
38
|
+
*/
|
|
39
|
+
function argValueMappingFromBuiltInIndex(props, argProps, conditionFn, excluding) {
|
|
40
|
+
const index = query_fn_props_1.BuiltInIndex.default();
|
|
41
|
+
return index.withAll(props, excluding).flatMap(identifier => {
|
|
42
|
+
const argValues = index.get(identifier)?.sig
|
|
43
|
+
?.map(([name, p], pos) => (p & argProps) !== 0 ? { pos, name } : undefined)
|
|
44
|
+
.filter(assert_1.isNotUndefined);
|
|
45
|
+
return argValues?.length ? [{ identifier, condition: { argValues, conditionFn } }] : [];
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=builtin-index-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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
|
+
/**
|
|
7
|
+
* Evaluation script for flowR's taint analysis.
|
|
8
|
+
*
|
|
9
|
+
* It uses the {@link FlowrAnalyzer} API and collects the function-call
|
|
10
|
+
* mappings through the {@link TaintAnalysisInstrumentation} hook (`analyzer.taint().withHook(...)`).
|
|
11
|
+
*
|
|
12
|
+
* For every `.R` file found (recursively) below the given dataset directory it runs the
|
|
13
|
+
* configured taint analyses and writes one JSON line with the collected trace to stdout
|
|
14
|
+
* (progress is always logged to stderr).
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* ts-node src/taint-analysis/eval/eval.ts <dataset-dir>
|
|
18
|
+
*/
|
|
19
|
+
const fs_1 = __importDefault(require("fs"));
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const flowr_analyzer_builder_1 = require("../../project/flowr-analyzer-builder");
|
|
22
|
+
const retriever_1 = require("../../r-bridge/retriever");
|
|
23
|
+
const instrumentation_1 = require("./instrumentation");
|
|
24
|
+
const predefined_1 = require("../predefined/predefined");
|
|
25
|
+
const log_1 = require("../../util/log");
|
|
26
|
+
const lattice_1 = require("../../abstract-interpretation/domains/lattice");
|
|
27
|
+
/** Recursively yield all relevant `.R` files below `dir`. */
|
|
28
|
+
function* findRFiles(dir) {
|
|
29
|
+
for (const entry of fs_1.default.readdirSync(dir, { withFileTypes: true })) {
|
|
30
|
+
const fullPath = path_1.default.join(dir, entry.name);
|
|
31
|
+
if (entry.isDirectory()) {
|
|
32
|
+
yield* findRFiles(fullPath);
|
|
33
|
+
}
|
|
34
|
+
else if (entry.isFile() && entry.name.endsWith('.R')) {
|
|
35
|
+
yield fullPath;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Collect all scripts below the dataset root, deriving source/id/script name from the path. */
|
|
40
|
+
function collectScripts(root) {
|
|
41
|
+
const paths = fs_1.default.statSync(root).isDirectory() ? findRFiles(root) : [root];
|
|
42
|
+
return Array.from(paths, file => {
|
|
43
|
+
const parts = file === root ? [path_1.default.basename(file)] : path_1.default.relative(root, file).split(path_1.default.sep);
|
|
44
|
+
return {
|
|
45
|
+
scriptName: parts.length >= 3 ? parts.slice(2).join('/') : parts[parts.length - 1],
|
|
46
|
+
path: file,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** Convert the instrumentation's nested `Map` trace into a plain, JSON-serializable object. */
|
|
51
|
+
function traceToObject(trace) {
|
|
52
|
+
const result = {};
|
|
53
|
+
for (const [analysis, byFile] of trace) {
|
|
54
|
+
const files = {};
|
|
55
|
+
for (const [file, info] of byFile) {
|
|
56
|
+
files[file ?? '<unknown>'] = info;
|
|
57
|
+
}
|
|
58
|
+
result[analysis] = files;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
function taintResultsToObject(results) {
|
|
63
|
+
return Object.fromEntries(results.entries().map(([name, { domains, msg, findings }]) => [name, {
|
|
64
|
+
domains: domains.value === lattice_1.Bottom ? domains.value.description : Object.fromEntries(domains.value.entries().map(([key, domain]) => [key, domain?.toJSON() ?? null])),
|
|
65
|
+
msg,
|
|
66
|
+
findings,
|
|
67
|
+
}]));
|
|
68
|
+
}
|
|
69
|
+
/** Run all configured taint analyses on a single script and return the JSON line to write. */
|
|
70
|
+
async function analyzeScript(run, analyzer) {
|
|
71
|
+
console.error(`Analyzing script ${run.scriptName}`);
|
|
72
|
+
const instrumentation = new instrumentation_1.TaintAnalysisInstrumentation();
|
|
73
|
+
const start = Date.now();
|
|
74
|
+
let result;
|
|
75
|
+
try {
|
|
76
|
+
// drop the previous file's requests and cached results, reusing the analyzer's parser
|
|
77
|
+
analyzer.reset();
|
|
78
|
+
analyzer.addRequest(`${retriever_1.fileProtocol}${run.path}`);
|
|
79
|
+
const analysis = analyzer
|
|
80
|
+
.taint()
|
|
81
|
+
.addPredefined(...predefined_1.allPredefinedTaintAnalysisNames)
|
|
82
|
+
.withHook(instrumentation.fnCallHook);
|
|
83
|
+
result = await analysis.run();
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
console.error(`Taint inference for script ${run.scriptName} failed: ${e.message}`);
|
|
87
|
+
return JSON.stringify({ script_name: run.scriptName, infer_failed: true }) + '\n';
|
|
88
|
+
}
|
|
89
|
+
console.error(`Finished taint inference for script ${run.scriptName}`);
|
|
90
|
+
return JSON.stringify({
|
|
91
|
+
script_name: run.scriptName,
|
|
92
|
+
infer_time: Date.now() - start,
|
|
93
|
+
inferred: traceToObject(instrumentation.trace),
|
|
94
|
+
result: taintResultsToObject(result),
|
|
95
|
+
}) + '\n';
|
|
96
|
+
}
|
|
97
|
+
async function main() {
|
|
98
|
+
const datasetArg = process.argv[2];
|
|
99
|
+
if (!datasetArg) {
|
|
100
|
+
console.error('Usage: eval <dataset-dir>');
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
const datasetPath = path_1.default.resolve(datasetArg);
|
|
104
|
+
if (!fs_1.default.existsSync(datasetPath)) {
|
|
105
|
+
console.error(`Dataset directory or file '${datasetPath}' does not exist`);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
log_1.log.updateSettings(l => l.settings.minLevel = 6 /* LogLevel.Fatal */);
|
|
109
|
+
const analyzer = await new flowr_analyzer_builder_1.FlowrAnalyzerBuilder()
|
|
110
|
+
.setEngine('tree-sitter')
|
|
111
|
+
.build();
|
|
112
|
+
const scripts = collectScripts(datasetPath);
|
|
113
|
+
console.error(`Found ${scripts.length} R script(s) in ${datasetPath}; writing results to stdout`);
|
|
114
|
+
try {
|
|
115
|
+
for (const script of scripts) {
|
|
116
|
+
process.stdout.write(await analyzeScript(script, analyzer));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
analyzer.close();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
void main();
|
|
124
|
+
//# sourceMappingURL=eval.js.map
|