From 4ee83d2958525a2c9fc9f2dcc2611b1954038afc Mon Sep 17 00:00:00 2001 From: Huabing Zhao Date: Wed, 1 Nov 2023 21:47:59 +0800 Subject: [PATCH] fix: null pointer when CORS maxAge is not specified (#2133) fix nullpointer Signed-off-by: huabing zhao Signed-off-by: Huabing Zhao (cherry picked from commit 35c4feaaf82dfc81e89c28576d5477a090b50725) Signed-off-by: Arko Dasgupta --- internal/xds/translator/cors.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/xds/translator/cors.go b/internal/xds/translator/cors.go index b070b7fb54a..14ce8232dca 100644 --- a/internal/xds/translator/cors.go +++ b/internal/xds/translator/cors.go @@ -126,7 +126,9 @@ func patchRouteWithCORSConfig(route *routev3.Route, irRoute *ir.HTTPRoute) error allowMethods = strings.Join(irRoute.CORS.AllowMethods, ", ") allowHeaders = strings.Join(irRoute.CORS.AllowHeaders, ", ") exposeHeaders = strings.Join(irRoute.CORS.ExposeHeaders, ", ") - maxAge = strconv.Itoa(int(irRoute.CORS.MaxAge.Seconds())) + if irRoute.CORS.MaxAge != nil { + maxAge = strconv.Itoa(int(irRoute.CORS.MaxAge.Seconds())) + } routeCfgProto := &corsv3.CorsPolicy{ AllowOriginStringMatch: allowOrigins,