Authorization Bypass Through User-Controlled Key in emicklei/go-restful


Reported on

Mar 7th 2022


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

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

However, although there's is already another param called allowedOriginPatterns used for matching origin using regular expression, all domains in AllowedDomains is also used as regular expression to check for matching origin in this code in file cors_filter.go:

if len(c.allowedOriginPatterns) == 0 {
            // compile allowed domains to allowed origin patterns
            allowedOriginRegexps, err := compileRegexps(c.AllowedDomains)
            if err != nil {
                return false
            c.allowedOriginPatterns = allowedOriginRegexps

        for _, pattern := range c.allowedOriginPatterns {
            if allowed = pattern.MatchString(origin); allowed {

So by this, if the user input to be one of domain in AllowedDomains, all domains starting with would be acceptable.

Proof of Concept

  1. Install go restful and create a file main.go with this content:
package main

import (
    restful ""

func main() {
    container := restful.NewContainer()

    ws := new(restful.WebService)
    server := &http.Server{Addr: ":8000", Handler: container}

    cors := restful.CrossOriginResourceSharing{
        ExposeHeaders: []string{"X-My-Header"},
        AllowedDomains: []string{""},
        CookiesAllowed: true,
        Container: container,

func hello(req *restful.Request, resp *restful.Response) {
    io.WriteString(resp, "world")

In the above code, is configured as an allowed domain.

  1. Run the above code and access link /hello with Origin Header = and see that the request gets through CORS policy and response looks like this:
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: X-My-Header
Date: Mon, 07 Mar 2022 13:31:08 GMT
Content-Length: 5
Content-Type: text/plain; charset=utf-8
Connection: close



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

We are processing your report and will contact the emicklei/go-restful team within 24 hours. 2 years ago
We created a GitHub Issue asking the maintainers to create a 2 years ago
Jamie Slome
2 years ago

As requested by the maintainer, a GitHub Issue has been created with the details of the report:

ComradeKtg submitted a
2 years ago
Jamie Slome
2 years ago

Current status of the report can be tracked via this PR.

Jamie Slome validated this vulnerability 2 years ago
ktg9 has been awarded the disclosure bounty
The fix bounty is now up for grabs
The researcher's credibility has increased: +7
Jamie Slome marked this as fixed in v3.8.0 with commit fd3c32 2 years ago
The fix bounty has been dropped
cors_filter.go#L135 has been validated
Jamie Slome
2 years ago

In accordance with the full disclosure of the issue and validation from the maintainer here - this report has been marked as valid and fixed in v3.8.0 as stated by the maintainer here.

Great work to all involved! 👍

to join this conversation