Skip to content

Authorization Bypass Through User-Controlled Key in go-zero

Critical severity GitHub Reviewed Published Mar 2, 2024 in zeromicro/go-zero • Updated Mar 12, 2024

Package

gomod github.com/zeromicro/go-zero (Go)

Affected versions

< 1.4.4

Patched versions

1.4.4

Description

Summary

Hello go-zero maintainer team, I would like to report a security concerning your CORS Filter feature.

Details

Go-zero allows user to specify a CORS Filter with a configurable allows param - which is an array of domains allowed in CORS policy.

However, the isOriginAllowed uses strings.HasSuffix to check the origin, which leads to bypass via domain like evil-victim.com

func isOriginAllowed(allows []string, origin string) bool {
	for _, o := range allows {
		if o == allOrigins {
			return true
		}

		if strings.HasSuffix(origin, o) {
			return true
		}
	}

	return false
}

PoC

Use code below as a PoC. Only requests from safe.com should bypass the CORS Filter

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) {
}

Send a request to localhost:8888 with Origin:not-safe.com
You can see the origin reflected in response, which bypass the CORS Filter
image

Impact

This vulnerability is capable of breaking CORS policy and thus allowing any page to make requests, retrieve data on behalf of other users.

References

@kevwan kevwan published to zeromicro/go-zero Mar 2, 2024
Published to the GitHub Advisory Database Mar 4, 2024
Reviewed Mar 4, 2024
Published by the National Vulnerability Database Mar 6, 2024
Last updated Mar 12, 2024

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N

EPSS score

0.043%
(11th percentile)

Weaknesses

CVE ID

CVE-2024-27302

GHSA ID

GHSA-fgxv-gw55-r5fq

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.