[STAL-2792] Add CLI option to export data flow graphs #535
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem are you trying to solve?
We'd like to be able to export the taint analysis graphs for each file as a debugging tool.
What is your solution?
This PR is necessarily large because:
unwrap
, and used internal apis on the JsRuntime that should not be exposed crate-wide.Implementation Highlights
A. v8 -> DOT is now a deno op
Because the canonical DOT representation requires access to internal data structures (e.g. the TsNode and Context bridge in order to get the node text/position), rather than leak the innards of the JsRuntime, the functionality is exposed as a deno op.
B. Hack: use Rule abstractions to pass data
The logic to generate the graph dots is modeled as a Rule, which allows us to use
execute_rule
, avoiding the need to duplicate/re-implement the Rust -> v8 bridging (here and here).This is very much a hack: I pass the DOT strings from the JsRuntime by repurposing Violation/Fix. This allows me to easily associate the DOT graphs for multiple methods to multiples classes. (This is ultimately more simple than trying to pass this data via
console.log
)C.
.dot
files are written adjacent to scanned filesThis will necessarily dirty the git working directory, however it is gated behind an opt-in cli flag. Because this is intended as a debug tool, errors are silently swallowed rather than handled.
Example:
Pre-analysis:
Post-analysis:
D. Generic abstraction
By not coupling to Java or Java's semantics, the DigraphCollection can be used for other languages or use cases--for example, generating interfile Java graphs would only involve adding an extra collection.
Sample output
File:
Output:
Visualized:
Alternatives considered
What the reviewer should know