Skip to content

Commit 76061b7

Browse files
committed
feat: add public notes API for publishing encrypted notes
- Add public_notes table with slug-based access - Implement CRUD endpoints for publishing/unpublishing notes - Add XSS protection with DOMPurify (blocks script, iframe, javascript: URLs) - Hide sensitive fields (id, noteId, userId) from public GET response - Add publish status fields to notes API responses - Generate cryptographically secure slugs with nanoid Security: Server-side HTML sanitization, ownership checks on all authenticated endpoints, no enumeration possible
1 parent 9835f6f commit 76061b7

File tree

10 files changed

+1845
-8
lines changed

10 files changed

+1845
-8
lines changed

drizzle/0002_mixed_bulldozer.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE TABLE "public_notes" (
2+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3+
"slug" text NOT NULL,
4+
"note_id" uuid NOT NULL,
5+
"user_id" text NOT NULL,
6+
"title" text NOT NULL,
7+
"content" text NOT NULL,
8+
"type" text DEFAULT 'note' NOT NULL,
9+
"author_name" text,
10+
"published_at" timestamp with time zone DEFAULT now() NOT NULL,
11+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
12+
CONSTRAINT "public_notes_slug_unique" UNIQUE("slug")
13+
);
14+
--> statement-breakpoint
15+
ALTER TABLE "public_notes" ADD CONSTRAINT "public_notes_note_id_notes_id_fk" FOREIGN KEY ("note_id") REFERENCES "public"."notes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
16+
ALTER TABLE "public_notes" ADD CONSTRAINT "public_notes_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
17+
CREATE INDEX "idx_public_notes_slug" ON "public_notes" USING btree ("slug");--> statement-breakpoint
18+
CREATE INDEX "idx_public_notes_note_id" ON "public_notes" USING btree ("note_id");--> statement-breakpoint
19+
CREATE INDEX "idx_public_notes_user_id" ON "public_notes" USING btree ("user_id");

0 commit comments

Comments
 (0)