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.
This commit is contained in:
Ali Josie 2023-01-30 14:02:10 +01:00 committed by GitHub
parent b2d4185eec
commit 8e7df33dd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {