Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3fae667
fixed database migration
ngoiyaeric Dec 15, 2025
b02198c
fix(db): add drizzle db export and use supabase createMessage in cale…
ngoiyaeric Dec 15, 2025
a6c6e50
chore(rebase): resolve conflicts and apply calendar/db fixes
google-labs-jules[bot] Oct 12, 2025
b5b2209
Fix linting errors, server actions config, and chat history functiona…
Dec 16, 2025
2a49291
fix(chat): Fix chat saving functionality by using direct inserts and …
ngoiyaeric Dec 17, 2025
22a330a
Move history button to left, disable auth for testing, fix chat persi…
Dec 18, 2025
6f305ea
Add missing path and share_path columns to chats table
Dec 19, 2025
c8a1447
Fix chat creation and add debug logging
Dec 21, 2025
8aaf0d0
chore: resolve merge conflicts and change history toggle icon to plant
ngoiyaeric Dec 30, 2025
6c325e9
chore: synchronize with main branch
ngoiyaeric Dec 30, 2025
76d4da4
Merge branch 'main' into refactor/collaboration-ui-integration
ngoiyaeric Dec 31, 2025
9108ced
fix: enable mock auth to bypass Supabase requirement
ngoiyaeric Jan 1, 2026
f09b65b
feat: integrate auth frontend with supabase and connect to backend
ngoiyaeric Jan 5, 2026
88bb95e
fix: prevent static pre-rendering of auth page to fix build error
ngoiyaeric Jan 5, 2026
f6d9246
temp: make changes for auth redirect and logging
ngoiyaeric Jan 5, 2026
7ad992b
auth: enforce Supabase auth, fix auth page compilation and proxy head…
ngoiyaeric Jan 5, 2026
acaa818
fix: resolve critical auth backend schema security issues
CJWTRUST Jan 6, 2026
f018d85
Fix race condition in chat and add error handling to server actions
ngoiyaeric Jan 6, 2026
f0765e6
fix: correct Supabase schema discrepancies and security issues
CJWTRUST Jan 7, 2026
db59402
fix: set proper path for new chat creation
CJWTRUST Jan 7, 2026
c79b56c
fix: guard retrieveContext against empty/undefined userInput
CJWTRUST Jan 7, 2026
caac000
Merge origin/main and resolve conflicts
ngoiyaeric Jan 12, 2026
8b53b6e
Changes before Firebase Studio auto-run
ngoiyaeric Jan 13, 2026
3ebae0c
Merge origin/main into refactor/collaboration-ui-integration
ngoiyaeric Jan 13, 2026
7c96403
fix: update Message type to match AIMessage and fix content parsing i…
ngoiyaeric Jan 13, 2026
6604b7d
Merge branch 'main' into refactor/collaboration-ui-integration
ngoiyaeric Jan 14, 2026
c8441fd
fix: syntax error in app/actions.tsx and refactor getUIStateFromAIState
ngoiyaeric Jan 14, 2026
09d35d4
Merge branch 'main' into refactor/collaboration-ui-integration
ngoiyaeric Jan 17, 2026
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
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
DATABASE_URL="postgresql://user:password@host:port/db"

# Server Actions Configuration
# Allow Server Actions in remote dev environments
SERVER_ACTIONS_ALLOWED_ORIGINS="*"

# Authentication Configuration
# Disable Supabase auth and use mock user for development/preview
AUTH_DISABLED_FOR_DEV="false"
74 changes: 74 additions & 0 deletions FIXES_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Auth Backend Schema Fixes - PR #327

## Summary of Changes

This commit addresses critical security vulnerabilities and auth backend schema issues identified in the CodeRabbit review.

## Critical Security Fixes

### 1. ✅ Deleted RLS Disable Migration
**File:** `supabase/migrations/0002_disable_rls_for_testing.sql` (DELETED)
- **Issue:** This migration disabled Row Level Security on all tables, creating a critical security vulnerability
- **Risk:** Anyone could read, modify, or delete ANY user's chats, messages, and participants
- **Fix:** Completely removed this migration file to ensure RLS remains enabled in production

### 2. ✅ Added pgcrypto Extension
**File:** `supabase/migrations/0000_init.sql`
- **Issue:** Used `gen_random_uuid()` without enabling the pgcrypto extension
- **Risk:** Migration would fail on typical Supabase setups
- **Fix:** Added `CREATE EXTENSION IF NOT EXISTS "pgcrypto";` at the start of the migration

### 3. ✅ Fixed User Lookup in Collaboration
**File:** `lib/actions/collaboration.ts`
- **Issue:** Queried non-existent `public.users` table instead of `auth.users`
- **Risk:** User invitation flow always failed
- **Fix:** Updated `inviteUserToChat()` to use `auth.admin.listUsers()` via the service client to properly look up users by email

### 4. ✅ Added Auth Check to RAG Function
**File:** `lib/actions/rag.ts`
- **Issue:** `retrieveContext()` had no authentication check
- **Risk:** Unauthorized users could access message embeddings
- **Fix:** Added authentication validation at the start of the function using `getCurrentUserIdOnServer()`

### 5. ✅ Added Environment Validation
**File:** `lib/supabase/client.ts`
- **Issue:** Service client creation didn't validate required environment variables
- **Risk:** Service client could fail silently, bypassing RLS checks
- **Fix:** Added proper validation with descriptive error messages for missing `NEXT_PUBLIC_SUPABASE_URL` or `SUPABASE_SERVICE_ROLE_KEY`

### 6. ✅ Improved INSERT Policy Security
**File:** `supabase/migrations/0002_add_insert_policy_for_chats.sql`
- **Issue:** Policy allowed any authenticated user to insert chats with any user_id
- **Risk:** Users could create chats impersonating other users
- **Fix:** Updated policy to enforce `auth.uid() = user_id`, ensuring users can only create chats where they are the owner

## Files Modified

1. `lib/actions/collaboration.ts` - Fixed user lookup to use auth.admin API
2. `lib/actions/rag.ts` - Added authentication check
3. `lib/supabase/client.ts` - Added environment variable validation
4. `supabase/migrations/0000_init.sql` - Added pgcrypto extension
5. `supabase/migrations/0002_add_insert_policy_for_chats.sql` - Improved security policy
6. `supabase/migrations/0002_disable_rls_for_testing.sql` - DELETED (critical security issue)

## Security Improvements

- ✅ RLS remains enabled on all tables
- ✅ All server actions now validate authentication
- ✅ User lookup uses proper Supabase auth APIs
- ✅ Environment variables are validated before use
- ✅ INSERT policies enforce proper ownership
- ✅ Database migrations will run successfully on standard Supabase setups

## Testing Recommendations

1. Verify RLS policies are active: Check Supabase dashboard
2. Test user invitation flow: Ensure users can be invited by email
3. Test RAG context retrieval: Verify auth check prevents unauthorized access
4. Test chat creation: Ensure users can only create chats as themselves
5. Run migrations on a test Supabase project to verify they execute without errors

## Related Issues

Addresses CodeRabbit review comments:
- https://github.com/QueueLab/QCX/pull/327#issuecomment-3714336689
Loading