@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server';
22import { requireNosqlAuth } from '@/app/api/nosql/_auth' ;
33import { validateMongoConnectionString } from '@/app/api/nosql/_mongo-safety' ;
44import { getMongoClient , releaseMongoClient } from '@/lib/nosql-client-pool' ;
5+ import { sanitizeError , validateDbName , validateCollectionName } from '@/lib/nosql-error-sanitizer' ;
56
67export async function POST ( request : Request ) {
78 const authError = await requireNosqlAuth ( request ) ;
@@ -21,6 +22,21 @@ export async function POST(request: Request) {
2122 return NextResponse . json ( { error : connectionError } , { status : 400 } ) ;
2223 }
2324
25+ const dbValidation = validateDbName ( dbName ) ;
26+ if ( ! dbValidation . valid ) {
27+ return NextResponse . json ( { error : dbValidation . error } , { status : 400 } ) ;
28+ }
29+
30+ const collValidation = validateCollectionName ( collectionName ) ;
31+ if ( ! collValidation . valid ) {
32+ return NextResponse . json ( { error : collValidation . error } , { status : 400 } ) ;
33+ }
34+
35+ const newCollValidation = validateCollectionName ( newCollectionName ) ;
36+ if ( ! newCollValidation . valid ) {
37+ return NextResponse . json ( { error : newCollValidation . error } , { status : 400 } ) ;
38+ }
39+
2440 const client = await getMongoClient ( connectionString ) ;
2541
2642 const db = client . db ( dbName ) ;
@@ -31,7 +47,7 @@ export async function POST(request: Request) {
3147 return NextResponse . json ( { success : true } ) ;
3248 } catch ( error : any ) {
3349 return NextResponse . json (
34- { error : error . message || 'Failed to rename collection' } ,
50+ { error : sanitizeError ( error ) } ,
3551 { status : 500 }
3652 ) ;
3753 }
0 commit comments