Skip to main content

Overview

RAPTOR generates production-ready security patches using LLM analysis combined with secure coding best practices. The system follows OWASP and CWE guidance to ensure comprehensive, maintainable fixes.
Patches are generated using a senior security engineer persona - focusing on defense-in-depth and production readiness, not just quick fixes.

Patch Creation Principles

1. Security First

1

Fix Completely

Address the root cause, not just symptoms
Bad Patch: Add bounds check to one vulnerable callGood Patch: Refactor to use safe API throughout
2

Defense in Depth

Apply multiple layers of protection
  • Input validation
  • Output sanitization
  • Secure API usage
  • Least privilege
3

No New Vulnerabilities

Ensure the fix doesn’t introduce new issues
  • Verify no integer overflows in new bounds checks
  • Check for NULL pointer dereferences
  • Avoid creating race conditions

2. Production Ready

Maintain existing functionality
Preserve performance characteristics
Keep code readable and maintainable
Include clear explanatory comments

3. Best Practices

  • Follow OWASP secure coding guidelines
  • Reference relevant CWE entries
  • Use framework-provided security functions
  • Validate all inputs, sanitize all outputs

Patch Generation Workflow

The LLM follows this process:

Patch Strategies by Vulnerability Type

SQL Injection

Principle: Use parameterized queries, never string concatenation References:
  • OWASP: SQL Injection Prevention Cheat Sheet
  • CWE-89: SQL Injection

Cross-Site Scripting (XSS)

Principle: HTML-encode all user input in output Context-Specific Encoding:
  • HTML context: html.escape()
  • JavaScript context: JSON encode + HTML escape
  • URL context: URL encode
  • CSS context: CSS escape

Command Injection

Principle: Use subprocess with argument lists, never shell=True Additional Defense:

Path Traversal

Principle: Canonicalize paths and validate they stay within allowed directory

Buffer Overflow

Better Alternative:

Cryptography

Principle: Use appropriate algorithms for the use case

Patch Output Format

Patches are saved in markdown format with full context:

Explanation

What Changed:
  1. Added length check before copy
  2. Used strncpy instead of strcpy
  3. Explicitly null-terminated buffer
  4. Added error handling for oversized input
Why:
  • Original code had no bounds checking - attacker could overflow buffer
  • strcpy copies until null byte - arbitrary length
  • Now we validate input length and use bounded copy
  • Explicit null termination prevents unterminated string bugs
Defense in Depth:
  • Input validation (length check)
  • Safe API (strncpy instead of strcpy)
  • Explicit termination (prevents partial write bugs)
  • Error logging (aids detection)

Testing Recommendations

Unit Tests:
Integration Tests:
  • Send normal requests - verify functionality
  • Send maximum-length inputs - verify acceptance
  • Send oversized inputs - verify rejection
  • Check logs for error messages
Security Tests:
  • Fuzz with AFL or libFuzzer
  • Run with AddressSanitizer
  • Verify no regression in existing tests

Generated by RAPTOR Autonomous Security Agent Review and test before applying to production