Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/control-plane/src/routes/keyboard-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export const keyboardShortcutRoutes = new Hono<ControlPlaneHonoEnv>();

keyboardShortcutRoutes.get(
"/keyboard-shortcuts",
admit({ ...SCM_AGNOSTIC_HUMAN_USER_ROUTE, authorization: ACTIVE_SELF }),
admit({
...SCM_AGNOSTIC_HUMAN_USER_ROUTE,
authorization: ACTIVE_SELF,
cacheControl: "private, no-store",
}),
async (c) => {
const { ctx } = c.var.admitted;
const shortcuts = await new KeyboardShortcutPreferencesStore(ctx.db).get(ctx.principal.userId);
Expand Down
1 change: 1 addition & 0 deletions packages/control-plane/src/routes/model-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ modelPreferencesRoutes.get(
admit({
...GITHUB_USER_OR_SERVICE_ROUTE,
authorization: activeGlobal({ actorlessGrants: [{ service: "slack-bot" }] }),
cacheControl: "private, no-store",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[deep review] This policy does not reach the browser-facing /api/model-preferences response. packages/web/src/app/api/model-preferences/route.ts parses the control-plane response and constructs a fresh NextResponse without forwarding Cache-Control, so the primary web caller still has no explicit private/no-store policy. The neighboring keyboard-shortcuts and skill-profile routes already expose the code-judo move here: replace the bespoke 42-line web handler with settingsProxy(() => "/model-preferences", "model preferences"). That makes the cache behavior consistent and deletes duplicated auth, body parsing, response translation, and error handling. Please cover the web route boundary as part of that change; the new control-plane-only test passes while this regression remains.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Confirmed and fixed in a74563a: /api/model-preferences is now settingsProxy(() => "/model-preferences", "model preferences"), and route.test.ts at that boundary asserts the private, no-store header on the read and the forwarded update.

}),
(c) => getModelPreferences(c.var.admitted.ctx)
);
Expand Down
7 changes: 6 additions & 1 deletion packages/control-plane/src/routes/skills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,11 @@ const PROFILES_MANAGE_OWN = admit({
...SCM_AGNOSTIC_HUMAN_USER_ROUTE,
authorization: requirePermission("skill_profiles.manage_own"),
});
const PROFILES_READ_OWN = admit({
...SCM_AGNOSTIC_HUMAN_USER_ROUTE,
authorization: requirePermission("skill_profiles.manage_own"),
cacheControl: "private, no-store",
});

export const skillRoutes = new Hono<ControlPlaneHonoEnv>();

Expand All @@ -649,7 +654,7 @@ skillRoutes.put("/skills/:id", SKILLS_MANAGE, (c) =>
dispatch(c, handleReplaceSkillContentAndAssignments)
);
skillRoutes.delete("/skills/:id", SKILLS_MANAGE, (c) => dispatch(c, handleDeleteSkill));
skillRoutes.get("/skill-profiles", PROFILES_MANAGE_OWN, (c) => dispatch(c, handleListProfiles));
skillRoutes.get("/skill-profiles", PROFILES_READ_OWN, (c) => dispatch(c, handleListProfiles));
skillRoutes.post("/skill-profiles", PROFILES_MANAGE_OWN, (c) => dispatch(c, handleCreateProfile));
skillRoutes.patch("/skill-profiles/:id", PROFILES_MANAGE_OWN, (c) =>
dispatch(c, handleUpdateProfile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ exports[`Hono route catalog conformance > dispatches every frozen method/path/po
"{"identity":"GET /image-builds/status","pathname":"/image-builds/status","groups":{},"authentication":"user-or-service","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"image_builds.read"}],"auditAllowed":false,"service":{"kind":"actor"}},"supportedScmProviders":["github"],"cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"GET /image-builds/enabled","pathname":"/image-builds/enabled","groups":{},"authentication":"user-or-service","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"image_builds.read"}],"auditAllowed":false,"service":{"kind":"actor"}},"supportedScmProviders":["github"],"cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"GET /image-builds/enabled-repos","pathname":"/image-builds/enabled-repos","groups":{},"authentication":"user-or-service","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"image_builds.read"}],"auditAllowed":false,"service":{"kind":"actor"}},"supportedScmProviders":["github"],"cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"GET /model-preferences","pathname":"/model-preferences","groups":{},"authentication":"user-or-service","authorization":{"kind":"active-global","service":{"kind":"actor","actorlessGrants":[{"service":"slack-bot"}]},"auditAllowed":false},"supportedScmProviders":["github"],"cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"GET /model-preferences","pathname":"/model-preferences","groups":{},"authentication":"user-or-service","authorization":{"kind":"active-global","service":{"kind":"actor","actorlessGrants":[{"service":"slack-bot"}]},"auditAllowed":false},"supportedScmProviders":["github"],"cacheControl":"private, no-store","hasServiceActorClaims":false}",
"{"identity":"PUT /model-preferences","pathname":"/model-preferences","groups":{},"authentication":"user-or-service","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"models.preferences.manage"}],"auditAllowed":true,"service":{"kind":"actor"}},"supportedScmProviders":["github"],"cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"GET /model-provider-accounts/legacy-credentials","pathname":"/model-provider-accounts/legacy-credentials","groups":{},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"provider_accounts.read"}],"auditAllowed":false,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":"private, no-store","hasServiceActorClaims":false}",
"{"identity":"GET /model-provider-accounts","pathname":"/model-provider-accounts","groups":{},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"provider_accounts.read"}],"auditAllowed":false,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":"private, no-store","hasServiceActorClaims":false}",
Expand Down Expand Up @@ -157,11 +157,11 @@ exports[`Hono route catalog conformance > dispatches every frozen method/path/po
"{"identity":"PATCH /skills/:id","pathname":"/skills/fixture-152-id%2Fraw","groups":{"id":"fixture-152-id%2Fraw"},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"skills.manage"}],"auditAllowed":true,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"PUT /skills/:id","pathname":"/skills/fixture-153-id%2Fraw","groups":{"id":"fixture-153-id%2Fraw"},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"skills.manage"}],"auditAllowed":true,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"DELETE /skills/:id","pathname":"/skills/fixture-154-id%2Fraw","groups":{"id":"fixture-154-id%2Fraw"},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"skills.manage"}],"auditAllowed":true,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"GET /skill-profiles","pathname":"/skill-profiles","groups":{},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"skill_profiles.manage_own"}],"auditAllowed":true,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"GET /skill-profiles","pathname":"/skill-profiles","groups":{},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"skill_profiles.manage_own"}],"auditAllowed":true,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":"private, no-store","hasServiceActorClaims":false}",
"{"identity":"POST /skill-profiles","pathname":"/skill-profiles","groups":{},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"skill_profiles.manage_own"}],"auditAllowed":true,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"PATCH /skill-profiles/:id","pathname":"/skill-profiles/fixture-157-id%2Fraw","groups":{"id":"fixture-157-id%2Fraw"},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"skill_profiles.manage_own"}],"auditAllowed":true,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"DELETE /skill-profiles/:id","pathname":"/skill-profiles/fixture-158-id%2Fraw","groups":{"id":"fixture-158-id%2Fraw"},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"skill_profiles.manage_own"}],"auditAllowed":true,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"GET /keyboard-shortcuts","pathname":"/keyboard-shortcuts","groups":{},"authentication":"user","authorization":{"kind":"active-self","auditAllowed":false},"supportedScmProviders":"all","cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"GET /keyboard-shortcuts","pathname":"/keyboard-shortcuts","groups":{},"authentication":"user","authorization":{"kind":"active-self","auditAllowed":false},"supportedScmProviders":"all","cacheControl":"private, no-store","hasServiceActorClaims":false}",
"{"identity":"PUT /keyboard-shortcuts","pathname":"/keyboard-shortcuts","groups":{},"authentication":"user","authorization":{"kind":"active-self","auditAllowed":true},"supportedScmProviders":"all","cacheControl":null,"hasServiceActorClaims":false}",
"{"identity":"GET /me/authorization","pathname":"/me/authorization","groups":{},"authentication":"user","authorization":{"kind":"authenticated","auditAllowed":false},"supportedScmProviders":"all","cacheControl":"private, no-store","hasServiceActorClaims":false}",
"{"identity":"GET /roles","pathname":"/roles","groups":{},"authentication":"user","authorization":{"kind":"active-user","allOf":[{"kind":"permission","permission":"workspace.roles.read"}],"auditAllowed":false,"service":{"kind":"actor"}},"supportedScmProviders":"all","cacheControl":"private, no-store","hasServiceActorClaims":false}",
Expand Down
43 changes: 43 additions & 0 deletions packages/web/src/app/api/model-preferences/route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { NextRequest } from "next/server";
import { controlPlaneUserFetch } from "@/lib/control-plane";
import { GET, PUT } from "./route";

vi.mock("@/lib/control-plane", () => ({ controlPlaneUserFetch: vi.fn() }));

const context = { params: Promise.resolve(undefined) };

describe("/api/model-preferences", () => {
beforeEach(() => vi.resetAllMocks());

it("relays the preferences read as a private, uncacheable response", async () => {
vi.mocked(controlPlaneUserFetch).mockResolvedValue(
Response.json({ defaultModel: "anthropic/claude-sonnet-5" })
);

const response = await GET(new NextRequest("http://localhost/api/model-preferences"), context);

expect(controlPlaneUserFetch).toHaveBeenCalledWith("/model-preferences", undefined);
expect(response.status).toBe(200);
expect(response.headers.get("Cache-Control")).toBe("private, no-store");
await expect(response.json()).resolves.toEqual({ defaultModel: "anthropic/claude-sonnet-5" });
});

it("forwards a preferences update with the browser session", async () => {
vi.mocked(controlPlaneUserFetch).mockResolvedValue(Response.json({ ok: true }));
const request = new NextRequest("http://localhost/api/model-preferences", {
method: "PUT",
headers: { Cookie: "__Secure-openinspect.session_token=session.signature" },
body: JSON.stringify({ defaultModel: "anthropic/claude-opus-5" }),
});

const response = await PUT(request, context);

expect(controlPlaneUserFetch).toHaveBeenCalledWith("/model-preferences", {
method: "PUT",
body: JSON.stringify({ defaultModel: "anthropic/claude-opus-5" }),
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
expect(response.status).toBe(200);
expect(response.headers.get("Cache-Control")).toBe("private, no-store");
});
});
43 changes: 2 additions & 41 deletions packages/web/src/app/api/model-preferences/route.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { getServerAuthSession } from "@/lib/server-auth-session";
import { controlPlaneUserFetch } from "@/lib/control-plane";
import { settingsProxy } from "@/lib/settings-proxy";

export async function GET() {
const session = await getServerAuthSession();
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

try {
const response = await controlPlaneUserFetch("/model-preferences");
const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
console.error("Failed to fetch model preferences:", error);
return NextResponse.json({ error: "Failed to fetch model preferences" }, { status: 500 });
}
}

export async function PUT(request: NextRequest) {
const session = await getServerAuthSession();
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

try {
const body = await request.json();

const response = await controlPlaneUserFetch("/model-preferences", {
method: "PUT",
body: JSON.stringify(body),
});

const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
console.error("Failed to update model preferences:", error);
return NextResponse.json({ error: "Failed to update model preferences" }, { status: 500 });
}
}
export const { GET, PUT } = settingsProxy(() => "/model-preferences", "model preferences");
Loading