Skip to content

Commit 7f179d6

Browse files
committed
Enforce min and max length for string and password types in the wizard
RELEASE_NOTES=[BUGFIX] Wizard: Enforce min and max length. Fixes #2922 Signed-off-by: Dominik Schulz <[email protected]>
1 parent 4dfb649 commit 7f179d6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

internal/create/wizard.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ func mkActFunc(tpl Template, s *root.Store, cb ActionCallback) func(context.Cont
222222
if err != nil {
223223
return err
224224
}
225+
if v.Min > 0 && len(sv) < v.Min {
226+
return fmt.Errorf("%s is too short (needs %d)", v.Name, v.Min)
227+
}
228+
if v.Max > 0 && len(sv) > v.Min {
229+
return fmt.Errorf("%s is too long (at most %d)", v.Name, v.Max)
230+
}
225231
if wantForName[k] {
226232
nameParts = append(nameParts, sv)
227233
}
@@ -259,6 +265,12 @@ func mkActFunc(tpl Template, s *root.Store, cb ActionCallback) func(context.Cont
259265
if err != nil {
260266
return err
261267
}
268+
if v.Min > 0 && len(password) < v.Min {
269+
return fmt.Errorf("%s is too short (needs %d)", v.Name, v.Min)
270+
}
271+
if v.Max > 0 && len(password) > v.Min {
272+
return fmt.Errorf("%s is too long (at most %d)", v.Name, v.Max)
273+
}
262274
}
263275

264276
sec.SetPassword(password)

0 commit comments

Comments
 (0)