Skip to content
Closed
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
4 changes: 0 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ SUPABASE_SERVICE_ROLE_KEY=eyJ...
# Google AI
GOOGLE_GENERATIVE_AI_API_KEY=AIza...

# Assistant UI
NEXT_PUBLIC_ASSISTANT_BASE_URL=https://...
ASSISTANT_API_KEY=sk_aui_...

# Firecrawl Web Scraping (Optional)
# Get your API key from firecrawl.dev
FIRECRAWL_API_KEY=fc_...
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# dependencies
/node_modules
.pnpm-store
/.pnp
.pnp.*
.yarn/*
Expand All @@ -22,6 +23,7 @@

# misc
.DS_Store
assistant-ui-main/
*.pem

# debug
Expand Down
35 changes: 35 additions & 0 deletions drizzle/0002_deep_shadowcat.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
CREATE TABLE "chat_messages" (

@cubic-dev-ai cubic-dev-ai Bot Feb 24, 2026

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.

P1: Security: chat_messages table is missing Row Level Security. Every other user-data table in this project has RLS enabled, but chat_messages (which stores sensitive conversation content) does not. Without RLS, any authenticated user can directly read/write messages in any thread, bypassing the chat_threads RLS policy. Add ALTER TABLE "chat_messages" ENABLE ROW LEVEL SECURITY and a corresponding policy that restricts access to messages whose thread belongs to an authorized workspace.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At drizzle/0002_deep_shadowcat.sql, line 8:

<comment>Security: `chat_messages` table is missing Row Level Security. Every other user-data table in this project has RLS enabled, but `chat_messages` (which stores sensitive conversation content) does not. Without RLS, any authenticated user can directly read/write messages in any thread, bypassing the `chat_threads` RLS policy. Add `ALTER TABLE "chat_messages" ENABLE ROW LEVEL SECURITY` and a corresponding policy that restricts access to messages whose thread belongs to an authorized workspace.</comment>

<file context>
@@ -0,0 +1,35 @@
+	"parent_id" text,
+	"format" text NOT NULL,
+	"content" jsonb NOT NULL,
+	"created_at" timestamp with time zone DEFAULT now()
+);
+--> statement-breakpoint
</file context>
Fix with Cubic

"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"thread_id" uuid NOT NULL,
"message_id" text NOT NULL,
"parent_id" text,
"format" text NOT NULL,
"content" jsonb NOT NULL,
"created_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "chat_threads" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"workspace_id" uuid NOT NULL,
"user_id" text NOT NULL,
"title" text,
"is_archived" boolean DEFAULT false,
"external_id" text,
"created_at" timestamp with time zone DEFAULT now(),
"updated_at" timestamp with time zone DEFAULT now(),
"last_message_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
ALTER TABLE "chat_threads" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
ALTER TABLE "chat_messages" ADD CONSTRAINT "chat_messages_thread_id_chat_threads_id_fk" FOREIGN KEY ("thread_id") REFERENCES "public"."chat_threads"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_threads" ADD CONSTRAINT "chat_threads_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "chat_threads" ADD CONSTRAINT "chat_threads_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_chat_messages_thread" ON "chat_messages" USING btree ("thread_id" uuid_ops);--> statement-breakpoint
CREATE INDEX "idx_chat_messages_thread_created" ON "chat_messages" USING btree ("thread_id" uuid_ops,"created_at" timestamptz_ops);--> statement-breakpoint
CREATE INDEX "idx_chat_threads_workspace" ON "chat_threads" USING btree ("workspace_id" uuid_ops);--> statement-breakpoint
CREATE INDEX "idx_chat_threads_user" ON "chat_threads" USING btree ("user_id" text_ops);--> statement-breakpoint
CREATE INDEX "idx_chat_threads_last_message" ON "chat_threads" USING btree ("workspace_id" uuid_ops,"last_message_at" timestamptz_ops);--> statement-breakpoint
CREATE POLICY "Users can manage threads in their workspaces" ON "chat_threads" AS PERMISSIVE FOR ALL TO "authenticated" USING ((EXISTS ( SELECT 1 FROM workspaces w
WHERE ((w.id = chat_threads.workspace_id) AND (w.user_id = (auth.jwt() ->> 'sub'::text)))))
OR (EXISTS ( SELECT 1 FROM workspace_collaborators c
WHERE ((c.workspace_id = chat_threads.workspace_id) AND (c.user_id = (auth.jwt() ->> 'sub'::text))))));
Loading