How htrgouvea/zarn works
Main Components
• Main Entry Point: The CLI script (zarn.pl) that initiates the analysis process.
• Engine Subsystem: The core analysis logic encapsulated in the lib/Zarn/Engine directory. This includes:
• AST Module (AST.pm): Responsible for parsing source Perl files into AST representations.
• Source-to-Sink (Source_to_Sink.pm): Likely helps with mapping data flow from origins to endpoints.
• Taint Analysis (Taint_Analysis.pm): Implements taint tracking to assess if the recognized tokens in the AST may be exploitable.
• Helper Utilities: Found under lib/Zarn/Helper, which include:
• Files Utility (Files.pm): For file manipulations and reading source code.
• Rules Utility (Rules.pm): Loads and manages security rules.
• Sarif Utility (Sarif.pm): Converts the analysis results into SARIF format for integration with tools like GitHub CodeQL.
• Rules Repository: The YAML files in the “rules” directory (e.g., default.yml, prototype.yml) that define the various security rules.
• Testing Suite: The tests directory with .t files provides the test cases ensuring component functionality and integration.
• CI/CD Integration: The GitHub Actions workflows (in .github/workflows) that run linting, security scans, and tests on each commit or pull request.
• Build & Deployment: The Makefile, Dockerfile, and cpanfile indicate how the project is built, packaged, and deployed.
Relationships and Data Flow
• The analysis begins when the CLI script (zarn.pl) is invoked with command-line arguments (like source location, rule files, output file for SARIF reports).
• The script delegates work to the Engine components:
• The AST module parses the individual Perl files to build a syntax tree.
• The Taint Analysis module then performs the taint tracking on this AST to detect if data flows from source to sink in a potentially vulnerable way.
• The Source-to-Sink module may be used to figure out the propagation of data through the code.
• The Rules Helper module then loads the security rules from the rules directory and cross-references the AST tokens found during analysis.
• Once analysis is complete, the Sarif Helper module produces an output in SARIF format, which is then consumed either by the CLI output or integrated with GitHub Actions for sending results to GitHub Security Tools.
• The testing components ensure that each of the above functions operate correctly, simulating real-world files and rule processing.
Architectural Patterns and Technologies
• Modular Design: Separation of different responsibilities into discrete modules (Engine, Helper, Rules).
• Layered Architecture: There is a clear separation between the input (CLI), processing (AST, analysis engines), rule evaluation, and output (SARIF report generation).
• Extensibility: The rules are defined in YAML and easily extensible, and the Engine modules encapsulate different analysis strategies (with possible future enhancements like call graph analysis).
• CI/CD and Integration: Built-in GitHub Actions workflows ensure that the static analysis and testing are run automatically, reinforcing a secure development lifecycle.
Additional Notes
• Importance of capturing as many architectural elements as possible, separating the system into distinct components based on functionality.
• Annotations and clear labels should ensure that even someone unfamiliar with dynamic languages like Perl will understand the phases of static analysis (i.e., parsing, analysis, rule evaluation, reporting).