-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
Bug Description
Malformed Cookie headers can trigger a slice bounds out of range panic in fasthttp’s collectCookies function, which may crash Fiber applications when reached via logger middleware.
panic: runtime error: slice bounds out of range [10:9]
goroutine 354206 [running]:
github.com/valyala/fasthttp.(*RequestHeader).collectCookies(0xc001767018)
/go/pkg/mod/github.com/valyala/[email protected]/header.go:3162 +0x2c5
github.com/valyala/fasthttp.(*RequestHeader).VisitAll.(*RequestHeader).All.func2(...)
/go/pkg/mod/github.com/valyala/[email protected]/header.go:1210
github.com/valyala/fasthttp.(*RequestHeader).VisitAll(0xc001767018, 0xc00173d518)
/go/pkg/mod/github.com/valyala/[email protected]/header.go:1239 +0x22f
github.com/gofiber/fiber/v2.(*Ctx).Protocol(0xc0002f1508)
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:1155 +0xe6
github.com/gofiber/fiber/v2/middleware/logger.createTagMap.func2({0x1c18e68, 0xc0026d62b8}, 0xc0002f1508?, 0x40?, {0x19aef13?, 0x28?})
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/logger/tags.go:62 +0x25
github.com/gofiber/fiber/v2/middleware/logger.New.func3(0xc0002f1508)
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/logger/logger.go:143 +0x4e8
github.com/gofiber/fiber/v2.(*Ctx).Next(0xc000813e90?)
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:1039 +0x3d
github.com/gofiber/fiber/v2/middleware/logger.New.func3(0xc0002f1508)
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/logger/logger.go:119 +0x2fd
github.com/gofiber/fiber/v2.(*Ctx).Next(0xc002858480?)
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:1039 +0x3d
main.main.New.func7(0xc0002f1508)
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/requestid/requestid.go:31 +0xe5
github.com/gofiber/fiber/v2.(*Ctx).Next(0x0?)
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:1039 +0x3d
github.com/gofiber/fiber/v2/middleware/cors.New.func1(0xc0002f1508)
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/cors/cors.go:173 +0x2b2
github.com/gofiber/fiber/v2.(*App).next(0xc000172f08, 0xc0002f1508)
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:143 +0x1a7
github.com/gofiber/fiber/v2.(*App).handler(0xc000172f08, 0x4f2973?)
/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:170 +0x69
github.com/valyala/fasthttp.(*Server).serveConn(0xc00019c908, {0x1c17518, 0xc00006ed28})
/go/pkg/mod/github.com/valyala/[email protected]/server.go:2465 +0x124b
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc00002b5f0, 0xc002060400)
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:225 +0x92
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:197 +0x32
created by github.com/valyala/fasthttp.(*workerPool).getCh in goroutine 179
/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:196 +0x194How to Reproduce
Example query from GPT
curl -k https://{{DOMAIN}}/wp-config.php \
-H 'User-Agent: Python/3.10 aiohttp/3.13.2' \
-H 'Cookie: sessionid=abc123; malformedcookie; =; test=123'Expected Behavior
not crash
Fiber Version
v2.52.1
Code Snippet (optional)
package main
import "github.com/gofiber/fiber/v3"
import "log"
func main() {
app := fiber.New()
// Steps to reproduce
log.Fatal(app.Listen(":3000"))
}Checklist:
- I agree to follow Fiber's Code of Conduct.
- I have checked for existing issues that describe my problem prior to opening this one.
- I understand that improperly formatted bug reports may be closed without explanation.
coderabbitai