feat(oidc-prompts): Add Validation for Prompts (#4130)

Add validation to prevent "none" from being combined with multiple prompts.

- Valid `["none"]`
- Invalid `["none", "select_account"]`
- Valid `["consent", "select_account"]`
This commit is contained in:
Elim Tsiagbey authored and GitHub committed 2023-12-08 09:51:54 -05:00
1 parent c70a6ff6ba
commit 053421600d
4 files changed
+86 -9

No files matched your search

@@ -1034,10 +1034,16 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateAuthMethodRequest
}
}
if len(attrs.GetPrompts()) > 0 {
for _, p := range attrs.GetPrompts() {
if !oidc.SupportedPrompt(oidc.PromptParam(p)) {
badFields[promptsField] = fmt.Sprintf("Contains unsupported prompt %q", p)
break
prompts := strutil.RemoveDuplicatesStable(attrs.GetPrompts(), false)
if strutil.StrListContains(prompts, string(oidc.None)) && len(prompts) > 1 {
badFields[promptsField] = fmt.Sprintf(`prompts (%s) includes "none" with other values`, prompts)
} else {
for _, p := range attrs.GetPrompts() {
if !oidc.SupportedPrompt(oidc.PromptParam(p)) {
badFields[promptsField] = fmt.Sprintf("Contains unsupported prompt %q", p)
break
}
}
}
}
@@ -1170,10 +1176,16 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateAuthMethodRequest
}
}
if len(attrs.GetPrompts()) > 0 {
for _, p := range attrs.GetPrompts() {
if !oidc.SupportedPrompt(oidc.PromptParam(p)) {
badFields[promptsField] = fmt.Sprintf("Contains unsupported prompt %q", p)
break
prompts := strutil.RemoveDuplicatesStable(attrs.GetPrompts(), false)
if strutil.StrListContains(prompts, string(oidc.None)) && len(prompts) > 1 {
badFields[promptsField] = fmt.Sprintf(`prompts (%s) includes "none" with other values`, prompts)
} else {
for _, p := range attrs.GetPrompts() {
if !oidc.SupportedPrompt(oidc.PromptParam(p)) {
badFields[promptsField] = fmt.Sprintf("Contains unsupported prompt %q", p)
break
}
}
}
}