Skip to content

Commit 1227556

Browse files
committed
cli/command/registry: preserve all whitespace in secrets
Preserve all whitespace and treat the secret as an opaque value, leaving it to the registry to (in)validate. We still check for empty values in some places. This partially reverts a21a5f4, but checks for empty (whitespace-only) passwords without mutating the value. This better aligns with [NIST SP 800-63B §5.1.1.2], which describes that the value should be treated as opaque, preserving any other whitespace, including newlines. Note that trimming whitespace may still happen elsewhere (see [NIST SP 800-63B (revision 4) §3.1.1.2]); > Verifiers **MAY** make limited allowances for mistyping (e.g., removing > leading and trailing whitespace characters before verification, allowing > the verification of passwords with differing cases for the leading character) [NIST SP 800-63B §5.1.1.2]: https://pages.nist.gov/800-63-3/sp800-63b.html#memsecretver [NIST SP 800-63B (revision 4) §3.1.1.2]: https://pages.nist.gov/800-63-4/sp800-63b.html#passwordver Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 2a99b14 commit 1227556

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

cli/command/registry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword
144144
}
145145
}
146146

147-
argPassword = strings.TrimSpace(argPassword)
148-
if argPassword == "" {
147+
isEmpty := strings.TrimSpace(argPassword) == ""
148+
if isEmpty {
149149
restoreInput, err := prompt.DisableInputEcho(cli.In())
150150
if err != nil {
151151
return registrytypes.AuthConfig{}, err

cli/command/registry/login_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,56 @@ func TestRunLogin(t *testing.T) {
306306
},
307307
},
308308
},
309+
{
310+
doc: "password with leading and trailing spaces",
311+
priorCredentials: map[string]configtypes.AuthConfig{},
312+
input: loginOptions{
313+
serverAddress: "reg1",
314+
user: "my-username",
315+
password: " my password with spaces ",
316+
},
317+
expectedCredentials: map[string]configtypes.AuthConfig{
318+
"reg1": {
319+
Username: "my-username",
320+
Password: " my password with spaces ",
321+
ServerAddress: "reg1",
322+
},
323+
},
324+
},
325+
{
326+
doc: "password stdin with line-endings",
327+
priorCredentials: map[string]configtypes.AuthConfig{},
328+
stdIn: " my password with spaces \r\n",
329+
input: loginOptions{
330+
serverAddress: "reg1",
331+
user: "my-username",
332+
passwordStdin: true,
333+
},
334+
expectedCredentials: map[string]configtypes.AuthConfig{
335+
"reg1": {
336+
Username: "my-username",
337+
Password: " my password with spaces ",
338+
ServerAddress: "reg1",
339+
},
340+
},
341+
},
342+
{
343+
doc: "password stdin with multiple line-endings",
344+
priorCredentials: map[string]configtypes.AuthConfig{},
345+
stdIn: " my password\nwith spaces \r\n\r\n",
346+
input: loginOptions{
347+
serverAddress: "reg1",
348+
user: "my-username",
349+
passwordStdin: true,
350+
},
351+
expectedCredentials: map[string]configtypes.AuthConfig{
352+
"reg1": {
353+
Username: "my-username",
354+
Password: " my password\nwith spaces \r\n",
355+
ServerAddress: "reg1",
356+
},
357+
},
358+
},
309359
}
310360

311361
for _, tc := range testCases {

0 commit comments

Comments
 (0)