@@ -26,19 +26,21 @@ import crypto from "crypto";
2626export const dynamic = "force-dynamic" ;
2727export const runtime = "nodejs" ;
2828
29- const FLAG_SECRET = process . env . FLAG_SECRET || "pbctf_default_secret_key_2026" ;
3029const FLAG_PREFIX = "pbctf" ;
3130
3231function generateFlag ( sessionId : string ) : string {
32+ if ( ! process . env . FLAG_SECRET ) {
33+ throw new Error ( "FLAG_SECRET is not configured" ) ;
34+ }
3335 const hmac = crypto
34- . createHmac ( "sha256" , FLAG_SECRET )
36+ . createHmac ( "sha256" , process . env . FLAG_SECRET )
3537 . update ( sessionId )
3638 . digest ( "hex" ) ;
3739 return `${ FLAG_PREFIX } {${ hmac . slice ( 0 , 24 ) } }` ;
3840}
3941
4042function isoIfDate ( v : any ) {
41- return v instanceof Date ? v . toISOString ( ) : v ?? null ;
43+ return v instanceof Date ? v . toISOString ( ) : ( v ?? null ) ;
4244}
4345
4446export async function GET ( request : NextRequest ) {
@@ -66,14 +68,16 @@ export async function GET(request: NextRequest) {
6668 ] ) ;
6769
6870 if ( ! user ) {
69- return NextResponse . json (
70- { message : "User not found" } ,
71- { status : 404 } ,
72- ) ;
71+ return NextResponse . json ( { message : "User not found" } , { status : 404 } ) ;
7372 }
7473
75- // Pre-compute the warm-up flag in parallel with everything else.
76- const flag = generateFlag ( uid ) ;
74+ // Pre-compute the warm-up flag in parallel with everything else. If
75+ let flag : string | null = null ;
76+ try {
77+ flag = generateFlag ( uid ) ;
78+ } catch ( flagError ) {
79+ console . error ( "bootstrap flag generation skipped:" , flagError ) ;
80+ }
7781
7882 // Phase 2: anything that depends on the user's teamCode.
7983 let team : any = null ;
@@ -254,9 +258,6 @@ export async function GET(request: NextRequest) {
254258 } ) ;
255259 } catch ( error : any ) {
256260 console . error ( "bootstrap error:" , error ) ;
257- return NextResponse . json (
258- { message : "Server error" } ,
259- { status : 500 } ,
260- ) ;
261+ return NextResponse . json ( { message : "Server error" } , { status : 500 } ) ;
261262 }
262263}
0 commit comments