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!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
fix(api): prevent setting or removing password on locked resumes (#3625)
Hoàng Anh Tuấn8da9d9da475d
diff --git a/docs/spec.json b/docs/spec.jsonindex d134f691d..77114c625 100644--- a/docs/spec.json+++ b/docs/spec.json@@ -1,7 +1,7 @@{"info": {"title": "Reactive Resume",- "version": "6.0.2",+ "version": "6.0.3","description": "Reactive Resume API. Mutations do not support Idempotency-Key. Do not automatically retry POST, PUT, PATCH or DELETE requests after a timeout: first read the resource to determine whether the operation succeeded. Existing enum values and response shapes are retained for compatibility.","license": {"name": "MIT",@@ -53765,6 +53765,21 @@"isLocked": {"type": "boolean"},+ "isPublic": {+ "type": "boolean",+ "description": "Whether a resume's public link is on; always false for letters."+ },+ "slug": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "description": "A resume's public address, /{username}/{slug}; null for letters."+ },"trashedAt": {"anyOf": [{@@ -53822,6 +53837,8 @@"name","tags","isLocked",+ "isPublic",+ "slug","trashedAt","createdAt","updatedAt",@@ -54804,6 +54821,10 @@"type": "boolean","description": "Whether email-based authentication is disabled on this instance."},+ "allowGuestLogin": {+ "type": "boolean",+ "description": "Whether visitors can continue as a guest on this instance."+ },"smtpEnabled": {"type": "boolean","description": "Whether outbound email (SMTP) is configured on this instance."@@ -54816,6 +54837,7 @@"required": ["disableSignups","disableEmailAuth",+ "allowGuestLogin","smtpEnabled","careerSchedulingEnabled"]@@ -74401,7 +74423,7 @@"put": {"operationId": "setResumePassword","summary": "Set resume password",- "description": "Sets or updates a password on a resume. When a password is set, viewers of the public resume must enter the password before the resume data is revealed. The password must be between 6 and 64 characters. Requires authentication.",+ "description": "Sets or updates a password on a resume. When a password is set, viewers of the public resume must enter the password before the resume data is revealed. The password must be between 6 and 64 characters. Locked resumes can't be changed; unlock the resume first. Requires authentication.","tags": ["Resume Sharing"],@@ -74440,6 +74462,66 @@"200": {"description": "The resume password was set successfully."},+ "403": {+ "description": "403",+ "content": {+ "application/json": {+ "schema": {+ "oneOf": [+ {+ "type": "object",+ "properties": {+ "defined": {+ "const": true+ },+ "code": {+ "const": "RESUME_LOCKED"+ },+ "status": {+ "const": 403+ },+ "message": {+ "type": "string",+ "default": "Unlock the resume first."+ },+ "data": {}+ },+ "required": [+ "defined",+ "code",+ "status",+ "message"+ ]+ },+ {+ "type": "object",+ "properties": {+ "defined": {+ "const": false+ },+ "code": {+ "type": "string"+ },+ "status": {+ "type": "number"+ },+ "message": {+ "type": "string"+ },+ "data": {}+ },+ "required": [+ "defined",+ "code",+ "status",+ "message"+ ]+ }+ ]+ }+ }+ }+ },"default": {"description": "Structured API error. See status and code; do not branch on message text.","content": {@@ -74494,7 +74576,7 @@"delete": {"operationId": "removeResumePassword","summary": "Remove resume password",- "description": "Removes password protection from a resume. After removal, the resume (if public) can be viewed without entering a password. Requires authentication.",+ "description": "Removes password protection from a resume. After removal, the resume (if public) can be viewed without entering a password. Locked resumes can't be changed; unlock the resume first. Requires authentication.","tags": ["Resume Sharing"],@@ -74513,6 +74595,66 @@"200": {"description": "The resume password was removed successfully."},+ "403": {+ "description": "403",+ "content": {+ "application/json": {+ "schema": {+ "oneOf": [+ {+ "type": "object",+ "properties": {+ "defined": {+ "const": true+ },+ "code": {+ "const": "RESUME_LOCKED"+ },+ "status": {+ "const": 403+ },+ "message": {+ "type": "string",+ "default": "Unlock the resume first."+ },+ "data": {}+ },+ "required": [+ "defined",+ "code",+ "status",+ "message"+ ]+ },+ {+ "type": "object",+ "properties": {+ "defined": {+ "const": false+ },+ "code": {+ "type": "string"+ },+ "status": {+ "type": "number"+ },+ "message": {+ "type": "string"+ },+ "data": {}+ },+ "required": [+ "defined",+ "code",+ "status",+ "message"+ ]+ }+ ]+ }+ }+ }+ },"default": {"description": "Structured API error. See status and code; do not branch on message text.","content": {diff --git a/packages/api/src/features/resume/service.test.ts b/packages/api/src/features/resume/service.test.tsindex 67a303015..763684bf7 100644--- a/packages/api/src/features/resume/service.test.ts+++ b/packages/api/src/features/resume/service.test.ts@@ -7,6 +7,7 @@ import { defaultResumeData } from "@reactive-resume/schema/resume/default";const dbMock = vi.hoisted(() => ({select: vi.fn(),transaction: vi.fn(),+ update: vi.fn(),}));const compareMock = vi.hoisted(() => vi.fn());const publishResumeUpdatedMock = vi.hoisted(() => vi.fn());@@ -66,7 +67,7 @@ vi.mock("drizzle-orm", () => ({join: (values: unknown[]) => values,}),}));-vi.mock("bcryptjs", () => ({ hash: vi.fn(), compare: compareMock }));+vi.mock("bcryptjs", () => ({ hash: vi.fn(async () => "hashed-password"), compare: compareMock }));vi.mock("./events", () => ({ publishResumeUpdated: publishResumeUpdatedMock }));vi.mock("./access", () => ({grantResumeAccess: grantResumeAccessMock,@@ -173,6 +174,7 @@ const createRestoreHarness = (currentData: ResumeData, restoredData: ResumeData)beforeEach(() => {dbMock.select.mockReset();dbMock.transaction.mockReset();+ dbMock.update.mockReset();compareMock.mockReset();publishResumeUpdatedMock.mockReset();grantResumeAccessMock.mockReset();@@ -385,6 +387,34 @@ describe("delete", () => {});});+describe.each([+ {+ name: "setPassword",+ run: () => resumeService.setPassword({ id: "r1", userId: "u1", password: "newPassword123" }),+ written: "hashed-password",+ },+ { name: "removePassword", run: () => resumeService.removePassword({ id: "r1", userId: "u1" }), written: null },+])("$name", ({ run, written }) => {+ it("writes the password when the resume is unlocked", async () => {+ const update = createUpdateChain([{ id: "r1", updatedAt: new Date() }]);+ dbMock.update.mockReturnValueOnce(update.chain);++ await expect(run()).resolves.toBeUndefined();+ expect(update.set).toHaveBeenCalledWith({ password: written });+ expect(update.where).toHaveBeenCalledWith(expect.arrayContaining([["is_locked", false]]));+ });++ it.each([+ { code: "RESUME_LOCKED", rows: [{ id: "r1" }] },+ { code: "NOT_FOUND", rows: [] },+ ])("throws $code when no unlocked row matches", async ({ code, rows }) => {+ dbMock.update.mockReturnValueOnce(createUpdateChain([]).chain);+ dbMock.select.mockReturnValueOnce(createSelectChain(rows));++ await expect(run()).rejects.toMatchObject({ code });+ });+});+describe("getBySlug", () => {it.each(["u1", "other-user"])("password gate exempts only the owner (%s)", async (currentUserId) => {dbMock.select.mockReturnValueOnce(diff --git a/packages/api/src/features/resume/service.ts b/packages/api/src/features/resume/service.tsindex 4b6d6ae85..23370b230 100644--- a/packages/api/src/features/resume/service.ts+++ b/packages/api/src/features/resume/service.ts@@ -355,6 +355,29 @@ async function notifyResumeUpdated(event: ResumeUpdatedEvent) {}}+// One conditional UPDATE skips locked rows atomically; only a miss pays for the read that says why.+async function updateResumePassword(input: { id: string; userId: string; password: string | null }) {+ const owned = and(eq(schema.resume.id, input.id), eq(schema.resume.userId, input.userId));+ const [resume] = await db+ .update(schema.resume)+ .set({ password: input.password })+ .where(and(owned, eq(schema.resume.isLocked, false)))+ .returning({ id: schema.resume.id, updatedAt: schema.resume.updatedAt });++ if (!resume) {+ const [existing] = await db.select({ id: schema.resume.id }).from(schema.resume).where(owned);+ throw existing ? new ORPCError("RESUME_LOCKED", { status: 403 }) : new ORPCError("NOT_FOUND");+ }++ await notifyResumeUpdated({+ type: "resume.updated",+ resumeId: resume.id,+ userId: input.userId,+ updatedAt: resume.updatedAt.toISOString(),+ mutation: "password",+ });+}+export const resumeService = {tags,statistics,@@ -752,25 +775,8 @@ export const resumeService = {});},- setPassword: async (input: { id: string; userId: string; password: string }) => {- const hashedPassword = await hash(input.password, 10);-- const [resume] = await db- .update(schema.resume)- .set({ password: hashedPassword })- .where(and(eq(schema.resume.id, input.id), eq(schema.resume.userId, input.userId)))- .returning({ id: schema.resume.id, updatedAt: schema.resume.updatedAt });-- if (!resume) throw new ORPCError("NOT_FOUND");-- await notifyResumeUpdated({- type: "resume.updated",- resumeId: resume.id,- userId: input.userId,- updatedAt: resume.updatedAt.toISOString(),- mutation: "password",- });- },+ setPassword: async (input: { id: string; userId: string; password: string }) =>+ updateResumePassword({ ...input, password: await hash(input.password, 10) }),verifyPassword: async (input: { slug: string; username: string; password: string; responseHeaders?: Headers }) => {const [resume] = await db@@ -800,23 +806,7 @@ export const resumeService = {return true;},- removePassword: async (input: { id: string; userId: string }) => {- const [resume] = await db- .update(schema.resume)- .set({ password: null })- .where(and(eq(schema.resume.id, input.id), eq(schema.resume.userId, input.userId)))- .returning({ id: schema.resume.id, updatedAt: schema.resume.updatedAt });-- if (!resume) throw new ORPCError("NOT_FOUND");-- await notifyResumeUpdated({- type: "resume.updated",- resumeId: resume.id,- userId: input.userId,- updatedAt: resume.updatedAt.toISOString(),- mutation: "password",- });- },+ removePassword: (input: { id: string; userId: string }) => updateResumePassword({ ...input, password: null }),delete: async (input: { id: string; userId: string }) => {await db.transaction(async (tx) => {diff --git a/packages/api/src/features/resume/sharing.ts b/packages/api/src/features/resume/sharing.tsindex 8e8db6cf3..d34506661 100644--- a/packages/api/src/features/resume/sharing.ts+++ b/packages/api/src/features/resume/sharing.ts@@ -52,12 +52,13 @@ export const sharingRouter = {operationId: "setResumePassword",summary: "Set resume password",description:- "Sets or updates a password on a resume. When a password is set, viewers of the public resume must enter the password before the resume data is revealed. The password must be between 6 and 64 characters. Requires authentication.",+ "Sets or updates a password on a resume. When a password is set, viewers of the public resume must enter the password before the resume data is revealed. The password must be between 6 and 64 characters. Locked resumes can't be changed; unlock the resume first. Requires authentication.",successDescription: "The resume password was set successfully.",}).input(resumeDto.setPassword.input).use(resumeMutationRateLimit).output(resumeDto.setPassword.output)+ .errors({ RESUME_LOCKED: { status: 403, message: "Unlock the resume first." } }).handler(({ context, input }) =>resumeService.setPassword({id: input.id,@@ -103,12 +104,13 @@ export const sharingRouter = {operationId: "removeResumePassword",summary: "Remove resume password",description:- "Removes password protection from a resume. After removal, the resume (if public) can be viewed without entering a password. Requires authentication.",+ "Removes password protection from a resume. After removal, the resume (if public) can be viewed without entering a password. Locked resumes can't be changed; unlock the resume first. Requires authentication.",successDescription: "The resume password was removed successfully.",}).input(resumeDto.removePassword.input).use(resumeMutationRateLimit).output(resumeDto.removePassword.output)+ .errors({ RESUME_LOCKED: { status: 403, message: "Unlock the resume first." } }).handler(({ context, input }) =>resumeService.removePassword({id: input.id,