gpt-engineer icon indicating copy to clipboard operation
gpt-engineer copied to clipboard

Security Issue: Arbitrary File Write Vulnerability in Code Modification Logic

Open glmgbj233 opened this issue 4 months ago • 0 comments

file:engineer/engineer.py

Description

In the current implementation of _edit_repo_file(), no security checks are performed on:

  1. The file path being modified
  2. The content being written to the file

This introduces potential security vulnerabilities that could result in:

  1. Malicious large language model (LLM) output writing to sensitive system files
  2. Path traversal attacks modifying files outside of the intended directory
  3. No validation of file extensions or content types

Affected Components

  1. File path handling in _find_relevant_files() — only prepends /tmp/repo/ without proper sanitization
  2. Direct file operations in _edit_repo_file() — blindly trusts the changes generated by the LLM

Steps to Reproduce

  1. Craft a malicious prompt that causes the LLM to generate harmful file modifications
  2. Observe the system executing these changes without validation

Recommended Fixes

  1. Implement path sanitization and validation
  2. Add a whitelist for allowed file extensions
  3. Validate content against dangerous patterns
  4. Introduce sandboxing for file operations

glmgbj233 avatar Jul 07 '25 08:07 glmgbj233