@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from 'next/server';
22import { getRun , start } from 'workflow/api' ;
33
44import { createApiErrorResponse } from '../../../lib/api-error' ;
5+ import { isJsonBodyTooLarge , readBoundedJson } from '../../../lib/bounded-json' ;
56import { parseGitHubUrl } from '../../../lib/analyzer' ;
67import { isPublicArtifactCacheConfigured } from '../../../lib/analyzer/v2/artifact-cache' ;
78import { auth } from '../../../lib/auth' ;
@@ -13,6 +14,11 @@ import {
1314
1415export const dynamic = 'force-dynamic' ;
1516
17+ const NO_STORE_HEADERS = {
18+ 'Cache-Control' : 'no-store, private, max-age=0' ,
19+ 'X-Content-Type-Options' : 'nosniff' ,
20+ } ;
21+
1622async function resolveCommitSha ( owner : string , name : string ) : Promise < string | null > {
1723 try {
1824 const response = await fetch ( `https://api.github.com/repos/${ owner } /${ name } /commits/HEAD` , {
@@ -103,8 +109,11 @@ export async function POST(request: NextRequest) {
103109
104110 let bodyUrl : unknown ;
105111 try {
106- bodyUrl = ( ( await request . json ( ) ) as { url ?: unknown } ) ?. url ;
107- } catch {
112+ bodyUrl = ( await readBoundedJson < { url ?: unknown } > ( request ) ) ?. url ;
113+ } catch ( error ) {
114+ if ( isJsonBodyTooLarge ( error ) ) {
115+ return createApiErrorResponse ( 'PAYLOAD_TOO_LARGE' , 'Request body exceeds the 16 KB limit.' , 413 ) ;
116+ }
108117 return createApiErrorResponse ( 'INVALID_REQUEST' , 'Body must be JSON with a "url" field.' , 400 ) ;
109118 }
110119 if ( typeof bodyUrl !== 'string' || ! bodyUrl . trim ( ) ) {
@@ -157,7 +166,7 @@ export async function POST(request: NextRequest) {
157166 commitSha,
158167 ...runEndpoints ( run . runId ) ,
159168 } ,
160- { status : 202 }
169+ { status : 202 , headers : NO_STORE_HEADERS }
161170 ) ;
162171 } catch ( error ) {
163172 console . error ( '[RepoDNA:WorkflowStartFailed]' , error ) ;
@@ -178,7 +187,7 @@ export async function GET(request: NextRequest) {
178187 try {
179188 const status = await runStatus ( runId ) ;
180189 return status
181- ? NextResponse . json ( status )
190+ ? NextResponse . json ( status , { headers : NO_STORE_HEADERS } )
182191 : createApiErrorResponse ( 'RUN_NOT_FOUND' , 'Unknown or expired analysis run.' , 404 ) ;
183192 } catch {
184193 return createApiErrorResponse ( 'RUN_NOT_FOUND' , 'Unknown or expired analysis run.' , 404 ) ;
0 commit comments