-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Feature Description
Fiber's CORS middleware actively bypasses the so-called wildcard exception: if developers configure their CORS middleware to allow credentials and specify the wildcard as an allowed origin, the resulting middleware unconditionally reflects the value of the request's Origin header in the Access-Control-Allow-Origin response header.
This is insecure insofar as it exposes users to cross-origin attacks that can be mounted from any origin.
For information, a similar issue was reported to (and subsequently fixed by) other Web frameworks/libraries:
Additional Context (optional)
Steps to reproduce
- Run
mkdir wildcardcraziness && cd $_. - Save the program below to
main.go. - Run
go mod init whatever && go mod tidy. - Run
go run main.go. - Run
curl -sD - -o /dev/null -H "Origin: https://attacker.org" localhost:8081/hello.
Expected behaviour
Perhaps the following:
curl -sD - -o /dev/null \
-H "Origin: https://attacker.org" \
localhost:8081/helloHTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
-snip-Ideally, though, the resulting middleware should not be built at all, since it is dysfunctional. More about this in my latest blog post.
Actual behaviour
curl -sD - -o /dev/null \
-H "Origin: https://attacker.org" \
localhost:8081/helloHTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://attacker.org
-snip-Note the unconditional reflection of the request's Origin header value (https://attacker.org) in the Access-Control-Allow-Origin response header.
Code Snippet
package main
import (
"log"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func main() {
app := fiber.New()
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowCredentials: true,
}))
app.Get("/hello", hello)
if err := app.Listen(":8081"); err != nil {
log.Fatal(err)
}
}
func hello(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
}Checklist:
- I agree to follow Fiber's Code of Conduct.
- I have checked for existing issues that describe my suggestion prior to opening this one.
- I understand that improperly formatted feature requests may be closed without explanation.