Skip to content
Book Open access

SOSecure: The Wisdom of the Crowd for Safer AI-Generated Code

Jul 2026 · AIware · pp. 135-144 · 0 citations · 36 references
Computer Science

TL;DR

SOSecure is introduced, a Retrieval- Augmented Generation (RAG) system that leverages the collective security expertise found in SO discussions to improve the security of LLM-generated code, and builds a security-focused knowledge base by extracting SO answers and comments that explicitly identify vulnerabilities.

Abstract

Large Language Models (LLMs) are widely used for automated code generation. Their reliance on infrequently updated pretraining data can leave them unaware of newly discovered vulnerabilities and evolving security standards, making them prone to producing insecure code. In contrast, developer communities on Stack Overflow (SO) provide an ever-evolving repository of knowledge, where security vulnerabilities are actively discussed and addressed through collective expertise. These community-driven insights remain largely untapped by LLMs. This paper introduces SOSecure, a Retrieval- Augmented Generation (RAG) system that leverages the collective security expertise found in SO discussions to improve the security of LLM-generated code. We build a security-focused knowledge base by extracting SO answers and comments that explicitly identify vulnerabilities. Unlike common uses of RAG, SOSecure triggers after code has been generated to find discussions that identify flaws in similar code. These are used in a prompt to an LLM to consider revising the code. Evaluation across three datasets (SALLM dataset, LLMSecEval, and LMSys) shows that SOSecure achieves strong fix rates of 71.7%, 91.3%, and 96.7% respectively, compared to prompting GPT-4 without relevant discussions (49.1%, 56.5%, and 37.5%), and outperforms multiple other baselines. SOSecure operates as a language-agnostic complement to existing LLMs, without requiring retraining or fine-tuning, making it easy to deploy. Our results underscore the importance of maintaining active developer forums,

Read PDF

Similar papers

Jul 2026

The Language of Security: How Prompt Syntax Shapes Secure Code Generation in Open LLMs

This work systematically generates syntactic variants of security-relevant code generation prompts and evaluates their impact on code security across multiple open LLMs and programming languages, identifying prompt syntax as a concrete security control surface and providing actionable guidance for reducing vulnerability risk in LLM-assisted development.

Matteo Cicalese, Antonio Della Porta, Stefano Lambiase et al. · 0 citations
#machine learning Preprint Sep 2026

CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code Generation

Retrieval-Augmented Code Generation (RACG) improves LLM-based software development by retrieving external code artifacts, documentation, and patches, and incorporating them into the generation context. This reliance on external knowledge introduces a critical trust boundary: poisoned artifacts can influence generated code without modifying the underlying LLM. Prior work shows that selecting existing vulnerable examples can increase the general vulnerability rate of RACG outputs, but leaves open whether a black-box attacker can construct a single task-matched artifact that propagates an attacker-selected weakness. We introduce CodePoisonRAG, a targeted upstream knowledge-poisoning framework that transforms benign fixed-code entries into poisoned artifacts. Its attack chain combines CWE-specific Vulnerability Injection, which embeds a selected source-to-sink flow while retaining task alignment, with Semantic Mislabeling, which adds false safety claims without repairing the vulnerable behavior. The attacker has no access to the victim's deployed knowledge base, retriever, re-ranker, generator, prompt, or defense mechanism and injects at most one artifact per anticipated programming task. We construct 85 poisoned artifacts covering ten CWE classes across Java and C, yielding an aggregate corpus-poisoning ratio of 0.7%. Across three generators, all 85 artifacts appear among the Top-3 results for their corresponding queries, and CodePoisonRAG achieves attack success rates between 0.80 and 0.93. Against CodeGuarder, which injects vulnerability-specific security knowledge into the generation context, the attack retains success rates between 0.40 and 0.71. These results show that RACG poisoning extends beyond the incidental propagation of existing vulnerabilities to the targeted construction and propagation of attacker-selected weaknesses.

Varun Gadey, Ziad Marey, Alexandra Dmitrienko · 0 citations
Open access 2026

Shift-Left Security for AI-Generated Code: Detecting and Preventing Vulnerabilities at Build-Time

A structured, research-backed blueprint for build-time security controls tailored specifically to AI-generated code is developed, organized across three interdependent layers: a pre-pull-request policy and governance layer; a build-time detection layer combining AI-augmented and traditional static analysis; and a prioritization and feedback layer applying application security posture management correlation to convert detection volume into developer-actionable risk reduction.

Bala Thripura Akasam · 0 citations
Review Jul 2026

Security Vulnerability Patterns in AI-Generated Code: A Cross-Model Comparative Study

The risk is not tied to any particular model but rather to the task category, and organizations should ask not which tool to trust, but instead whether LLM-generated automation code should be deployed without review.

Shanna M. Kahn, John D. Hastings · 0 citations
Preprint Aug 2026

Securing AI-Generated Code: A Just-in-Time Vulnerability Detection and Remediation Pipeline

An automated security evaluation pipeline that generates Python code from LLMSecEval prompts, scans for vulnerabilities using CodeQL and Bandit in parallel with an independent Code Validator LLM, enriches the Code Validator findings with MITRE ATT&CK techniques, CWE Observed Examples, and Python best practice guidelines, generates fixes via the Code Generation LLM, and re-scans with CodeQL and Bandit to verify outcomes is presented.

Mikhail Surikov · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.