Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions internal/resources/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ const (
GoTrueFallbackSecretNameSuffix = "-gotrue-jwt-secret"
)

const emailHookSecretBytes = 32

// ProjectCredentials is the validated, transient projection of the external
// credential bundle. Secret values are never written to project status.
type ProjectCredentials struct {
Expand Down Expand Up @@ -289,7 +287,7 @@ func ValidateEmailHookSecret(secret *corev1.Secret) error {
return fmt.Errorf("email hook Secret must contain a Standard Webhooks value")
}
payload, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(value, "v1,whsec_"))
if err != nil || len(payload) != emailHookSecretBytes {
if err != nil || len(payload) == 0 {
return fmt.Errorf("email hook Secret contains an invalid Standard Webhooks value")
}
return nil
Expand Down
8 changes: 7 additions & 1 deletion internal/resources/secrets/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestValidateEmailHookSecretRejectsMalformedValues(t *testing.T) {
tests := map[string]string{
"empty payload": "v1,whsec_",
"invalid base64": "v1,whsec_not-base64",
"short payload": "v1,whsec_" + base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{1}, 31)),
"wrong prefix": strings.TrimPrefix(validValue, "v1,"),
}

Expand All @@ -59,6 +58,13 @@ func TestValidateEmailHookSecretRejectsMalformedValues(t *testing.T) {
if err := ValidateEmailHookSecret(valid); err != nil {
t.Fatalf("ValidateEmailHookSecret() rejected a valid secret: %v", err)
}

preserved := &corev1.Secret{Data: map[string][]byte{EmailHookSecretKey: []byte(
"v1,whsec_" + base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{1}, 58)),
)}}
if err := ValidateEmailHookSecret(preserved); err != nil {
t.Fatalf("ValidateEmailHookSecret() rejected a valid preserved secret: %v", err)
}
}

func newTestProject(namespace string) *supabasev1alpha1.SupabaseProject {
Expand Down
Loading