Skip to content

Commit 6aab160

Browse files
authored
trim control characters from secret to prevent newlines in client secret (#3936)
1 parent a2e0247 commit 6aab160

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

pkg/ingress/model_build_actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (t *defaultModelBuildTask) buildAuthenticateOIDCAction(ctx context.Context,
187187

188188
t.secretKeys = append(t.secretKeys, secretKey)
189189
clientID := strings.TrimRightFunc(string(rawClientID), unicode.IsSpace)
190-
clientSecret := string(rawClientSecret)
190+
clientSecret := strings.TrimRightFunc(string(rawClientSecret), unicode.IsControl)
191191
return elbv2model.Action{
192192
Type: elbv2model.ActionTypeAuthenticateOIDC,
193193
AuthenticateOIDCConfig: &elbv2model.AuthenticateOIDCActionConfig{

pkg/ingress/model_build_actions_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,61 @@ func Test_defaultModelBuildTask_buildAuthenticateOIDCAction(t *testing.T) {
8585
},
8686
},
8787
},
88+
{
89+
name: "clientSecret has control characters at end",
90+
env: env{
91+
secrets: []*corev1.Secret{
92+
{
93+
ObjectMeta: metav1.ObjectMeta{
94+
Namespace: "my-ns",
95+
Name: "my-k8s-secret",
96+
},
97+
Data: map[string][]byte{
98+
"clientID": []byte("my-client-id"),
99+
"clientSecret": []byte("my-client-secret\n"),
100+
},
101+
},
102+
},
103+
},
104+
args: args{
105+
authCfg: AuthConfig{
106+
Type: AuthTypeCognito,
107+
IDPConfigOIDC: &AuthIDPConfigOIDC{
108+
Issuer: "https://example.com",
109+
AuthorizationEndpoint: "https://authorization.example.com",
110+
TokenEndpoint: "https://token.example.com",
111+
UserInfoEndpoint: "https://userinfo.example.co",
112+
SecretName: "my-k8s-secret",
113+
AuthenticationRequestExtraParams: map[string]string{
114+
"key1": "value1",
115+
},
116+
},
117+
OnUnauthenticatedRequest: "authenticate",
118+
Scope: "email",
119+
SessionCookieName: "my-session-cookie",
120+
SessionTimeout: 65536,
121+
},
122+
namespace: "my-ns",
123+
},
124+
want: elbv2model.Action{
125+
Type: elbv2model.ActionTypeAuthenticateOIDC,
126+
AuthenticateOIDCConfig: &elbv2model.AuthenticateOIDCActionConfig{
127+
Issuer: "https://example.com",
128+
AuthorizationEndpoint: "https://authorization.example.com",
129+
TokenEndpoint: "https://token.example.com",
130+
UserInfoEndpoint: "https://userinfo.example.co",
131+
ClientID: "my-client-id",
132+
ClientSecret: "my-client-secret",
133+
AuthenticationRequestExtraParams: map[string]string{
134+
"key1": "value1",
135+
},
136+
OnUnauthenticatedRequest: authBehaviorAuthenticate,
137+
Scope: awssdk.String("email"),
138+
SessionCookieName: awssdk.String("my-session-cookie"),
139+
SessionTimeout: awssdk.Int64(65536),
140+
},
141+
},
142+
},
88143
{
89144
name: "clientID & clientSecret configured - legacy clientId",
90145
env: env{

0 commit comments

Comments
 (0)