T09 · Insecure Skill Coding Practices
- Location
scripts/create-harness-docs.js:473- Finding
Unconditional Overwrite of Existing Agent Policy, CI, Documentation, and Test Files
- Content
View full analysis
Vulnerability Details
File Location:
scripts/create-harness-docs.js:473-474, 541, 548, 760, 769, 965
Vulnerability Type: Unsafe file overwrite
Risk Level: MediumComplete Vulnerable Code Snippets
js const filePath = path.join(PROJECT_ROOT, 'AGENTS.md'); fs.writeFileSync(filePath, content);js const filePath = path.join(PROJECT_ROOT, 'docs/architecture/ARCHITECTURE.md'); fs.writeFileSync(filePath, content); success(`创建 docs/architecture/ARCHITECTURE.md`); // Create documentation for each business domain for (const domain of project.domains) { const domainContent = generateDomainDoc(domain, project); const domainPath = path.join(PROJECT_ROOT, `docs/architecture/domains/${domain}.md`); fs.writeFileSync(domainPath, domainContent); }js const filePath = path.join(PROJECT_ROOT, 'docs/quality/grades.md'); fs.writeFileSync(filePath, content);js const filePath = path.join(PROJECT_ROOT, '.github/workflows/harness-ci.yml'); fs.writeFileSync(filePath, content);js fs.writeFileSync(path.join(testDir, 'ArchitectureTest.java'), content);Technical Analysis
The generation functions use
fs.writeFileSync()with its default write behavior, which creates a file or truncates and replaces it when it already exists. There is no existence check, confirmation prompt, backup, atomic merge process, or explicit force option.The documented
--initmode invokes all relevant generation functions and can therefore replace existing:AGENTS.mdAgent instructions and repository policy;- architecture and domain documentation;
- quality assessment records;
.github/workflows/harness-ci.yml;src/test/java/com/example/arch/ArchitectureTest.java.
This is security-relevant because
AGENTS.mdcan govern future Agent behavior and the GitHub Actions workflow governs repository security and quality checks. Replacing either file can r ...[truncated 1913 chars]- Remediation
View remediation
Remediation Suggestions
-
Refuse to overwrite existing files by default:
js fs.writeFileSync(filePath, content, { flag: 'wx' });Handle
EEXISTby reporting that the destination was preserved. -
Add an explicit
--forceoption for intentional replacement. The default execution path must remain non-destructive. -
Before writing, display a file-by-file change plan identifying files that will be created, modified, or skipped.
-
Require interactive confirmation before replacing security-sensitive files such as
AGENTS.mdand.github/workflows/harness-ci.yml. In non-interactive environments, require the explicit force option. -
Create timestamped backups before approved replacement, or use a safe merge mechanism that only updates clearly delimited generated sections.
-
Write content to a temporary file in the same directory, validate it, and atomically rename it into place only after authorization.
-
Treat Agent policy, CI workflow, and test files as protected destinations requiring separate opt-in flags, such as
--replace-agents,--replace-ci, and--replace-tests. -
Add automated tests confirming that existing destination files remain unchanged unless explicit overwrite authorization is supplied.
-
