Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[security] Authorization Bypass Through User-Controlled Key #489

Closed
JamieSlome opened this issue Mar 29, 2022 · 9 comments
Closed

[security] Authorization Bypass Through User-Controlled Key #489

JamieSlome opened this issue Mar 29, 2022 · 9 comments

Comments

@JamieSlome
Copy link

@emicklei - following on from #488 and https://huntr.dev/bounties/be837427-415c-4d8c-808b-62ce20aa84f1/, we are sharing the details of the report as requested in the SECURITY.md.

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

Reported on Mar 7th 2022

Description

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

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

Proof of Concept

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

import (
restful "github.com/emicklei/go-restful/v3"
"io"
"net/http"
)

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

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

//container.Filter(logHeaders)
cors := restful.CrossOriginResourceSharing{
    ExposeHeaders: []string{"X-My-Header"},
    AllowedDomains: []string{"example.com"},
    CookiesAllowed: true,
    Container: container,
}
container.Filter(cors.Filter)
server.ListenAndServe()

}

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

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

Run the above code and access link /hello with Origin Header = example.com.hacker.domain 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-Allow-Origin: example.com.hacker.domain
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

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

Occurrences

cors_filter.go L135

@sickcodes
Copy link

sickcodes commented Apr 11, 2022

AllowedDomains: []string{"example.com"},

If Allowed Domain is meant to be ^example.com$ this would be 0.

However, if there's no other way to deny domains then this is critical as it defeats the confidentiality (high), integrity (high), with no apparent affect to confidentiality (none) because it allows *example.com* 9.1

@sickcodes
Copy link

Given the update in the commit above does fix exact match domains, then this is

image

tompreston pushed a commit to tompreston/go-restful that referenced this issue May 9, 2022
@JamieSlome
Copy link
Author

@emicklei - can you please confirm whether you agree with the severity rating above? Plus, is there any timeline for getting this commit released?

emicklei added a commit that referenced this issue Jun 2, 2022
@emicklei
Copy link
Owner

emicklei commented Jun 4, 2022

@emicklei - can you please confirm whether you agree with the severity rating above? Plus, is there any timeline for getting this commit released?

I do not have the expertise to verify the rating. I hope to merge the PR within days.

@JamieSlome
Copy link
Author

@emicklei - no worries at all. Can you at least confirm whether you perceive this to be a vulnerability?

If you could mark it accordingly on our report, that would be appreciated, otherwise, we will do it on your behalf :)

https://huntr.dev/bounties/be837427-415c-4d8c-808b-62ce20aa84f1/

@emicklei
Copy link
Owner

emicklei commented Jun 6, 2022

I agree that this is a vulnerability ; not sure about the high impact rating.

emicklei added a commit that referenced this issue Jun 6, 2022
* use exact matching of allowed domain entries, issue #489

* update doc, add testcases from PR conversation

* introduce AllowedDomainFunc #489

* more tests, fix doc

* lowercase origin before checking cors
@emicklei
Copy link
Owner

emicklei commented Jun 6, 2022

merged into 3.8.0

@emicklei emicklei closed this as completed Jun 6, 2022
@JamieSlome
Copy link
Author

@emicklei - thanks for the work 👍

@othomann
Copy link

othomann commented Jun 7, 2022

@emicklei Hi, is it possible to backport to v2.x stream ? I have an indirect dependency to v2.15.0+incompatible that is tagged with this vulnerability.Thanks.

L3n41c pushed a commit to L3n41c/go-restful that referenced this issue Jul 11, 2022
…cklei#493)

* use exact matching of allowed domain entries, issue emicklei#489

* update doc, add testcases from PR conversation

* introduce AllowedDomainFunc emicklei#489

* more tests, fix doc

* lowercase origin before checking cors
emicklei added a commit that referenced this issue Jul 11, 2022
* use exact matching of allowed domain entries, issue #489

* update doc, add testcases from PR conversation

* introduce AllowedDomainFunc #489

* more tests, fix doc

* lowercase origin before checking cors

Co-authored-by: Ernest Micklei <ernest.micklei@gmail.com>
vasiliy-ul added a commit to vasiliy-ul/containerized-data-importer that referenced this issue Jul 26, 2022
The updated version fixes 'Authorization Bypass Through User-Controlled
Key' vulnerability (CVE-2022-1996).

References:
emicklei/go-restful#489
emicklei/go-restful#503

Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
kubevirt-bot pushed a commit to kubevirt/containerized-data-importer that referenced this issue Jul 27, 2022
The updated version fixes 'Authorization Bypass Through User-Controlled
Key' vulnerability (CVE-2022-1996).

References:
emicklei/go-restful#489
emicklei/go-restful#503

Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
joel-bluedata added a commit to joel-bluedata/kubedirector that referenced this issue Aug 10, 2022
Putting some CVEs in our rearview mirror.

jf docker scan before: 4 critical, 15 high
after (using golang 1.18.5): 1 critical, 8 high

The remaining critical is CVE-2022-1996 from emicklei/go-restful ... we could try to force an update on that package or we might be required to finally move to a more recent version of operator SDK. I'm not super exercised about that one though because as described in emicklei/go-restful#489 I believe it does not apply to KD. Will double-check.
joel-bluedata added a commit to joel-bluedata/kubedirector that referenced this issue Aug 17, 2022
Putting some CVEs in our rearview mirror.

jf docker scan before: 4 critical, 15 high
after (using golang 1.18.5): 1 critical, 8 high

The remaining critical is CVE-2022-1996 from emicklei/go-restful ... we could try to force an update on that package or we might be required to finally move to a more recent version of operator SDK. I'm not super exercised about that one though because as described in emicklei/go-restful#489 I believe it does not apply to KD. Will double-check.
joel-bluedata added a commit to joel-bluedata/kubedirector that referenced this issue Aug 18, 2022
Putting some CVEs in our rearview mirror.

jf docker scan before: 4 critical, 15 high
after (using golang 1.18.5): 1 critical, 8 high

The remaining critical is CVE-2022-1996 from emicklei/go-restful ... we could try to force an update on that package or we might be required to finally move to a more recent version of operator SDK. I'm not super exercised about that one though because as described in emicklei/go-restful#489 I believe it does not apply to KD. Will double-check.
michi-covalent added a commit to cilium/cilium that referenced this issue Jan 20, 2023
To pick up the fix for emicklei/go-restful#489.

Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
michi-covalent added a commit to cilium/cilium that referenced this issue Jan 24, 2023
To pick up the fix for emicklei/go-restful#489.

Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
michi-covalent added a commit to cilium/cilium that referenced this issue Jan 24, 2023
To pick up the fix for emicklei/go-restful#489

Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
joestringer pushed a commit to cilium/cilium that referenced this issue Jan 25, 2023
To pick up the fix for emicklei/go-restful#489

Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
kserve-oss-bot pushed a commit to kserve/modelmesh-serving that referenced this issue Feb 16, 2023
#### Motivation

Address a security vulnerability in old version of the `go-restful` library

#### Modifications

Update go dependency

#### Result

No longer vulnerable to the "Authorization Bypass Through User-Controlled Key".

#### Related Issues:

https://github.com/kserve/modelmesh-serving/security/dependabot/4
emicklei/go-restful#489
https://www.cve.org/CVERecord?id=CVE-2022-1996
https://huntr.dev/bounties/be837427-415c-4d8c-808b-62ce20aa84f1/

Signed-off-by: Christian Kadner <ckadner@us.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants