Authorization Bypass Through User-Controlled Key Affecting github.com/zeromicro/go-zero/rest/internal/cors package, versions <1.5.1


Severity

Recommended
0.0
critical
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of concept
EPSS
0.04% (11th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-GOLANG-GITHUBCOMZEROMICROGOZERORESTINTERNALCORS-6371516
  • published5 Mar 2024
  • disclosed4 Mar 2024
  • creditcokeBeer

Introduced: 4 Mar 2024

CVE-2024-27302  (opens in a new tab)
CWE-639  (opens in a new tab)

How to fix?

Upgrade github.com/zeromicro/go-zero/rest/internal/cors to version 1.5.1 or higher.

Overview

Affected versions of this package are vulnerable to Authorization Bypass Through User-Controlled Key due to the improper input validation in the CORS Filter feature. An attacker can bypass CORS policy and make requests to retrieve data on behalf of other users by using a domain that has a suffix matching an allowed domain in the CORS policy.

PoC

package main

import (
    "errors"
    "net/http"

    "github.com/zeromicro/go-zero/rest"
)

func main() {
    svr := rest.MustNewServer(rest.RestConf{Port: 8888}, rest.WithRouter(mockedRouter{}), rest.WithCors("safe.com"))
    svr.Start()
}

type mockedRouter struct{}

// some sensitive path
func (m mockedRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    // check user's cookie
    // ...
    // return sensitive data
    w.Write([]byte("social_id: 420101198008292930"))
}

func (m mockedRouter) Handle(_, _ string, handler http.Handler) error {
    return errors.New("foo")
}

func (m mockedRouter) SetNotFoundHandler(_ http.Handler) {
}

func (m mockedRouter) SetNotAllowedHandler(_ http.Handler) {
}

References

CVSS Scores

version 3.1