kubernetes/kubernetes

docker credential JSON: validate non UTF-8 characters

クローズ

#131,982 opened on 2025/05/27

 (9 件のコメント) (0 件のリアクション) (1 人の担当者)Go (43,066 件のフォーク)batch import
help wantedkind/bugpriority/backlogsig/nodesig/securitytriage/accepted

Repository metrics

Stars
 (122,268 個のスター)
PR merge metrics
 (平均マージ 28d 17h) (30d で 343 merged PRs)

説明

What happened?

Using base64 encoding, it’s possible to include arbitrary data (including non-UTF-8 strings) that can pass Kubernetes validation. While this may be a minor issue within Kubernetes itself and likely not exploitable directly, it could pose a risk to external systems that consume these secrets. If such systems assume UTF-8 encoding, they might be vulnerable to unexpected behavior or exploitation.

What did you expect to happen?

The input should be rejected with an "invalid UTF-8" error.

How can we reproduce it (as minimally and precisely as possible)?

A test case for https://github.com/kubernetes/kubernetes/blob/a647c6a8893df95050d6acbd60850df420d90518/pkg/credentialprovider/config_test.go#L122

// auth field decodes to username & password with non UTF-8 characters
{
	input: []byte(`{"auth": "YcV6OmHFeg==", "email": "foo@example.com"}`),
	expect: DockerConfigEntry{
		Username: "a\xc5z",
		Password: "a\xc5z",
		Email:    "foo@example.com",
	},
	fail: false,
},

I'd expect this input to fail with invalid character error

s := string(decoded)
if !utf8.ValidString(s) {
	return "", "", errors.New("invalid UTF-8")
}
parts := strings.SplitN(s, ":", 2)

https://github.com/kubernetes/kubernetes/blob/a647c6a8893df95050d6acbd60850df420d90518/pkg/credentialprovider/config.go#L303

Anything else we need to know?

No response

Kubernetes version

master

Cloud provider

OS version

Install tools

No response

Container runtime (CRI) and version (if applicable)

No response

Related plugins (CNI, CSI, ...) and versions (if applicable)

No response

コントリビューターガイド