File tree Expand file tree Collapse file tree 4 files changed +27
-6
lines changed
Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 11import type { NextRequest } from 'next/server'
22import { NextResponse } from 'next/server'
33import { checkHybridAuth } from '@/lib/auth/hybrid'
4+ import { validateAlphanumericId } from '@/lib/core/security/input-validation'
45import { getBaseUrl } from '@/lib/core/utils/urls'
56import { createLogger } from '@/lib/logs/console/logger'
67import { StorageService } from '@/lib/uploads'
@@ -147,6 +148,10 @@ export async function POST(request: NextRequest) {
147148 { status : 400 }
148149 )
149150 }
151+ const voiceIdValidation = validateAlphanumericId ( body . voiceId , 'voiceId' )
152+ if ( ! voiceIdValidation . isValid ) {
153+ return NextResponse . json ( { error : voiceIdValidation . error } , { status : 400 } )
154+ }
150155 const result = await synthesizeWithElevenLabs ( {
151156 text,
152157 apiKey,
Original file line number Diff line number Diff line change 11import { type NextRequest , NextResponse } from 'next/server'
22import { z } from 'zod'
33import { checkHybridAuth } from '@/lib/auth/hybrid'
4+ import { validateNumericId } from '@/lib/core/security/input-validation'
45import { generateRequestId } from '@/lib/core/utils/request'
56import { createLogger } from '@/lib/logs/console/logger'
67import { processFilesToUserFiles } from '@/lib/uploads/utils/file-utils'
@@ -41,6 +42,17 @@ export async function POST(request: NextRequest) {
4142 const body = await request . json ( )
4243 const validatedData = DiscordSendMessageSchema . parse ( body )
4344
45+ const channelIdValidation = validateNumericId ( validatedData . channelId , 'channelId' )
46+ if ( ! channelIdValidation . isValid ) {
47+ logger . warn ( `[${ requestId } ] Invalid channelId format` , {
48+ error : channelIdValidation . error ,
49+ } )
50+ return NextResponse . json (
51+ { success : false , error : channelIdValidation . error } ,
52+ { status : 400 }
53+ )
54+ }
55+
4456 logger . info ( `[${ requestId } ] Sending Discord message` , {
4557 channelId : validatedData . channelId ,
4658 hasFiles : ! ! ( validatedData . files && validatedData . files . length > 0 ) ,
Original file line number Diff line number Diff line change 11import { NextResponse } from 'next/server'
22import { authorizeCredentialUse } from '@/lib/auth/credential-access'
3+ import { validateAlphanumericId } from '@/lib/core/security/input-validation'
34import { generateRequestId } from '@/lib/core/utils/request'
45import { createLogger } from '@/lib/logs/console/logger'
56import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
@@ -19,9 +20,10 @@ export async function POST(request: Request) {
1920 return NextResponse . json ( { error : 'Credential is required' } , { status : 400 } )
2021 }
2122
22- if ( ! siteId ) {
23- logger . error ( 'Missing siteId in request' )
24- return NextResponse . json ( { error : 'Site ID is required' } , { status : 400 } )
23+ const siteIdValidation = validateAlphanumericId ( siteId , 'siteId' )
24+ if ( ! siteIdValidation . isValid ) {
25+ logger . error ( 'Invalid siteId' , { error : siteIdValidation . error } )
26+ return NextResponse . json ( { error : siteIdValidation . error } , { status : 400 } )
2527 }
2628
2729 const authz = await authorizeCredentialUse ( request as any , {
Original file line number Diff line number Diff line change 11import { NextResponse } from 'next/server'
22import { authorizeCredentialUse } from '@/lib/auth/credential-access'
3+ import { validateAlphanumericId } from '@/lib/core/security/input-validation'
34import { generateRequestId } from '@/lib/core/utils/request'
45import { createLogger } from '@/lib/logs/console/logger'
56import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
@@ -19,9 +20,10 @@ export async function POST(request: Request) {
1920 return NextResponse . json ( { error : 'Credential is required' } , { status : 400 } )
2021 }
2122
22- if ( ! collectionId ) {
23- logger . error ( 'Missing collectionId in request' )
24- return NextResponse . json ( { error : 'Collection ID is required' } , { status : 400 } )
23+ const collectionIdValidation = validateAlphanumericId ( collectionId , 'collectionId' )
24+ if ( ! collectionIdValidation . isValid ) {
25+ logger . error ( 'Invalid collectionId' , { error : collectionIdValidation . error } )
26+ return NextResponse . json ( { error : collectionIdValidation . error } , { status : 400 } )
2527 }
2628
2729 const authz = await authorizeCredentialUse ( request as any , {
You can’t perform that action at this time.
0 commit comments