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
}
}
}
}
@@ -1454,6 +1454,25 @@ func TestCreate(t *testing.T) {
},
},
},
{
name: "Create OIDC AuthMethod with none and other prompts",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Type: oidc.Subtype.String(),
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
Issuer: wrapperspb.String("https://example.discovery.url:4821/.well-known/openid-configuration/"),
ClientId: wrapperspb.String("exampleclientid"),
ClientSecret: wrapperspb.String("secret"),
ApiUrlPrefix: wrapperspb.String("https://callback.prefix:9281/path"),
Prompts: []string{string(oidc.None), string(oidc.SelectAccount)},
},
},
}},
idPrefix: globals.OidcAuthMethodPrefix + "_",
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
errContains: "includes \\\"none\\\" with other values",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {