fix: use D1 database layer in API routes and fix SQL injection#12
Open
Rayhan1967 wants to merge 1 commit intoworkos:mainfrom
Open
fix: use D1 database layer in API routes and fix SQL injection#12Rayhan1967 wants to merge 1 commit intoworkos:mainfrom
Rayhan1967 wants to merge 1 commit intoworkos:mainfrom
Conversation
- Migrate all API routes from SQLite (better-sqlite3) to D1 for Cloudflare Pages compatibility - Fix SQL injection vulnerability in searchRecordingsWithContext using parameterized queries - Add missing functions to D1 layer: getSpeakersByRecordingIds, getSummariesByRecordingIds - Update page components to use async D1 functions - Add type re-exports in D1 module for TypeScript compatibility Critical fixes for Cloudflare Pages deployment: - API routes were using SQLite functions that don't work in Cloudflare Workers - SQL injection vulnerability in source parameter filtering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes two critical issues that prevent the application from working correctly on Cloudflare Pages:
1. Database Layer Mismatch (Critical)
Problem: API routes were using SQLite functions (
better-sqlite3) which don't work in Cloudflare Workers environment.Solution: Migrated all API routes and page components to use the D1 database layer (
@/lib/db/d1) instead of SQLite.Files changed:
src/app/api/recordings/[id]/route.tssrc/app/api/recordings/[id]/summary/route.tssrc/app/api/recordings/[id]/clips/route.tssrc/app/api/clips/route.tssrc/app/api/clips/[clipId]/route.tssrc/app/api/speakers/route.tssrc/app/api/participants/route.tssrc/app/api/recordings/paginated/route.tssrc/app/recordings/[id]/page.tsxsrc/app/c/[clipId]/page.tsx2. SQL Injection Vulnerability (High)
Problem: In
searchRecordingsWithContext(), thesourceparameter was being interpolated directly into the SQL query string, which is a security risk.Location:
src/lib/db/index.ts:324Before:
After:
Additional Changes
getSpeakersByRecordingIds,getSummariesByRecordingIds,dbRowToClip,dbRowToRecordingVerification