Skip to content

🐛 [Bug]: EncryptCookie middleware panics the app with index out of range error #3954

@dogukanoksuz

Description

@dogukanoksuz

Bug Description

My tech stack uses NuxtJS v4 and Shadcn UI for it. It has a cookie named sidebar:state and it breaks my fiber v3 application, when i remove this cookie it resolves. I think library conflict with cookie names that has : character in it. For now i changed the cookie name but it's a temporary fix.

panic: runtime error: index out of range [1] with length 1

goroutine 74 [running]:
runtime/debug.Stack()
        /opt/homebrew/Cellar/go/1.25.3/libexec/src/runtime/debug/stack.go:26 +0x64
github.com/gofiber/fiber/v3/middleware/recover.defaultStackTraceHandler({0x140004b13f8?, 0x1044e9b08?}, {0x104fd0720, 0x1400042e2d0})
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/recover/recover.go:12 +0x24
project/internal/server.RunServer.New.func1.1()
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/recover/recover.go:31 +0x78
panic({0x104fd0720?, 0x1400042e2d0?})
        /opt/homebrew/Cellar/go/1.25.3/libexec/src/runtime/panic.go:783 +0x120
github.com/gofiber/fiber/v3/middleware/encryptcookie.New.func1.(*RequestHeader).Cookies.1(...)
        /Users/divergent/go/pkg/mod/github.com/valyala/[email protected]/header.go:1163
github.com/gofiber/fiber/v3/middleware/encryptcookie.New.func1({0x1050579a8, 0x14000179508})
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/encryptcookie/encryptcookie.go:23 +0x83c
github.com/gofiber/fiber/v3.(*DefaultCtx).Next(0x14000408ba0?)
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:235 +0x74
github.com/gofiber/fiber/v3/middleware/logger.New.func3({0x1050579a8, 0x14000179508})
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/logger/logger.go:109 +0x260
github.com/gofiber/fiber/v3.(*DefaultCtx).Next(0x140004b19c8?)
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:235 +0x74
github.com/gofiber/fiber/v3/middleware/compress.New.func3({0x1050579a8, 0x14000179508})
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/compress/compress.go:99 +0x50
github.com/gofiber/fiber/v3.(*DefaultCtx).Next(0x9?)
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:235 +0x74
project/internal/server.RunServer.New.func1({0x1050579a8?, 0x14000179508?})
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/recover/recover.go:43 +0xbc
github.com/gofiber/fiber/v3.(*App).next(0x140002e6008, 0x14000179508)
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:156 +0x1a0
github.com/gofiber/fiber/v3.(*App).requestHandler(0x140002e6008, 0x1048c19a0?)
        /Users/divergent/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:332 +0x118
github.com/valyala/fasthttp.(*Server).serveConn(0x140002b8008, {0x1050488d0, 0x14000482918})
        /Users/divergent/go/pkg/mod/github.com/valyala/[email protected]/server.go:2465 +0xe00
github.com/valyala/fasthttp.(*workerPool).workerFunc(0x1400013a480, 0x140001b9c00)
        /Users/divergent/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:225 +0x6c
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
        /Users/divergent/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:197 +0x30
created by github.com/valyala/fasthttp.(*workerPool).getCh in goroutine 1
        /Users/divergent/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:196 +0x1b8

How to Reproduce

Steps to reproduce the behavior:

  1. Enable encryptcookie middleware and add a cookie named sidebar:state
  2. Reload the application
  3. Send a request using this cookie
  4. See the app is crashing with log i provide

Expected Behavior

App should run without any error.

Fiber Version

v3.0.0-rc3

Code Snippet (optional)

app.Use(encryptcookie.New(encryptcookie.Config{
		Key: config.MustString("app.key"),
	}))

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions