From 8e7df33dd663b7b7467ba60ac14fe5e84906519e Mon Sep 17 00:00:00 2001 From: Ali Josie <33804388+0xc0d@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:02:10 +0100 Subject: [PATCH] gin.Context: check key type on calling Value when key is 0 The type of context key is part of the key used in the context.Context type. Many packages uses zero and an unexported type to inject values into context.Context. --- context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context.go b/context.go index 04742527..8b8b7425 100644 --- a/context.go +++ b/context.go @@ -1200,7 +1200,7 @@ func (c *Context) Err() error { // if no value is associated with key. Successive calls to Value with // the same key returns the same result. func (c *Context) Value(key any) any { - if key == 0 { + if _, ok := key.(int); ok && key == 0 { return c.Request } if key == ContextKey {