T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/detect_conflicts.py:198
- Finding
- Untrusted Maven and Gradle Projects Can Execute Arbitrary Build Logic During Scanning<![CDATA[ ## Vulnerability Details **File Location**: `scripts/detect_conflicts.py:198-204` and `scripts/detect_conflicts.py:247-257` **Vulnerability Type**: Execution of untrusted project build logic **Risk Level**: High ### Vulnerable Code ```python result = subprocess.run( [mvn_cmd, "dependency:tree", "-DoutputType=text", "--batch-mode", "-q"], cwd=project_dir, capture_output=True, text=True, timeout=300 ) ``` ```python gradle_cmd = "gradlew.bat" if os.name == "nt" else "./gradlew" gradle_path = project_dir / gradle_cmd if not gradle_path.exists(): gradle_cmd = "gradle" try: result = subprocess.run( [str(gradle_path) if gradle_path.exists() else gradle_cmd, "dependencies", "--configuration", "compileClasspath"], cwd=project_dir, capture_output=True, text=True, timeout=300 ) ``` ### Technical Analysis The scanner executes Maven or Gradle inside the project being audited. Although arguments are passed as an array and therefore do not introduce conventional shell command injection, the build system itself is an executable-code boundary. A Maven project can execute attacker-controlled logic through build extensions, plugins, lifecycle behavior, and configuration loaded from the repository or environment. A Gradle project is especially dangerous because Gradle build scripts are executable programs. In addition, the scanner directly executes the repository-provided `gradlew` or `gradlew.bat` wrapper without validating its content or provenance. The requested tasks, such as `dependency:tree` and `dependencies`, do not guarantee safety. Build initialization and configuration happen before or while those tasks run, allowing malicious project code to execute even if the requested task appears read-only. The five-minute timeout only limits execution duration. It does not restrict filesystem access, subprocess creation, credential access, or network communication. ### Attack Path ...[truncated 1443 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Make static parsing the default for repositories that have not been explicitly trusted. 2. Require explicit, informed user confirmation before executing any project build command. 3. Clearly warn that Maven and Gradle build evaluation can execute arbitrary repository-controlled code. 4. Never execute a repository-provided Gradle wrapper without verification. Validate the wrapper scripts and wrapper JAR against an approved checksum or use a trusted, externally installed Gradle distribution. 5. Run live dependency resolution in a disposable sandbox or container with: - A read-only project mount where feasible. - No access to host credentials, SSH agents, cloud metadata, or sensitive environment variables. - A temporary isolated home directory. - Network access disabled unless dependency resolution explicitly requires it. - Strict CPU, memory, process, and execution-time limits. - A non-privileged operating-system identity. 6. Prevent the sandbox from accessing host Maven and Gradle credential files such as `~/.m2/settings.xml` and Gradle user-home secrets. 7. Document that live build analysis must not be used directly on untrusted repositories outside an isolation boundary. ]]>
