fix(https): defer CORS param resolution until runtime
What This PR Solves
Fixes https://github.com/firebase/firebase-functions/issues/1773.
CORS options can be backed by params such as defineList, but v2 HTTPS handlers were resolving those params while the Functions control API was analyzing source code. At that point runtime env values may not exist yet, which can trigger deploy-time warnings or failures like parsing undefined.
This PR keeps the param-backed CORS option unresolved during function definition and resolves it from the CORS middleware at request time instead. It preserves debug CORS behavior and the existing single-origin normalization.
Testing Details
- Updated v2 HTTPS unit coverage for
onRequest({ cors: defineList(...) })so function analysis can run withFUNCTIONS_CONTROL_API=truebefore the param value exists, then runtime request handling resolvesORIGINS. - Updated v2 HTTPS unit coverage for
onCall({ cors: defineList(...) })with the same deploy-time/runtime split. - Manually tested with a local
test-project/functionsapp exporting bothcorsParamOnRequestandcorsParamOnCall, each usingcors: defineList("ALLOWED_ORIGINS"). - Manual test loaded the functions while
FUNCTIONS_CONTROL_API=trueandALLOWED_ORIGINSwas unset, confirming module analysis no longer resolves/parses the param during deploy-time loading. - Manual test then set
ALLOWED_ORIGINS=["https://app.example.com","https://admin.example.com"]and verified CORS preflight behavior: allowed origins returned the matchingAccess-Control-Allow-Originheader, andhttps://evil.example.comdid not.
Thanks for doing this. I see the bug that needs to be corrected. But this only fixes the V2 API and not the V1 API. I'm going to try a different approach where we can accept a param in the common library and it resolves the param inside the callback for the express server (since that is only run during live execution it is safe there)
https://github.com/firebase/firebase-functions/pull/1903 tries a different approach. By consolidating more logic into /common we can avoid global executions of the param access code as well as removing duplicate code
Closing as #1903 has been merged.