Răsfoiți Sursa

Convert context value to string securely

DarthSim 5 ani în urmă
părinte
comite
65579a5770
2 a modificat fișierele cu 6 adăugiri și 3 ștergeri
  1. 4 2
      download.go
  2. 2 1
      processing_options.go

+ 4 - 2
download.go

@@ -210,9 +210,11 @@ func getImageData(ctx context.Context) *imageData {
 }
 
 func getCacheControlHeader(ctx context.Context) string {
-	return ctx.Value(cacheControlHeaderCtxKey).(string)
+	str, _ := ctx.Value(cacheControlHeaderCtxKey).(string)
+	return str
 }
 
 func getExpiresHeader(ctx context.Context) string {
-	return ctx.Value(expiresHeaderCtxKey).(string)
+	str, _ := ctx.Value(expiresHeaderCtxKey).(string)
+	return str
 }

+ 2 - 1
processing_options.go

@@ -1046,7 +1046,8 @@ func parsePath(ctx context.Context, r *http.Request) (context.Context, error) {
 }
 
 func getImageURL(ctx context.Context) string {
-	return ctx.Value(imageURLCtxKey).(string)
+	str, _ := ctx.Value(imageURLCtxKey).(string)
+	return str
 }
 
 func getProcessingOptions(ctx context.Context) *processingOptions {