Introduction
Automated Program Repair (APR) has traditionally been limited by the scarcity of high-quality training data. While static analysis (SA) tools are proficient at identifying vulnerabilities, they have rarely been utilized to generate repairs. StaticFixer introduces a novel framework that repurposes static analysis to automatically repair security vulnerabilities by "witnessing" safety properties in existing code and utilizing a graph-based domain-specific language (DSL) to implement non-local fixes.
The Challenge of Non-Local Security Vulnerabilities
Security flaws such as Cross-Site Scripting (XSS) and Unvalidated Dynamic Calls (UDC) are inherently non-local. Unlike simple syntax errors, these vulnerabilities depend on the flow of untrusted data from a source (e.g., a request parameter) to a sensitive sink (e.g., a database or response). Fixing these requires identifying the correct point in the dataflow to insert a sanitizer or guard, which may be many lines away from the actual source or sink.
Existing APR tools often struggle with this distance, as they treat code as a linear sequence of text. General-purpose models like Codex frequently fail to maintain semantic precision, such as checking the wrong variable or placing a guard in an ineffective scope.
Methodology
StaticFixer addresses these challenges through two primary innovations: Static-Analysis Witnessing and a Graph-Based DSL.
Static-Analysis Witnessing
To overcome the "data hunger" of machine learning models, StaticFixer inverts the traditional use of static analysis. Instead of searching for bugs, it analyzes safe code to find "witnesses" of safety—specific sanitizers or guards that satisfy security properties. By programmatically removing these witnesses, the system generates synthetic, perfectly aligned pairs of vulnerable and safe code. This automated pipeline provides a high-volume, high-quality dataset for training repair strategies.
Graph-Based Domain-Specific Language (DSL)
Rather than treating code as text, StaticFixer represents programs as graphs combining Abstract Syntax Trees (AST) and dataflow edges. The system uses a specialized DSL to describe repair strategies as traversals over this graph.
As shown in the figure above, the DSL allows the system to navigate from a variable declaration to its usage in a function call across different branches of the AST. This semantic approach ensures that repairs are structurally sound and tied to the actual information flow of the vulnerability.
Experimental Results
StaticFixer was evaluated against real-world JavaScript vulnerabilities scraped from GitHub. It significantly outperformed state-of-the-art models:
- UDC Vulnerabilities: StaticFixer achieved a 93.94% success rate, compared to 66.67% for OpenAI’s Codex.
- XSS Vulnerabilities: StaticFixer reached a 91.82% success rate, while Codex trailed significantly at 32.59%.
- Precision: The system typically produces only a few candidate fixes per bug, with a high ratio of correct candidates (averaging 3 out of 4), reducing the manual verification burden for developers.
Conclusion
StaticFixer demonstrates that the "knowledge" embedded in static analysis tools can be effectively inverted to drive automated repair. By moving from syntactic text-based models to semantic graph-based strategies, the system achieves high precision in fixing complex, non-local security bugs. Future work aims to extend this analysis across multiple files and integrate Large Language Models to improve the naturalness of the generated error-handling logic.
Summary updated