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

x/crypto/ssh: misuse of ServerConfig.PublicKeyCallback may cause authorization bypass #70779

Closed
rolandshoemaker opened this issue Dec 11, 2024 · 14 comments · Fixed by piplabs/story-geth#79 or vkamlesh/local-path-provisioner#1 · May be fixed by rancher/local-path-provisioner#469 or vmware-tanzu/velero#8514
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done. Security
Milestone

Comments

@rolandshoemaker
Copy link
Member

rolandshoemaker commented Dec 11, 2024

Applications and libraries which misuse the ServerConfig.PublicKeyCallback callback may be susceptible to an authorization bypass.

The documentation for ServerConfig.PublicKeyCallback says that "A call to this function does not guarantee that the key offered is in fact used to authenticate." Specifically, the SSH protocol allows clients to inquire about whether a public key is acceptable before proving control of the corresponding private key. PublicKeyCallback may be called with multiple keys, and the order in which the keys were provided cannot be used to infer which key the client successfully authenticated with, if any. Some applications, which store the key(s) passed to PublicKeyCallback (or derived information) and make security relevant determinations based on it once the connection is established, may make incorrect assumptions.

For example, an attacker may send public keys A and B, and then authenticate with A. PublicKeyCallback would be called only twice, first with A and then with B. A vulnerable application may then make authorization decisions based on key B for which the attacker does not actually control the private key.

Since this API is widely misused, as a partial mitigation golang.org/x/crypto@v0.31.0 enforces the property that, when successfully authenticating via public key, the last key passed to ServerConfig.PublicKeyCallback will be the key used to authenticate the connection. PublicKeyCallback will now be called multiple times with the same key, if necessary. Note that the client may still not control the last key passed to PublicKeyCallback if the connection is then authenticated with a different method, such as PasswordCallback, KeyboardInteractiveCallback, or NoClientAuth.

Users should be using the Extensions field of the Permissions return value from the various authentication callbacks to record data associated with the authentication attempt instead of referencing external state. Once the connection is established the state corresponding to the successful authentication attempt can be retrieved via the ServerConn.Permissions field. Note that some third-party libraries misuse the Permissions type by sharing it across authentication attempts; users of third-party libraries should refer to the relevant projects for guidance.

Thanks to Damien Tournoud, Patrick Dawkins, Vince Parker, and Jules Duvivier from the Platform.sh / Upsun engineering team for reporting this issue.

@gabyhelp

This comment was marked as outdated.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/635315 mentions this issue: ssh: make the public key cache a 1-entry FIFO cache

@rolandshoemaker rolandshoemaker changed the title security: fix CVE-2024-45337 x/crypto/ssh: misuse of ServerConfig.PublicKeyCallback may cause authorization bypass Dec 11, 2024
@dmitshur dmitshur added this to the Unreleased milestone Dec 11, 2024
@bhiggins
Copy link

Related: #20094

@acestronautical
Copy link

It looks like this was reported in 2017 in #20094 but that issue was frozen due to no real world examples of misuse of the API being found at the time. I actually think the write up and discussion on the older issue is a little clearer.

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Dec 11, 2024
bradfitz added a commit to tailscale/tailscale that referenced this issue Dec 12, 2024
When we first made Tailscale SSH, we assumed people would want public
key support soon after. Turns out that hasn't been the case; people
love the Tailscale identity authentication and check mode.

In light of CVE-2024-45337, just remove all our public key code to not
distract people, and to make the code smaller. We can always get it
back from git if needed.

Updates tailscale/corp#25131
Updates golang/go#70779

Co-authored-by: Percy Wegmann <percy@tailscale.com>
Change-Id: I87a6e79c2215158766a81942227a18b247333c22
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
bradfitz added a commit to tailscale/tailscale that referenced this issue Dec 12, 2024
When we first made Tailscale SSH, we assumed people would want public
key support soon after. Turns out that hasn't been the case; people
love the Tailscale identity authentication and check mode.

In light of CVE-2024-45337, just remove all our public key code to not
distract people, and to make the code smaller. We can always get it
back from git if needed.

Updates tailscale/corp#25131
Updates golang/go#70779

Co-authored-by: Percy Wegmann <percy@tailscale.com>
Change-Id: I87a6e79c2215158766a81942227a18b247333c22
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
bradfitz added a commit to tailscale/tailscale that referenced this issue Dec 12, 2024
When we first made Tailscale SSH, we assumed people would want public
key support soon after. Turns out that hasn't been the case; people
love the Tailscale identity authentication and check mode.

In light of CVE-2024-45337, just remove all our public key code to not
distract people, and to make the code smaller. We can always get it
back from git if needed.

Updates tailscale/corp#25131
Updates golang/go#70779

Co-authored-by: Percy Wegmann <percy@tailscale.com>
Change-Id: I87a6e79c2215158766a81942227a18b247333c22
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
bradfitz added a commit to tailscale/tailscale that referenced this issue Dec 12, 2024
When we first made Tailscale SSH, we assumed people would want public
key support soon after. Turns out that hasn't been the case; people
love the Tailscale identity authentication and check mode.

In light of CVE-2024-45337, just remove all our public key code to not
distract people, and to make the code smaller. We can always get it
back from git if needed.

Updates tailscale/corp#25131
Updates golang/go#70779

Co-authored-by: Percy Wegmann <percy@tailscale.com>
Change-Id: I87a6e79c2215158766a81942227a18b247333c22
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
@cwayne18
Copy link

I'm sorry but how on earth has this been assigned a CVSS score of 9.1?

@FiloSottile
Copy link
Contributor

CVSS scores for widely used libraries are more or less meaningless. Most security vulnerabilities (and many bugs) can be inconsequential or critical depending on the application.

More concretely, I don't think the Go project is involved in the CVSS scoring process. @rolandshoemaker?

@brandond
Copy link

brandond commented Dec 12, 2024

As per the discussion at #20094 - this is NOT a vulnerability in this library. It is just a poorly documented callback API that has a POTENTIAL for misuse by users who do not understand how SSH key exchange works.

Now everyone that uses x/crypto has a nice 9.1 CVE that they have to "patch", even if they're not using x/crypto/ssh, or use the callback properly.

@FiloSottile
Copy link
Contributor

FiloSottile commented Dec 12, 2024

Now everyone that uses x/crypto has a nice 9.1 CVE that they have to "patch", even if they're not using x/crypto/ssh

I invite you to take the opportunity to ask your vendor scanner why they report such obvious false positives, when the public vulnerability database includes package and symbol information. govulncheck is an example of a scanner that won't report that false positive.

https://github.com/golang/vulndb/blob/71259c6095afe08ddb01e45142c674502056db6c/data/reports/GO-2024-3321.yaml#L8-L10

@brandond
Copy link

brandond commented Dec 12, 2024

Yes, unfortunately the GitHub Advisory Database and dependabot don't seem to be capable of using that information yet so they're going around opening alerts across hundreds of projects.

@rolandshoemaker
Copy link
Member Author

We explicitly don't assign CVSS scores for our CVEs, as we do not believe they can be accurately calculated for libraries. MITRE et al fills those in when we omit them, despite our objections, and there is not much we can do about that.

@FiloSottile
Copy link
Contributor

Yes, unfortunately the GitHub Advisory Database and dependabot don't seem to be capable of using that information yet so they're going around opening alerts across hundreds of projects.

According to the README of https://github.com/community/community, the feedback channel to report this limitation is https://github.com/orgs/community/discussions/categories/code-security.

@cwayne18
Copy link

Fair point, I appreciate the info! I mistakenly was under the impression the team submitting the CVE passed along a score, my bad!

@acestronautical
Copy link

In the hypothetical scenario that someone is misusing this API, will patching up past 9.1 give them false confidence? What are the implications of API misuse after https://go.dev/cl/635315?

@FiloSottile
Copy link
Contributor

The most common misuse, recording the last seen PublicKey, is mitigated as long as there are no other authentication methods (PasswordCallback, KeyboardInteractiveCallback, or NoClientAuth).

Since this API is widely misused, as a partial mitigation golang.org/x/crypto@v0.31.0 enforces the property that, when successfully authenticating via public key, the last key passed to ServerConfig.PublicKeyCallback will be the key used to authenticate the connection. PublicKeyCallback will now be called multiple times with the same key, if necessary. Note that the client may still not control the last key passed to PublicKeyCallback if the connection is then authenticated with a different method, such as PasswordCallback, KeyboardInteractiveCallback, or NoClientAuth.

neurosnap added a commit to picosh/pico that referenced this issue Dec 13, 2024
orgads pushed a commit to orgads/telegraf that referenced this issue Dec 16, 2024
vkamlesh added a commit to vkamlesh/local-path-provisioner that referenced this issue Dec 16, 2024
vkamlesh added a commit to vkamlesh/velero that referenced this issue Dec 16, 2024
The change will fix CVE-2023-45288

Vulnerability details:  https://nvd.nist.gov/vuln/detail/CVE-2024-45337
Fix: golang/go#70779

Signed-off-by: Kamlesh Verma <kamlesh.a.verma@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment