Skip to content

fix: 增加预启动命令前的确认步骤#3050

Open
lhx077 wants to merge 1 commit into
devfrom
codex/propose-fix-for-rce-vulnerability
Open

fix: 增加预启动命令前的确认步骤#3050
lhx077 wants to merge 1 commit into
devfrom
codex/propose-fix-for-rce-vulnerability

Conversation

@lhx077

@lhx077 lhx077 commented Jun 6, 2026

Copy link
Copy Markdown
Member

Motivation

  • Instance-level pre-launch commands were read from instance-managed config files and executed automatically via cmd.exe, creating an RCE risk when users import or open untrusted instance/modpack folders.
  • The change aims to prevent silent execution of attacker-controlled per-instance commands by requiring explicit user consent before running them.

Description

  • Added ConfirmInstancePreLaunchCommand(string) to ModLaunch to show a warning dialog and ask the user to Run or Skip an instance-supplied pre-launch command.
  • The instance command is passed through ArgumentReplace then validated by ConfirmInstancePreLaunchCommand, and if the user declines the command is cleared so it will not be executed or written to exported launch scripts.
  • Added English and Simplified Chinese localization keys for the confirmation prompt (Minecraft.Launch.CustomCommand.InstanceConfirm.*) in PCL.Core/App/Localization/Languages/en-US.xaml and PCL.Core/App/Localization/Languages/zh-CN.xaml.
  • The global pre-launch command behavior was left unchanged; only per-instance commands now require confirmation.

Testing

  • Parsed modified XAML localization files with xml.etree.ElementTree.parse to validate XML well-formedness, and the check succeeded.
  • Ran git diff --check to ensure no whitespace/error diff issues, and it reported no problems.
  • Attempted dotnet --info to run a build verification but it failed in the environment with /bin/bash: dotnet: command not found, so no project build was executed.

Codex Task

由 Sourcery 提供的摘要

在运行每个实例的预启动命令之前,增加一个确认步骤,以减少无意或不安全命令被执行的风险。

新功能:

  • 在执行实例特定的预启动命令或将其包含到导出的启动脚本之前,提示用户确认或跳过这些命令。

文档:

  • 为实例预启动命令确认对话框新增英文和简体中文的本地化条目。
Original summary in English

Summary by Sourcery

Add a confirmation step before running per-instance pre-launch commands to mitigate unintended or unsafe command execution.

New Features:

  • Prompt users to confirm or skip instance-specific pre-launch commands before they are executed or included in exported launch scripts.

Documentation:

  • Add English and Simplified Chinese localization entries for the instance pre-launch command confirmation dialog.

@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: S PR 大小评估:小型 and removed codex labels Jun 6, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 6, 2026

Copy link
Copy Markdown

审阅者指南

在执行每实例预启动命令之前增加一个确认对话框以降低 RCE 风险,并将其接入实例命令流程,同时为该提示添加新的本地化字符串。

实例预启动命令确认的时序图

sequenceDiagram
    participant ModLaunch
    participant Config
    participant ModBase
    participant ModMain
    participant Lang

    ModLaunch->>Config: read PreLaunchCommand[PathInstance]
    alt instance command not empty
        ModLaunch->>ModLaunch: ArgumentReplace(customCommandVersion, true)
        ModLaunch->>ModBase: RunInUiWait(callback)
        ModBase->>ModMain: MyMsgBox(message, title, runText, skipText, isWarn)
        ModMain->>Lang: Text(Minecraft.Launch.CustomCommand.InstanceConfirm.Message)
        ModMain->>Lang: Text(Minecraft.Launch.CustomCommand.InstanceConfirm.Title)
        ModMain->>Lang: Text(Minecraft.Launch.CustomCommand.InstanceConfirm.Run)
        ModMain->>Lang: Text(Minecraft.Launch.CustomCommand.InstanceConfirm.Skip)
        ModMain-->>ModBase: result (1 for Run, other for Skip)
        ModBase-->>ModLaunch: confirmed flag
        alt confirmed is false
            ModLaunch->>ModLaunch: McLaunchLog("已跳过实例自定义命令:" + command)
            ModLaunch->>ModLaunch: customCommandVersion = ""
        end
    end
    ModLaunch->>ModLaunch: continue launch and script export with customCommandGlobal and customCommandVersion
Loading

文件级更改

更改 详情 文件
为每实例预启动命令引入一个确认流程,并将其集成到启动流水线中。
  • 添加 ConfirmInstancePreLaunchCommand 辅助方法,在 UI 线程上使用本地化文本显示警告对话框,并返回用户的选择。
  • 当用户跳过某个每实例预启动命令时记录一条日志消息。
  • 更新 McLaunchCustom,使每实例预启动命令先进行参数展开,然后传入确认辅助方法;如果未被确认,则清空该命令以避免后续执行或导出。
Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.cs
为新的确认对话框在英文和简体中文中添加本地化条目。
  • 在英文本地化文件中定义实例预启动命令确认提示的标题、正文消息和“运行/跳过”按钮文本资源。
  • 在简体中文本地化文件中镜像同一组资源,并保持与现有本地化风格一致。
PCL.Core/App/Localization/Languages/en-US.xaml
PCL.Core/App/Localization/Languages/zh-CN.xaml

提示与命令

与 Sourcery 交互

  • 触发新的审阅: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub Issue: 在审阅评论下回复,要求 Sourcery 从该评论创建一个 Issue。你也可以在审阅评论下回复 @sourcery-ai issue 来从中创建 Issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中的任意位置写上 @sourcery-ai 即可随时生成标题。你也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 总结: 在 Pull Request 内容中的任意位置写上 @sourcery-ai summary,即可在指定位置生成 PR 总结。你也可以在 Pull Request 中评论 @sourcery-ai summary 来在任意时间(重新)生成总结。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide 来在任意时间(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve 来解决所有 Sourcery 评论。如果你已经处理了所有评论但不想再看到它们,这会很有用。
  • 撤销所有 Sourcery 审阅: 在 Pull Request 中评论 @sourcery-ai dismiss 来撤销所有现有的 Sourcery 审阅。尤其适用于你想从头开始新的审阅——别忘了再评论 @sourcery-ai review 来触发新一轮审阅!

自定义你的体验

访问你的 控制面板 来:

  • 启用或禁用审阅功能,例如 Sourcery 生成的 Pull Request 总结、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅指令。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Adds a confirmation dialog before executing per-instance pre-launch commands to mitigate RCE risk, and wires it into the instance command path along with new localized strings for the prompt.

Sequence diagram for instance pre-launch command confirmation

sequenceDiagram
    participant ModLaunch
    participant Config
    participant ModBase
    participant ModMain
    participant Lang

    ModLaunch->>Config: read PreLaunchCommand[PathInstance]
    alt instance command not empty
        ModLaunch->>ModLaunch: ArgumentReplace(customCommandVersion, true)
        ModLaunch->>ModBase: RunInUiWait(callback)
        ModBase->>ModMain: MyMsgBox(message, title, runText, skipText, isWarn)
        ModMain->>Lang: Text(Minecraft.Launch.CustomCommand.InstanceConfirm.Message)
        ModMain->>Lang: Text(Minecraft.Launch.CustomCommand.InstanceConfirm.Title)
        ModMain->>Lang: Text(Minecraft.Launch.CustomCommand.InstanceConfirm.Run)
        ModMain->>Lang: Text(Minecraft.Launch.CustomCommand.InstanceConfirm.Skip)
        ModMain-->>ModBase: result (1 for Run, other for Skip)
        ModBase-->>ModLaunch: confirmed flag
        alt confirmed is false
            ModLaunch->>ModLaunch: McLaunchLog("已跳过实例自定义命令:" + command)
            ModLaunch->>ModLaunch: customCommandVersion = ""
        end
    end
    ModLaunch->>ModLaunch: continue launch and script export with customCommandGlobal and customCommandVersion
Loading

File-Level Changes

Change Details Files
Introduce a confirmation flow for per-instance pre-launch commands and integrate it into the launch pipeline.
  • Add ConfirmInstancePreLaunchCommand helper that shows a warning dialog on the UI thread using localized text and returns the user’s choice.
  • Log a message when a per-instance pre-launch command is skipped by the user.
  • Update McLaunchCustom so that per-instance pre-launch commands are argument-expanded, then passed through the confirmation helper, and cleared if not confirmed to avoid later execution or export.
Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.cs
Add localization entries for the new confirmation dialog in English and Simplified Chinese.
  • Define title, body message, and Run/Skip button text resources for the instance pre-launch command confirmation prompt in the English localization file.
  • Mirror the same set of resources in the Simplified Chinese localization file, matching existing localization style.
PCL.Core/App/Localization/Languages/en-US.xaml
PCL.Core/App/Localization/Languages/zh-CN.xaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出了一些总体反馈:

  • ConfirmInstancePreLaunchCommand 的日志消息被硬编码为中文("已跳过实例自定义命令");建议改用本地化字符串 key,这样日志输出就能与当前 UI 语言保持一致。
  • 在确认对话框中展示完整的预启动命令,对于较长或复杂的命令可能会比较臃肿;可以考虑对命令进行截断或调整展示方式(例如使用可滚动文本区域,或者简短预览并提供查看完整内容的方式),以保持对话框的可用性。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `ConfirmInstancePreLaunchCommand` log message is hard-coded in Chinese (`"已跳过实例自定义命令"`); consider using a localized string key so the log output matches the current UI language.
- Displaying the full pre-launch command in the confirmation dialog may become unwieldy for long or complex commands; consider truncating or formatting the command (e.g., scrollable text area or shortened preview with a way to see full content) to keep the dialog usable.

Sourcery 对开源项目免费使用——如果你觉得我们的代码审查有帮助,欢迎分享 ✨
帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English

Hey - I've left some high level feedback:

  • The ConfirmInstancePreLaunchCommand log message is hard-coded in Chinese ("已跳过实例自定义命令"); consider using a localized string key so the log output matches the current UI language.
  • Displaying the full pre-launch command in the confirmation dialog may become unwieldy for long or complex commands; consider truncating or formatting the command (e.g., scrollable text area or shortened preview with a way to see full content) to keep the dialog usable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `ConfirmInstancePreLaunchCommand` log message is hard-coded in Chinese (`"已跳过实例自定义命令"`); consider using a localized string key so the log output matches the current UI language.
- Displaying the full pre-launch command in the confirmation dialog may become unwieldy for long or complex commands; consider truncating or formatting the command (e.g., scrollable text area or shortened preview with a way to see full content) to keep the dialog usable.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@lhx077 lhx077 changed the title Add confirmation prompt for instance pre-launch commands fix: 增加预启动命令前的确认步骤 Jun 6, 2026
@whitecat346

Copy link
Copy Markdown
Member

修复无法编译问题

private static bool ConfirmInstancePreLaunchCommand(string command)
{
var confirmed = false;
ModBase.RunInUiWait(() =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MyMsgBox 不需要切换到 UI 上下文运行

ModBase.RunInUiWait(() =>
confirmed = ModMain.MyMsgBox(
Lang.Text("Minecraft.Launch.CustomCommand.InstanceConfirm.Message",
ModMinecraft.McInstanceSelected?.Name ?? "", command),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ModMinecraft.McInstanceSelected?.Name ?? "", command),
ModInstanceList.McInstanceSelected?.Name ?? "", command),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S PR 大小评估:小型 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants