Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix(auth): require browser sessions for account deletion (#3595)

Hoàng Anh Tuấnf9a94eca9b5c
diff --git a/apps/server/src/openapi/generator.test.ts b/apps/server/src/openapi/generator.test.ts
index 79a9448ff..8eb8eea56 100644
--- a/apps/server/src/openapi/generator.test.ts
+++ b/apps/server/src/openapi/generator.test.ts
@@ -97,6 +97,11 @@ it("documents anonymous routes, all supported credentials, and additive PATCH ro
expect(spec.paths?.["/flags"]?.get?.security).toEqual([]);
expect(spec.paths?.["/resumes/{username}/{slug}"]?.get?.security).toEqual([]);
expect(spec.paths?.["/resumes"]?.get?.security).toEqual([{ apiKey: [] }, { bearerAuth: [] }, { cookieAuth: [] }]);
+ expect(spec.paths?.["/auth/account"]?.delete?.security).toEqual([{ cookieAuth: [] }]);
+ expect(spec.paths?.["/auth/account"]?.delete).toHaveProperty(
+ "x-codeSamples.0.source",
+ expect.stringContaining('--cookie "<session-cookie>"'),
+ );
for (const path of ["/applications/{id}", "/cover-letters/{id}"]) {
expect(spec.paths?.[path]?.put?.requestBody).toBeDefined();
expect(spec.paths?.[path]?.patch?.requestBody).toBeDefined();
diff --git a/apps/server/src/openapi/generator.ts b/apps/server/src/openapi/generator.ts
index 1310cdd22..383443fff 100644
--- a/apps/server/src/openapi/generator.ts
+++ b/apps/server/src/openapi/generator.ts
@@ -261,7 +261,14 @@ function addCurlSamples(spec: OpenAPI.Document) {
const url = `${(operation.servers ?? spec.servers)?.[0]?.url ?? ""}${path.replace(/\{(\w+)\}/g, "<$1>")}${query ? `?${query}` : ""}`;
// Double quotes work in POSIX shells, PowerShell and cmd alike.
const args = method === "get" ? [`"${url}"`] : [`--request ${method.toUpperCase()}`, `"${url}"`];
- if ((operation.security ?? spec.security)?.length) args.push(`--header "x-api-key: <api-key>"`);
+ const security = operation.security ?? spec.security;
+ if (security?.length) {
+ args.push(
+ security.some((requirement) => "apiKey" in requirement)
+ ? `--header "x-api-key: <api-key>"`
+ : `--cookie "<session-cookie>"`,
+ );
+ }
const body = operation.requestBody && !("$ref" in operation.requestBody) ? operation.requestBody.content : {};
const json = body["application/json"];
diff --git a/docs/guides/using-the-api.mdx b/docs/guides/using-the-api.mdx
index 1b2710d1e..53c9a7ddf 100644
--- a/docs/guides/using-the-api.mdx
+++ b/docs/guides/using-the-api.mdx
@@ -168,6 +168,8 @@ The API accepts three kinds of credentials:
Send one credential. When several are present, the server tries API key, bearer token, then session cookie, using the first valid credential. Cookie-authenticated requests with a foreign `Origin` or cross-site fetch metadata are rejected; explicit API keys and bearer tokens do not rely on browser cookies.
+Account deletion (`DELETE /auth/account`) requires a browser session; API keys and OAuth tokens receive `403 FORBIDDEN`. Delete your account in **Settings → Account**.
+
A private request without valid credentials gets `401` with the code `UNAUTHORIZED`. Public operations are marked with `security: []` in the OpenAPI specification. Public resumes still enforce visibility, trash status and sharing passwords, and redact private data.
REST data responses use `Cache-Control: no-store`. Uploaded profile images are public; other uploaded files require the owner's credentials, including conditional download requests. Assistant attachments are not exposed through the uploads URL. Unknown and unauthorized file URLs return `404`.
diff --git a/docs/guides/using-the-mcp-server.mdx b/docs/guides/using-the-mcp-server.mdx
index 91293c034..751568703 100644
--- a/docs/guides/using-the-mcp-server.mdx
+++ b/docs/guides/using-the-mcp-server.mdx
@@ -222,7 +222,7 @@ Additional tools use `api_` followed by the API router path in snake case. Input
| Files and exports | `api_rest_document_exports_resume`, `api_rest_document_exports_letter`, `api_rest_file_upload` | PDF, DOCX, Markdown and JSON exports; file upload/delete and supported file imports |
| Checks and AI | `api_rest_check_resume`, `api_rest_check_pdf`, `api_rest_match_resume`, `api_ai_improve` | Deterministic checks and matching; PDF/DOCX parsing, qualitative review, line rewrites, job search and posting extraction |
| Assistant | `api_agent_threads_start`, `api_agent_messages_send`, `api_agent_attachments_create` | Threads, messages, cancellation, resumable replies, proposed edit status and attachments |
-| Account and instance | `api_auth_export_data`, `api_auth_delete_account`, `api_flags_get` | Account export/deletion, enabled auth providers and platform statistics |
+| Account and instance | `api_auth_export_data`, `api_auth_delete_account`, `api_flags_get` | Account export, browser handoff for account deletion, enabled auth providers and platform statistics |
| Integrations | `api_ai_providers_list`, `api_web_access_status` | Provider list/test/delete and web connection status/test/delete; credential entry uses browser handoffs |
Resume and letter exports return authenticated REST URLs. Download with your existing credentials or open in your signed-in browser. Letter localization words are encoded in the URL. No generated file is permanently copied into storage by the export tool.
@@ -249,7 +249,7 @@ The server reads storage directly and verifies the account prefix and path segme
### Browser and streaming workflows
-`open_account_settings` opens profile, security, API keys, preferences or account settings. Provider creation/update and web credential entry return their authenticated settings page. Password changes, passkeys, two-factor authentication and provider credentials require user interaction in that browser. Browser preferences, local undo and document selection remain browser workflows; durable edits and history are available through MCP.
+`open_account_settings` opens profile, security, API keys, preferences or account settings. Provider creation/update and web credential entry return their authenticated settings page. Account deletion, password changes, passkeys, two-factor authentication and provider credentials require user interaction in that browser. Browser preferences, local undo and document selection remain browser workflows; durable edits and history are available through MCP.
MCP is stateless and accepts POST requests with JSON responses. GET/DELETE return 405; there is no standalone SSE subscription. Draft/message streams are collected up to 500,000 characters; `truncated` identifies longer responses. Read the assistant thread for persisted replies. `api_resume_updates_subscribe` returns an owned snapshot; poll its `updatedAt` for changes. `api_resume_verify_password` returns a resource cookie capability; pass it as `resourceCookie` to `api_resume_get_by_slug`. It expires server-side after ten minutes and cannot authenticate an account.
diff --git a/docs/spec.json b/docs/spec.json
index e3ae62444..100142da5 100644
--- a/docs/spec.json
+++ b/docs/spec.json
@@ -32609,7 +32609,7 @@
"delete": {
"operationId": "deleteAccount",
"summary": "Delete user account",
- "description": "Permanently deletes the authenticated user's account, including all resumes, uploaded files (profile pictures, screenshots, PDFs), and associated data. This action is irreversible. Requires authentication.",
+ "description": "Permanently deletes the authenticated user's account, including all resumes, uploaded files (profile pictures, screenshots, PDFs), and associated data. This action is irreversible. Requires a browser session; keys and OAuth tokens cannot delete accounts.",
"tags": [
"Authentication"
],
@@ -32660,12 +32660,6 @@
}
},
"security": [
- {
- "apiKey": []
- },
- {
- "bearerAuth": []
- },
{
"cookieAuth": []
}
@@ -32674,7 +32668,7 @@
{
"lang": "bash",
"label": "cURL",
- "source": "curl --request DELETE \"https://rxresu.me/api/openapi/auth/account\" --header \"x-api-key: <api-key>\" --header \"Content-Type: application/json\" --data '{}'"
+ "source": "curl --request DELETE \"https://rxresu.me/api/openapi/auth/account\" --cookie \"<session-cookie>\" --header \"Content-Type: application/json\" --data '{}'"
}
]
}
diff --git a/packages/api/src/features/auth/delete-account.test.ts b/packages/api/src/features/auth/delete-account.test.ts
new file mode 100644
index 000000000..54f627bfd
--- /dev/null
+++ b/packages/api/src/features/auth/delete-account.test.ts
@@ -0,0 +1,43 @@
+import { expect, it, vi } from "vitest";
+import { createProcedureClient } from "@orpc/server";
+
+const deleteAccount = vi.hoisted(() => vi.fn());
+vi.mock("@reactive-resume/auth/config", () => ({ auth: { api: {} } }));
+vi.mock("./service", () => ({ authService: { deleteAccount } }));
+const { authRouter } = await import("./router");
+
+it.each(["apiKey", "bearer", "session"] as const)(
+ "requires a browser session to delete an account: %s",
+ async (method) => {
+ deleteAccount.mockReset().mockResolvedValue(undefined);
+ const remove = createProcedureClient(authRouter.deleteAccount, {
+ context: {
+ locale: "en-US",
+ reqHeaders: new Headers(),
+ authentication: {
+ user: {
+ id: "owner",
+ name: "Owner",
+ email: "[email protected]",
+ emailVerified: true,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ },
+ method,
+ permissions: ["read", "write", "delete"],
+ },
+ },
+ });
+
+ if (method === "session") {
+ await expect(remove({})).resolves.toBeUndefined();
+ expect(deleteAccount).toHaveBeenCalledWith({ userId: "owner" });
+ } else {
+ await expect(remove({})).rejects.toMatchObject({
+ code: "FORBIDDEN",
+ message: "Account deletion must be performed in your browser settings.",
+ });
+ expect(deleteAccount).not.toHaveBeenCalled();
+ }
+ },
+);
diff --git a/packages/api/src/features/auth/router.ts b/packages/api/src/features/auth/router.ts
index 1824517b4..1e4886805 100644
--- a/packages/api/src/features/auth/router.ts
+++ b/packages/api/src/features/auth/router.ts
@@ -94,16 +94,21 @@ export const authRouter = {
deleteAccount: protectedProcedure
.route({
+ spec: (operation) => ({ ...operation, security: [{ cookieAuth: [] }] }),
method: "DELETE",
path: "/auth/account",
tags: ["Authentication"],
operationId: "deleteAccount",
summary: "Delete user account",
description:
- "Permanently deletes the authenticated user's account, including all resumes, uploaded files (profile pictures, screenshots, PDFs), and associated data. This action is irreversible. Requires authentication.",
+ "Permanently deletes the authenticated user's account, including all resumes, uploaded files (profile pictures, screenshots, PDFs), and associated data. This action is irreversible. Requires a browser session; keys and OAuth tokens cannot delete accounts.",
successDescription: "The user account and all associated data have been successfully deleted.",
})
.input(z.object({}).optional())
.output(z.void())
- .handler(({ context }) => authService.deleteAccount({ userId: context.user.id })),
+ .handler(async ({ context }) => {
+ if (context.authentication?.method !== "session")
+ throw new ORPCError("FORBIDDEN", { message: "Account deletion must be performed in your browser settings." });
+ await authService.deleteAccount({ userId: context.user.id });
+ }),
};
diff --git a/packages/mcp/src/parity.test.ts b/packages/mcp/src/parity.test.ts
index e495a321b..d51c901f3 100644
--- a/packages/mcp/src/parity.test.ts
+++ b/packages/mcp/src/parity.test.ts
@@ -20,6 +20,7 @@ import { registerTools } from "./tools";
let client: Client;
let server: McpServer;
const calls = {
+ auth: { deleteAccount: vi.fn() },
resume: { listVersions: vi.fn(), getById: vi.fn() },
rest: { fileUpload: vi.fn(), documentExports: { resume: vi.fn() } },
coverLetters: { draft: vi.fn() },
@@ -59,6 +60,14 @@ afterEach(async () => {
await server?.close();
});
+it("hands account deletion to browser settings without invoking the API", async () => {
+ const result = await client.callTool({ name: "api_auth_delete_account", arguments: {} });
+ expect(result.isError).not.toBe(true);
+ expect(result.structuredContent).toMatchObject({ action: "auth.deleteAccount", requiresBrowser: true });
+ expect(new URL((result.structuredContent as { url: string }).url).pathname).toBe("/dashboard/settings/account");
+ expect(calls.auth.deleteAccount).not.toHaveBeenCalled();
+});
+
it("discovers API-derived contracts and exchanges native files and dates through the SDK", async () => {
const { tools } = await client.listTools();
const cardTools = new Map(buildMcpServerCard("1.0.0").tools.map((tool) => [tool.name, tool]));
diff --git a/packages/mcp/src/parity.ts b/packages/mcp/src/parity.ts
index 181388fc2..a39cb543b 100644
--- a/packages/mcp/src/parity.ts
+++ b/packages/mcp/src/parity.ts
@@ -72,7 +72,6 @@ const PARITY_PROCEDURES = {
"agent.attachments.delete": router.agent.attachments.delete,
"auth.providers.list": router.auth.providers.list,
"auth.exportData": router.auth.exportData,
- "auth.deleteAccount": router.auth.deleteAccount,
"flags.get": router.flags.get,
"statistics.getTotals": router.statistics.getTotals,
"statistics.github.getStarCount": router.statistics.github.getStarCount,
@@ -116,6 +115,7 @@ const BROWSER_HANDOFFS = {
"webAccess.save": "ai",
"resume.getRoot": "",
"auth.createApiKey": "api-keys",
+ "auth.deleteAccount": "account",
} as const;
const handoffAnnotations = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };