Skip to content

🐛 [Bug]: MessagePack serialization broke flash messages #3437

@zhukovra

Description

@zhukovra

Bug Description

Hello, I'm trying to use flash messages implemented in c.Redirect.With() and c.Redirect.Message() and it looks like that cookie serialization violates HTTP standards.

Below is 3 curl executions, 2 of them fails with error. Chrome and other browsers shows internal errors when trying to open /redirectWithRoute and /redirectWithTo URLs.

~ % curl -v 'http://127.0.0.1:3001/redirectWithRoute'
*   Trying 127.0.0.1:3001...
* Connected to 127.0.0.1 (127.0.0.1) port 3001
> GET /redirectWithRoute HTTP/1.1
> Host: 127.0.0.1:3001
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 302 Found
< Date: Tue, 06 May 2025 10:24:13 GMT
< Content-Length: 0
< Location: /
* Nul byte in header
* Closing connection
curl: (8) Nul byte in header

~ % curl -v 'http://127.0.0.1:3001/redirectWithTo'   
*   Trying 127.0.0.1:3001...
* Connected to 127.0.0.1 (127.0.0.1) port 3001
> GET /redirectWithTo HTTP/1.1
> Host: 127.0.0.1:3001
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 302 Found
< Date: Tue, 06 May 2025 10:24:21 GMT
< Content-Length: 0
< Location: /
* Nul byte in header
* Closing connection
curl: (8) Nul byte in header

 ~ % curl -v 'http://127.0.0.1:3001/'              
*   Trying 127.0.0.1:3001...
* Connected to 127.0.0.1 (127.0.0.1) port 3001
> GET / HTTP/1.1
> Host: 127.0.0.1:3001
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 200 OK
< Date: Tue, 06 May 2025 10:24:28 GMT
< Content-Type: application/json
< Content-Length: 31
< 
* Connection #0 to host 127.0.0.1 left intact
{"Key":"","Value":"","Level":0}%  

How to Reproduce

Steps to reproduce the behavior:

  1. Run application in code snippet
  2. Open terminal and run curl commands described in description

Expected Behavior

curl: (8) Nul byte in header is not returned by curl command

Fiber Version

v3.0.0-beta.4

Code Snippet (optional)

package main

import (
	"fmt"

	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/fiber/v3/middleware/logger"
)

func main() {
	app := fiber.New(fiber.Config{
		AppName: "Go Test",
	})

	app.Use(logger.New(logger.ConfigDefault))

	app.Get("/redirectWithRoute", func(c fiber.Ctx) error {
		return c.Redirect().With("status", "Logged in successfully").Route("base")
	})
	app.Get("/redirectWithTo", func(c fiber.Ctx) error {
		return c.Redirect().With("status", "Logged in successfully").To("/")
	})

	app.Get("/", func(c fiber.Ctx) error {
		fmt.Println("messages", c.Redirect().Messages())
		// => Logged in successfully
		return c.JSON(c.Redirect().Message("status"))
	}).Name("base")

	if err := app.Listen(":3001"); err != nil {
		panic(err)
	}
}

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

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions