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
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
- OWASP: SQL Injection Prevention Cheat Sheet
- CWE-89: SQL Injection
Cross-Site Scripting (XSS)
- HTML context:
html.escape() - JavaScript context: JSON encode + HTML escape
- URL context: URL encode
- CSS context: CSS escape
Command Injection
shell=True
Additional Defense:
Path Traversal
Buffer Overflow
Cryptography
Patch Output Format
Patches are saved in markdown format with full context:Explanation
What Changed:- Added length check before copy
- Used
strncpyinstead ofstrcpy - Explicitly null-terminated buffer
- Added error handling for oversized input
- Original code had no bounds checking - attacker could overflow buffer
strcpycopies until null byte - arbitrary length- Now we validate input length and use bounded copy
- Explicit null termination prevents unterminated string bugs
- Input validation (length check)
- Safe API (strncpy instead of strcpy)
- Explicit termination (prevents partial write bugs)
- Error logging (aids detection)
Testing Recommendations
Unit Tests:- Send normal requests - verify functionality
- Send maximum-length inputs - verify acceptance
- Send oversized inputs - verify rejection
- Check logs for error messages
- 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