T09 · Insecure Skill Coding Practices
- Location
scripts/patch_all_v10.cjs:83- Finding
Non-atomic broad rewriting of installed executable bundles
- Content
View full analysis
Vulnerability Details
File Location:
scripts/patch_all_v10.cjs:83-138, 198-217;scripts/apply_patch.cjs:73, 222-231
Vulnerability Type: Unsafe in-place modification of installed application code
Risk Level: HighVulnerable Code
javascript function writeCore(fn, c) { fs.writeFileSync(path.join(DIST, fn), c); } for (const [from, to] of globalRepl) { for (const f of coreFiles) { let c = readCore(f); if (c.includes(to)) continue; if (c.includes(from)) { c = c.split(from).join(to); writeCore(f, c); p2++; } } } function writePlugin(fn, c) { fs.writeFileSync(path.join(PLUGIN_DIST, fn), c); } if (graphContent.includes('https://login.microsoftonline.com/')) { graphContent = graphContent.replaceAll( 'https://login.microsoftonline.com/', 'https://login.chinacloudapi.cn/' ); ok('MSAL login endpoints'); p3++; } if (graphContent.includes('sts.windows.net')) { graphContent = graphContent.replaceAll( 'sts.windows.net', 'sts.chinacloudapi.cn' ); ok('STS issuers'); p3++; } if (oauthContent.includes('https://login.microsoftonline.com/')) { oauthContent = oauthContent.replaceAll( 'https://login.microsoftonline.com/', 'https://login.chinacloudapi.cn/' ); writePlugin(oauthFile, oauthContent); ok('OAuth token endpoints'); p4++; }The legacy patcher uses the same unsafe model:
javascript function writeFileContent(filename, content) { fs.writeFileSync(path.join(OPENCLAW_DIST, filename), content); } if (content.includes(repl.from)) { content = content.split(repl.from).join(repl.to); writeFileContent(file, content); patchedFiles++; }Technical Analysis
The scripts directly overwrite executable JavaScript bundles inside installed OpenClaw and MSTeams packages. Several changes use unrestricted string replacement across complete compiled files.
The implementation does not:
- Verify an exact supported package version before mutation ...[truncated 2365 chars]
- Remediation
View remediation
Remediation Suggestions
- Enforce an explicit allowlist of exact OpenClaw and MSTeams package versions.
- Verify cryptographic hashes of every target file before applying a patch.
- Refuse to patch unknown or modified bundles.
- Create permission-preserving backups before any modification.
- Write patched content to a temporary file in the same directory, validate it, and atomically rename it into place.
- Parse source structure or use exact, context-aware patches instead of unrestricted string replacement.
- Confirm that every expected replacement occurs exactly once unless a different count is explicitly expected.
- Run JavaScript syntax validation and comprehensive endpoint-policy verification before committing changes.
- Treat the operation as a transaction: if any phase fails, restore every changed file.
- Provide a documented rollback command and retain a manifest containing original hashes, patched hashes, and backup locations.
