fix: update the save configuration of the cli tools

This commit is contained in:
2026-07-19 20:56:53 +07:00
parent d741708d44
commit c9d17d3586
2 changed files with 23 additions and 1 deletions
+4 -1
View File
@@ -205,8 +205,11 @@ export async function proxy(request) {
// case, can change privileged system networking. Keep them available only // case, can change privileged system networking. Keep them available only
// to authenticated dashboard users on the local machine; never allow the // to authenticated dashboard users on the local machine; never allow the
// shared CLI bearer token to become a remote host-administration credential. // shared CLI bearer token to become a remote host-administration credential.
// Configuration routes only persist dashboard-user settings in SQLite, so
// authenticated remote dashboard users may access them.
if (pathname === "/api/cli-tools" || pathname.startsWith("/api/cli-tools/")) { if (pathname === "/api/cli-tools" || pathname.startsWith("/api/cli-tools/")) {
if (!isLocalRequest(request)) { const isConfigRoute = pathname.startsWith("/api/cli-tools/config/");
if (!isLocalRequest(request) && !isConfigRoute) {
return NextResponse.json({ error: "CLI Tools are available only from the local machine" }, { status: 403 }); return NextResponse.json({ error: "CLI Tools are available only from the local machine" }, { status: 403 });
} }
if (!(await isAuthenticated(request))) { if (!(await isAuthenticated(request))) {
+19
View File
@@ -292,6 +292,25 @@ describe("dashboard guard CLI Tools access", () => {
expect(response.body.error).toBe("CLI Tools are available only from the local machine"); expect(response.body.error).toBe("CLI Tools are available only from the local machine");
}); });
it("allows authenticated remote users to access CLI tool configuration", async () => {
const response = await proxy(request("/api/cli-tools/config/claude", {
host: "router.example.com",
}, "user-token"));
expect(response).toBe(mocks.nextResponse);
});
it("rejects unauthenticated remote CLI tool configuration access", async () => {
mocks.verifyDashboardAuthToken.mockResolvedValue(false);
const response = await proxy(request("/api/cli-tools/config/claude", {
host: "router.example.com",
}));
expect(response.status).toBe(401);
expect(response.body.error).toBe("Unauthorized");
});
it("allows a local administrator to use CLI Tools", async () => { it("allows a local administrator to use CLI Tools", async () => {
mocks.getUserById.mockResolvedValue({ id: "user-1", isActive: true, role: "admin" }); mocks.getUserById.mockResolvedValue({ id: "user-1", isActive: true, role: "admin" });