Introduction
Static Application Security Testing (SAST) tools are essential for identifying vulnerabilities in modern software. However, their effectiveness in dynamically typed languages like JavaScript and Python is often hampered by a lack of explicit type information. Without knowing the type of a variable, dataflow analysis—the process of tracking untrusted input through a program—becomes a "guessing game." If a tool cannot determine that a variable represents a database client or a specific API request object, it may fail to identify critical security flaws.
In the paper "Learning Type Inference for Enhanced Dataflow Analysis," researchers from QwietAI, Stellenbosch University, and TU Berlin present CodeTIDAL5 and JoernTI. This system leverages Large Language Models (LLMs) to predict variable types and integrates these predictions directly into professional security workflows, significantly enhancing the precision of vulnerability detection.
The Type Inference Problem
Traditional SAST tools rely on dataflow analysis to map the path from a "source" (user input) to a "sink" (a sensitive function like a database query). In dynamic languages, the absence of type annotations often causes these tools to lose the dataflow trail. For instance, if a tool doesn't recognize that req is an Express.Request object, it won't know that req.body contains potentially malicious data.
While Machine Learning (ML) has been proposed for type inference before, existing solutions face three primary hurdles:
- User-Defined Types: Most models struggle with custom classes and types specific to a single project.
- Operational Complexity: Academic prototypes are often difficult to deploy in standard development environments.
- Tool Integration: There is a significant gap between ML model outputs and the actual tools used by security researchers.
Methodology: CodeTIDAL5 and JoernTI
The researchers addressed these challenges with a two-part system designed for both accuracy and practical utility.
CodeTIDAL5: The Inference Engine
CodeTIDAL5 is a Transformer-based model built on the CodeT5+ architecture. Unlike previous models that treat code as a linear sequence of tokens, CodeTIDAL5 utilizes usage slicing. This technique extracts a specific "slice" of code that demonstrates how a variable is used—such as the methods it calls or the functions it is passed into—providing the model with high-density context.
Because it uses an encoder-decoder (generative) approach, CodeTIDAL5 is not limited to a predefined list of types. It can generate type names dynamically, allowing it to predict user-defined types it has never encountered during training.
JoernTI: The Integration Bridge
To make these predictions actionable, the authors developed JoernTI, an integration for the open-source code analysis platform Joern. JoernTI functions as a server that receives code from Joern, queries CodeTIDAL5 for type suggestions, and re-integrates those types into the program’s Code Property Graph (CPG). This allows the static analysis engine to "see" the types and complete dataflow paths that were previously broken.
Experimental Results
The model was evaluated using the ManyTypes4TypeScript (MT4TS) dataset and the LambdaNet benchmark. The results demonstrate a significant leap in performance:
- State-of-the-Art Accuracy: CodeTIDAL5 achieved 71.27% overall accuracy on the MT4TS benchmark, an improvement of 7.85% over previous best-in-class models.
- Handling Custom Types: On the LambdaNet dataset, the model outperformed existing solutions on user-defined types by 6.31%.
- Efficiency: With only 220 million parameters, the model is efficient enough to run on standard consumer hardware, such as an M1 MacBook, making it accessible for local development.
Real-World Case Study: CWE-943
The practical value of the system was demonstrated through a case study involving a NoSQL injection vulnerability (CWE-943). Standard Joern analysis, lacking type information, failed to find any results. However, with JoernTI enabled, the system correctly inferred the missing types, allowing the tool to successfully map the dataflow from the attacker's request to the vulnerable database query.
Key Insights
- Contextual Windows: Increasing the context window to 512 tokens (from the standard 256) significantly improved prediction accuracy.
- Useful Hallucinations: The researchers noted that even when the generative model "hallucinates" a type name, the result is often semantically useful. For example, predicting a type
Customerfor a variable namedcustomerhelps security researchers identify and tag Personally Identifiable Information (PII). - Hybrid Analysis: The system employs a hybrid approach, using fast, rule-based propagation for simple cases and reserving the LLM for complex, "hard" variables.
Conclusion and Future Work
CodeTIDAL5 and JoernTI represent a significant step forward in bridging the gap between machine learning research and practical security tooling. While currently focused on JavaScript and TypeScript, the underlying logic is language-agnostic. Future work will focus on expanding language support, improving automated type validation using TypeScript declaration files, and developing multi-language models capable of cross-language type inference.
Paper Citation: Seidel, L., Effendi, S. D. B., Pinho, X., Rieck, K., van der Merwe, B., & Yamaguchi, F. (2023). Learning Type Inference for Enhanced Dataflow Analysis. Presented at ESORICS '23. arXiv:2310.00673
Summary updated