Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practices

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Patir, Rupam, Guo, Keyan, Cai, Haipeng, Hu, Hongxin
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866912642285699072
author Patir, Rupam
Guo, Keyan
Cai, Haipeng
Hu, Hongxin
author_facet Patir, Rupam
Guo, Keyan
Cai, Haipeng
Hu, Hongxin
contents The code generation capabilities of Large Language Models (LLMs) have transformed the field of software development. However, this advancement also presents significant security challenges, as LLM-generated code often contains vulnerabilities. One direction of research strengthens LLMs by injecting or refining security knowledge through curated datasets, model tuning, or static analyzers. While effective in certain settings, these methods can be resource-intensive, less adaptable to zero-day vulnerabilities, and often inapplicable to proprietary models. To address these challenges, we introduce GRASP, which explores a new direction that focuses on structured reasoning over Secure Coding Practices(SCPs) rather than additional training or external feedback. GRASP comprises two key ideas: (1) an SCP graph that organizes SCPs into a Directed Acyclic Graph (DAG) capturing dependencies and relationships, and (2) a graph-based reasoning process that systematically guides LLMs through relevant SCPs for code generation. This design enables interpretable, model-agnostic, and scalable security improvements, particularly for previously unseen vulnerabilities. Our evaluation shows that GRASP consistently achieves Security Rates (SR) exceeding 80% across multiple LLMs, and delivers up to 88% improvements over baselines on zero-day vulnerabilities.
format Preprint
id arxiv_https___arxiv_org_abs_2510_09682
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practices
Patir, Rupam
Guo, Keyan
Cai, Haipeng
Hu, Hongxin
Cryptography and Security
Artificial Intelligence
Software Engineering
The code generation capabilities of Large Language Models (LLMs) have transformed the field of software development. However, this advancement also presents significant security challenges, as LLM-generated code often contains vulnerabilities. One direction of research strengthens LLMs by injecting or refining security knowledge through curated datasets, model tuning, or static analyzers. While effective in certain settings, these methods can be resource-intensive, less adaptable to zero-day vulnerabilities, and often inapplicable to proprietary models. To address these challenges, we introduce GRASP, which explores a new direction that focuses on structured reasoning over Secure Coding Practices(SCPs) rather than additional training or external feedback. GRASP comprises two key ideas: (1) an SCP graph that organizes SCPs into a Directed Acyclic Graph (DAG) capturing dependencies and relationships, and (2) a graph-based reasoning process that systematically guides LLMs through relevant SCPs for code generation. This design enables interpretable, model-agnostic, and scalable security improvements, particularly for previously unseen vulnerabilities. Our evaluation shows that GRASP consistently achieves Security Rates (SR) exceeding 80% across multiple LLMs, and delivers up to 88% improvements over baselines on zero-day vulnerabilities.
title Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practices
topic Cryptography and Security
Artificial Intelligence
Software Engineering
url https://arxiv.org/abs/2510.09682