mirror of
https://github.com/distribution/distribution.git
synced 2025-09-13 13:49:00 +00:00
Fix registry token authentication bug
When a JWT contains a JWK header without a certificate chain, the original code only checked if the KeyID (kid) matches one of the trusted keys, but doesn't verify that the actual key material matches. As a result, if an attacker guesses the kid, they can inject an untrusted key which would then be used to grant access to protected data. This fixes the issue such as only the trusted key is verified. Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
This commit is contained in:
@@ -219,11 +219,12 @@ func verifyJWK(header jose.Header, verifyOpts VerifyOptions) (signingKey crypto.
|
||||
// Check to see if the key includes a certificate chain.
|
||||
if len(jwk.Certificates) == 0 {
|
||||
// The JWK should be one of the trusted root keys.
|
||||
if _, trusted := verifyOpts.TrustedKeys[jwk.KeyID]; !trusted {
|
||||
trustedKey, trusted := verifyOpts.TrustedKeys[jwk.KeyID]
|
||||
if !trusted {
|
||||
return nil, errors.New("untrusted JWK with no certificate chain")
|
||||
}
|
||||
// The JWK is one of the trusted keys.
|
||||
return
|
||||
return trustedKey, nil
|
||||
}
|
||||
|
||||
opts := x509.VerifyOptions{
|
||||
|
Reference in New Issue
Block a user