T09 · Insecure Skill Coding Practices
Error
- Location
- references/deploy.mjs:53
- Finding
- Overbroad Directory Publication Can Expose Unrelated Sensitive Files<![CDATA[ ## Vulnerability Details **File Location**: `references/deploy.mjs:53-69` **Vulnerability Type**: Unrestricted recursive staging of the source directory **Risk Level**: High ### Vulnerable Code ```js // Copy sibling assets (css/js/img) so a multi-file page renders — but only when // the source dir is a SEPARATE directory (not our staged root's parent), and // never the staged dir itself, so we can't recurse into our own output. const srcDir = dirname(htmlPath); if ( existsSync(srcDir) && statSync(srcDir).isDirectory() && srcDir !== stagedDir && srcDir !== root ) { cpSync(srcDir, stagedDir, { recursive: true, filter: (s) => !s.includes('node_modules') && !s.includes('.git') && !s.includes('__MACOSX') && !basename(s).startsWith('.') && s !== stagedDir, // guard against copying the staged dir into itself }); } ``` ### Technical Analysis Deploying a single HTML file recursively copies its entire containing directory into the deployment staging directory. The filter excludes only a small set of hidden or specially named paths. It does not restrict staging to assets referenced by the page or exclude visible sensitive files such as: - `credentials.json` - Configuration and environment backups - Database exports - Private reports - Source maps containing source code - Unrelated documents or archives Wrangler later publishes the staged directory. Consequently, the script can transmit and publicly host files that the operator did not intend to deploy. This exceeds the minimum filesystem and network scope necessary to publish the specified HTML file and its required assets. ### Attack Path 1. An HTML file is placed in, or selected from, a directory containing unrelated sensitive files. 2. The operator runs the documented `deploy.mjs` command for that HTML file. 3. `stageForDrop()` recursively copies the complete parent directory. 4. The limited filter permits visible sensitive files to enter the staging ...[truncated 832 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Stage only the explicitly requested HTML file by default. 2. Parse HTML and CSS references and copy only required local assets after canonical path validation. 3. Alternatively, require an explicit site-directory argument so directory publication is intentional and visible. 4. Generate and display a deployment manifest before upload, especially when files other than the requested page are included. 5. Reject symlinks and ensure every copied path remains inside the approved source root. 6. Add deny rules for common sensitive filenames and extensions as defense in depth, including credential files, environment files, private keys, database files, backups, and archives. 7. Add tests proving that unrelated visible files and nested sensitive files are not staged. ]]>
