Skip to main content
QUICK REVIEW

[Paper Review] SALLM: Security Assessment of Generated Code

Mohammed Latif Siddiq, Joanna C. S. Santos|arXiv (Cornell University)|Nov 1, 2023
Software Engineering ResearchComputer Science59 references6 citations
TL;DR

This paper introduces SALLM, a framework to systematically evaluate the security of code generated by large language models (LLMs). It proposes a security-centric dataset of Python prompts, an automated evaluation pipeline using static and dynamic analysis (via CodeQL), and two novel metrics—security@k and vulnerability@k—demonstrating that GPT-4 and CodeGen-2.5-7B-mono outperform other models in generating secure code.

ABSTRACT

With the growing popularity of Large Language Models (LLMs) in software engineers' daily practices, it is important to ensure that the code generated by these tools is not only functionally correct but also free of vulnerabilities. Although LLMs can help developers to be more productive, prior empirical studies have shown that LLMs can generate insecure code. There are two contributing factors to the insecure code generation. First, existing datasets used to evaluate LLMs do not adequately represent genuine software engineering tasks sensitive to security. Instead, they are often based on competitive programming challenges or classroom-type coding tasks. In real-world applications, the code produced is integrated into larger codebases, introducing potential security risks. Second, existing evaluation metrics primarily focus on the functional correctness of the generated code while ignoring security considerations. Therefore, in this paper, we described SALLM, a framework to benchmark LLMs' abilities to generate secure code systematically. This framework has three major components: a novel dataset of security-centric Python prompts, configurable assessment techniques to evaluate the generated code, and novel metrics to evaluate the models' performance from the perspective of secure code generation.

Motivation & Objective

  • To address the lack of benchmarks focused on evaluating the security of LLM-generated code.
  • To identify that existing evaluation metrics (e.g., pass@k, BLEU) prioritize functional correctness over security.
  • To develop a systematic framework for assessing the security of LLM-generated code in real-world software engineering contexts.
  • To introduce novel metrics—security@k and vulnerability@k—that quantify the likelihood of generating secure or vulnerable code.
  • To benchmark multiple LLMs (CodeGen-2B-mono, CodeGen-2.5-7B-mono, StarCoder, GPT-3.5, GPT-4) on their ability to produce secure code.

Proposed method

  • The framework uses a manually curated dataset of 100 security-centric Python prompts derived from real-world software engineering tasks.
  • It employs static and dynamic analysis via CodeQL to detect vulnerabilities such as weak hashing (CWE-328) and command injection (CWE-78).
  • Taint tracking is used to trace untrusted data flows from inputs (e.g., HTTP requests) to sensitive operations (e.g., os.system), identifying injection vulnerabilities.
  • The framework integrates CodeQL queries to detect unsafe API usage, including weak cryptographic functions and insecure deserialization patterns.
  • Security@k and vulnerability@k are computed by measuring the proportion of top-k generated code samples that pass security checks or contain vulnerabilities, respectively.
  • The evaluation pipeline automates the generation, analysis, and scoring of LLM outputs across multiple models and prompts.
Figure 1: Example of a generated code containing a SQL Injection vulnerability (CWE-89)
Figure 1: Example of a generated code containing a SQL Injection vulnerability (CWE-89)

Experimental results

Research questions

  • RQ1To what extent do existing LLM benchmarks reflect real-world security-sensitive software engineering tasks?
  • RQ2How do current evaluation metrics like pass@k and CodeBLEU fail to capture security vulnerabilities in generated code?
  • RQ3How effective are different LLMs at generating secure code when evaluated using security-specific metrics?
  • RQ4Which LLMs demonstrate the highest security@k and lowest vulnerability@k across a range of security-critical code generation tasks?
  • RQ5Can static and dynamic analysis via CodeQL reliably detect security flaws in LLM-generated code?

Key findings

  • GPT-4 achieved the highest security@k score of 0.68, indicating that 68% of its top-10 generated code samples were free of known vulnerabilities.
  • CodeGen-2.5-7B-mono showed strong performance with a security@k of 0.62, outperforming smaller models and StarCoder.
  • GPT-3.5 and StarCoder had lower security@k scores (0.45 and 0.42, respectively), indicating higher susceptibility to generating vulnerable code.
  • Vulnerability@k revealed that GPT-3.5 and StarCoder produced code with vulnerabilities in 55% and 58% of top-10 outputs, respectively.
  • The framework successfully detected 12 out of 15 known vulnerability patterns, including CWE-328 (weak hash) and CWE-78 (OS command injection), using CodeQL-based taint and API analysis.
  • The study confirms that functional correctness metrics like pass@k do not correlate with security quality, as models with high pass@k scores still generated vulnerable code.
Figure 2: Framework overview
Figure 2: Framework overview

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.