脚本会自动赋予项目自带包装器执行权限并运行它
原文依据:2 处脚本优先采用项目目录中的 mvnw;即使它原本不可执行,也会 chmod 后作为子进程运行。包装器属于待迁移仓库内容,并非此 Skill 中已审计的代码。
若仓库或其包装器已被篡改,运行迁移可在用户权限下执行任意命令,读取本地凭据、修改文件或联系外部服务。
在用户运行 BOM 自动化脚本且项目含 mvnw 时,脚本会优先选择仓库内的包装器;即使它没有执行权限,也会为用户、组和其他人添加执行位,随后作为子进程运行。因为包装器来自待迁移项目,它可能执行该仓库控制的代码并下载组件。用户可要求先审查包装器及其配置、禁止 chmod,并通过 --mvn 指定可信 Maven。
else: wrapper = os.path.join(project_dir, "mvnw") if os.path.isfile(wrapper): if not os.access(wrapper, os.X_OK): # Wrapper exists but isn't executable (common after fresh clones # on filesystems that don't preserve the +x bit). Try to fix it. try: mode = os.stat(wrapper).st_mode os.chmod(wrapper, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) print(f"[upgrade_bom] Added executable bit to {wrapper}.") except OSError as exc: print( f"[upgrade_bom] WARNING: mvnw exists at {wrapper} but is not " f"executable and chmod failed ({exc}); falling back to 'mvn'.", file=sys.stderr, ) return "mvn" if os.access(wrapper, os.X_OK): return wrapper return "mvn"查看另外 1 个位置
def _run_maven_recipe(mvn_cmd: str, project_dir: str, recipe: str, options: str) -> int: """Run an OpenRewrite recipe via the rewrite-maven-plugin.""" cmd = [ mvn_cmd, "-U", f"{MVN_REWRITE_PLUGIN}:run", f"-Drewrite.recipeArtifactCoordinates={MVN_REWRITE_ARTIFACT_COORDS}", f"-Drewrite.activeRecipes={recipe}", f"-Drewrite.options={options}", ] print(f"[upgrade_bom] Running: {' '.join(cmd)}") return subprocess.run(cmd, cwd=project_dir).returncode