SOSecure: Safer Code Generation with RAG and StackOverflow Discussions
Not on the map. Why?
Abstract (arXiv)
Large Language Models (LLMs) are widely used for automated code generation. Their reliance on infrequently updated pretraining data leaves 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, LLMSecEval, and LMSys) show 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, which have dropped substantially in usage with LLM adoptions.
Key facts. Cited by 5 papers in the map (data through 14 Oct 2026). First posted on arXiv 17 Mar 2025.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2025: 3; 2026: 2.
5 papers.
- 2025Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injectioncited by 16
- 2025RESCUE: Retrieval Augmented Secure Code Generationcited by 7
- 2026CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code Generationcited by 1
- 2025Harmonia: End-to-End RAG Serving Optimizationcited by 0
- 2026SEEK: Agentic Knowledge Graph Retrieval for Secure Code Generationcited by 0
- 2026SEEK: Agentic Knowledge Graph Retrieval for Secure Code Generation10 Oct 2026
- 2026CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code Generation2 Sep 2026
- 2025RESCUE: Retrieval Augmented Secure Code Generation21 Oct 2025
- 2025Harmonia: End-to-End RAG Serving Optimization1 May 2025
- 2025Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injection23 Apr 2025
Similar, not cited
Close in wording, no citation either way
- 2026Inference-Time Safety For Code LLMs Via Retrieval-Augmented Revision
- 2026Improving LLM-Assisted Secure Code Generation through Retrieval-Augmented-Generation and Multi-Tool Feedback
- 2025Rethinking the Evaluation of Secure Code Generation
- 2026RealSec-bench: A Benchmark for Evaluating Secure Code Generation in Real-World Repositories
- 2026Revisiting Vul-RAG: Reproducibility and Replicability of RAG-based Vulnerability Detection with Open-Weight Models
- 2026Persistent Human Feedback, LLMs, and Static Analyzers for Secure Code Generation and Vulnerability Detection
- 2025RefleXGen:The unexamined code is not worth using
- 2026An Empirical Evaluation of LLM-Based Approaches for Code Vulnerability Detection: RAG, SFT, and Dual-Agent Systems