fix(plugins): ask before loading a changed Java agent (#4003)

When a plugin's Java agent jar changed, the host already refused to load it until java.agent was granted again, but Settings still showed the permission as granted, so the agent silently disappeared from Run/Debug. PluginInfo now carries the agent's file name, arguments and whether its jar still matches the approved hash; Settings › Plugins warns about a changed jar and offers Approve new jar, which grants the permission again.

Co-authored-by: NeverKnowsTomorrow <36879844+NeverKnowsTomorrow@users.noreply.github.com>
This commit is contained in:
Q
2026-11-17 21:20:40 +08:00
committed by GitHub
co-authored by NeverKnowsTomorrow
parent 39f709def5
commit a83bad107c
11 changed files with 137 additions and 11 deletions
+12
View File
@@ -8880,6 +8880,8 @@ export type PluginInfo = {
homepage: string | null,
changeNotes: string | null,
icon: PluginIcon | null,
/** The Java agent this plugin declares, and whether it is still approved. */
javaAgent: PluginJavaAgent | null,
source: PluginSource,
/** Package directory. */
path: IpcPath,
@@ -8914,6 +8916,16 @@ export type PluginInfo = {
extensionPoints: ExtensionPointInfo[],
};
/** The Java agent a plugin contributes, for Settings › Plugins. */
export type PluginJavaAgent = {
/** The jar's file name. */
fileName: string,
/** The optional argument passed after `=`. */
args: string | null,
/** The jar still has the hash recorded when `java.agent` was granted. */
approved: boolean,
};
/**
* Commands of this module the remote server answers.
* Versioned plugin visuals, refreshed after the editor synchronizes its buffer.
+21 -4
View File
@@ -581,7 +581,7 @@ function CapabilityList({ plugin, busy }: { plugin: PluginInfo; busy: boolean })
c.id.startsWith("process:") ? (
<ProgramPermission plugin={plugin} cap={c} disabled={busy || !confirmed} />
) : (
c.id === "java.agent" && <JavaAgentDetail plugin={plugin} />
c.id === "java.agent" && <JavaAgentDetail plugin={plugin} cap={c} disabled={busy || !confirmed} />
)
}
>
@@ -601,14 +601,31 @@ function CapabilityList({ plugin, busy }: { plugin: PluginInfo; busy: boolean })
}
/** The agent a `java.agent` grant loads: its jar's file name and arguments, as `-javaagent:` takes them. */
function JavaAgentDetail({ plugin }: { plugin: PluginInfo }) {
const agent = plugin.contributions.find((c) => c.point === "javaAgents");
function JavaAgentDetail({ plugin, cap, disabled }: { plugin: PluginInfo; cap: CapabilityInfo; disabled: boolean }) {
const agent = plugin.javaAgent;
if (!agent) return null;
const approve = async () => {
// Revoking and granting again recomputes the jar's hash in the host.
if (await setPluginCapability(plugin.id, cap.id, false)) {
await setPluginCapability(plugin.id, cap.id, true);
}
};
return (
<div className={styles.programPermission}>
<span className={clsx(styles.mono, styles.programPath)} aria-label={tx("Java agent")}>
{agent.label}
{agent.fileName}
{agent.args ? `=${agent.args}` : ""}
</span>
{cap.granted && !agent.approved && (
<div className={styles.error} role="alert">
<p>
<T>The agent jar changed since you approved it. Approve the new jar before the next launch.</T>
</p>
<Button size="small" variant="primary" disabled={disabled} onClick={() => void approve()}>
<T>Approve new jar</T>
</Button>
</div>
)}
</div>
);
}
@@ -69,6 +69,7 @@ function plugin(partial: Partial<PluginInfo> & Pick<PluginInfo, "id">): PluginIn
homepage: null,
changeNotes: null,
icon: null,
javaAgent: null,
source: "installed",
path: `/plugins/${partial.id}`,
enabled: true,
@@ -1604,6 +1605,7 @@ describe("marketplace", () => {
},
],
contributions: [{ point: "javaAgents", label: "spring-agent.jar=port=0" }],
javaAgent: { fileName: "spring-agent.jar", args: "port=0", approved: true },
}),
]),
);
@@ -1613,6 +1615,47 @@ describe("marketplace", () => {
expect(within(permissions).getByLabelText("Java agent")).toHaveTextContent("spring-agent.jar=port=0");
});
it("warns when a granted Java agent jar changed and can approve it again", async () => {
const user = userEvent.setup();
const base = createMemoryPluginsBackend([
plugin({
id: "spring",
name: "Spring",
hasCode: false,
status: "static",
javaAgent: { fileName: "spring-agent.jar", args: null, approved: false },
capabilities: [
{
id: "java.agent",
risk: "high",
description: "Run code inside the Java applications you start",
optional: true,
granted: true,
},
],
contributions: [{ point: "javaAgents", label: "spring-agent.jar" }],
}),
]);
const calls: [string, string, boolean][] = [];
setPluginsBackend({
...base,
setCapability: async (id, capability, granted) => {
calls.push([id, capability, granted]);
return base.setCapability(id, capability, granted);
},
});
render(<PluginsPage initialTab="installed" />);
const permissions = await screen.findByRole("list", { name: "Permissions" });
expect(within(permissions).getByRole("alert")).toHaveTextContent("The agent jar changed since you approved it");
await user.click(within(permissions).getByRole("button", { name: "Approve new jar" }));
await waitFor(() =>
expect(calls).toEqual([
["spring", "java.agent", false],
["spring", "java.agent", true],
]),
);
});
it("offers to roll back an update", async () => {
const base = createMemoryPluginsBackend([
plugin({ id: "p", name: "P", version: "2.0.0", previousVersion: "1.0.0" }),
+1
View File
@@ -453,6 +453,7 @@ function samplePlugins(): PluginInfo[] {
homepage: null,
changeNotes: null,
icon: null,
javaAgent: null,
source: "installed" as const,
enabled: true,
error: null,
+3 -1
View File
@@ -2370,5 +2370,7 @@
"Install IDE Copy": "Install IDE Copy",
"Not installed:": "Not installed:",
"Additional servers": "Additional servers",
"Run alongside the one above": "Run alongside the one above"
"Run alongside the one above": "Run alongside the one above",
"The agent jar changed since you approved it. Approve the new jar before the next launch.": "The agent jar changed since you approved it. Approve the new jar before the next launch.",
"Approve new jar": "Approve new jar"
}
+3 -1
View File
@@ -8748,5 +8748,7 @@
"Install IDE Copy": "安装到 IDE",
"Not installed:": "未安装:",
"Additional servers": "附加服务器",
"Run alongside the one above": "与上面选中的服务器同时运行"
"Run alongside the one above": "与上面选中的服务器同时运行",
"The agent jar changed since you approved it. Approve the new jar before the next launch.": "Agent jar 在授权后发生了变化。请先批准新的 jar,再启动应用。",
"Approve new jar": "批准新的 jar"
}