QLCoder: A Query Synthesizer For Static Analysis of Security Vulnerabilities

Claire Wang, Ziyang Li, Saikat Dutta, Mayur Naik

Static analysis is the "spell-check" of the security world. Tools like CodeQL allow developers to write queries that scan massive codebases for dangerous patterns, like SQL injection or buffer overflows. However, there’s a catch: writing these queries is incredibly difficult. It requires a rare intersection of security expertise, deep knowledge of program analysis, and mastery of a niche, evolving query language.

In their ICLR 2025 paper, researchers from the University of Pennsylvania, Johns Hopkins, and Cornell introduce QLCoder, an agentic framework that turns natural language CVE (Common Vulnerabilities and Exposures) descriptions into precise, executable CodeQL queries.

TL;DR

QLCoder is an AI-powered "query synthesizer" that automatically writes CodeQL scripts to detect specific security vulnerabilities. By embedding a Large Language Model (LLM) in a feedback loop with a real static analysis engine and a specialized toolset, it achieves a 53.4% success rate in detecting real-world vulnerabilities—massively outperforming general-purpose AI coding assistants.

Overview of the QLCoder workflow, translating CVE descriptions and patches into executable CodeQL queries for regression testing, variant analysis, and patch validation.

What Problem Does This Paper Address?

The security industry is drowning in new vulnerabilities; over 40,000 CVEs were reported in 2024 alone. While static analysis tools are powerful, their "query suites" (the library of known bad patterns) often miss specific bugs or produce too many false alarms.

Large Language Models (LLMs) seem like a natural fit for writing these queries, but they face a "low-resource" language problem. CodeQL isn't as common as Python or Java, and its syntax changes frequently. Consequently, standard LLMs often "hallucinate" deprecated commands or fail to understand the complex, multi-file dataflow paths required to confirm a vulnerability.

Methods

QLCoder doesn't just ask an LLM to write a query and hope for the best. Instead, it uses an agentic iterative refinement loop:

  1. The Agent: Built on the Claude Code framework, the agent uses Claude 3.5 Sonnet to reason about the vulnerability.
  2. The Toolbox (MCP): The agent interacts with the environment via the Model Context Protocol (MCP).
The QLCoder Agentic Toolbox, featuring a Vector Database for RAG and a CodeQL Language Server for real-time syntax guidance via the Model Context Protocol (MCP).

This toolbox includes:

  • Vector Database (RAG): Provides the agent with up-to-date CodeQL documentation, sample queries, and snippets of the target project's Abstract Syntax Tree (AST).
  • CodeQL Language Server (LSP): Acts like an IDE's autocomplete, providing real-time syntax guidance and error diagnostics to prevent the agent from using non-existent functions.
  • The Validator: Once a query is proposed, QLCoder executes it on two versions of the code: the vulnerable version and the patched version.
  • Feedback Loop: If the query fails to find the bug in the vulnerable version or (crucially) if it still flags the bug in the patched version, the validator sends a detailed report back to the agent to try again.

Datasets

The authors evaluated QLCoder using CWE-Bench-Java, a benchmark consisting of 176 CVEs across 111 Java projects.

  • The projects range from tiny utilities to massive codebases with 1.5 million lines of code.
  • To ensure the LLM wasn't just "remembering" its training data, the authors included 65 fresh CVEs from 2025, which were reported after the model's training cutoff.

Key Insights and Ideas

  • Semantic Precision is the Goal: A "correct" query isn't just one that compiles; it must be discriminative. It must raise an alarm on the buggy code but remain silent on the fixed code. This "fix discrimination" forces the agent to understand exactly what the developers changed to secure the app.
  • LSP is Better than Web Search: The researchers found that giving the agent access to a live Language Server (for syntax checking) was far more effective than allowing it to search the web, which often returned outdated or irrelevant snippets that "polluted" the agent's reasoning.
  • Structured Reasoning over ASTs: By providing the agent with specific AST snippets from the "diff" of the patch, QLCoder helps the model identify the exact sources, sinks, and "sanitizers" (code that cleans dangerous input) involved in the bug.

Key Results

QLCoder sets a new state-of-the-art for automated vulnerability detection:

  • Success Rate: It synthesized correct, discriminative queries for 53.4% of the CVEs.
  • Baselines: In comparison, the base Claude Code agent only managed 10%, and Gemini CLI failed to produce any successful queries (0%).
  • F1 Score: QLCoder achieved an F1 score of 0.7, dwarfing the scores of general-purpose query suites in CodeQL (0.073) and IRIS (0.048) on these specific real-world cases.
  • Robustness: Performance remained consistent even on the "post-cutoff" 2025 CVEs, proving the system relies on reasoning rather than memorization.

Limitations and Future Work

  • Language Scope: Currently, the system is specialized for Java. While the framework is "CWE-agnostic," expanding to C++, Python, or Go would require populating the RAG database with new language-specific documentation.
  • Complex Vulnerabilities: QLCoder struggles with vulnerabilities that aren't purely code-based, such as those involving complex configuration files or multi-language interactions.
  • Cost and Time: Synthesizing a query takes about an hour and costs roughly $2.90 in API tokens. While much cheaper than a human security consultant, it is still a significant computational investment for large-scale scanning.

The authors have open-sourced the CodeQL LSP MCP server and QLCoder at github.com/neuralprogram/qlcoder.

Summary updated

BibTeX
@inproceedings{wang2026qlcoder,
  author = {Claire Wang and Ziyang Li and Saikat Dutta and Mayur Naik},
  title = {{QLCoder: A Query Synthesizer For Static Analysis of Security Vulnerabilities}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=J91IKwJrqv},
}
Figure