Skip to content

Commit

Permalink
fix: change password requirements to a map
Browse files Browse the repository at this point in the history
  • Loading branch information
silentworks committed Nov 26, 2024
1 parent 260897a commit 0030a06
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
9 changes: 8 additions & 1 deletion internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ EOF
formatMapForEnvConfig(utils.Config.Auth.Sms.TestOTP, &testOTP)
}

var password_requirements = map[config.PasswordRequirements]string{
"": "",
"letters_digits": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:0123456789",
"lower_upper_letters_digits": "abcdefghijklmnopqrstuvwxyz:ABCDEFGHIJKLMNOPQRSTUVWXYZ:0123456789",
"lower_upper_letters_digits_symbols": "abcdefghijklmnopqrstuvwxyz:ABCDEFGHIJKLMNOPQRSTUVWXYZ:0123456789:!@#$%^&*()_+-=[]{};'\\\\:\"|<>?,./`~",
}

env := []string{
"API_EXTERNAL_URL=" + utils.Config.Api.ExternalUrl,

Expand Down Expand Up @@ -507,7 +514,7 @@ EOF
"GOTRUE_SMS_TEST_OTP=" + testOTP.String(),

fmt.Sprintf("GOTRUE_PASSWORD_MIN_LENGTH=%v", utils.Config.Auth.MinimumPasswordLength),
fmt.Sprintf("GOTRUE_PASSWORD_REQUIRED_CHARACTERS=%v", utils.Config.Auth.PasswordRequirements),
fmt.Sprintf("GOTRUE_PASSWORD_REQUIRED_CHARACTERS=%v", password_requirements[utils.Config.Auth.PasswordRequirements]),
fmt.Sprintf("GOTRUE_SECURITY_REFRESH_TOKEN_ROTATION_ENABLED=%v", utils.Config.Auth.EnableRefreshTokenRotation),
fmt.Sprintf("GOTRUE_SECURITY_REFRESH_TOKEN_REUSE_INTERVAL=%v", utils.Config.Auth.RefreshTokenReuseInterval),
fmt.Sprintf("GOTRUE_SECURITY_MANUAL_LINKING_ENABLED=%v", utils.Config.Auth.EnableManualLinking),
Expand Down
29 changes: 19 additions & 10 deletions pkg/config/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@ import (
"github.com/supabase/cli/pkg/diff"
)

type PasswordRequirements string

const (
NoRequirements PasswordRequirements = ""
LettersDigits PasswordRequirements = "letters_digits"
LowerUpperLettersDigits PasswordRequirements = "lower_upper_letters_digits"
LowerUpperLettersDigitsSymbols PasswordRequirements = "lower_upper_letters_digits_symbols"
)

type (
auth struct {
Enabled bool `toml:"enabled"`
Image string `toml:"-"`

SiteUrl string `toml:"site_url"`
AdditionalRedirectUrls []string `toml:"additional_redirect_urls"`
JwtExpiry uint `toml:"jwt_expiry"`
MinimumPasswordLength uint `toml:"minimum_password_length"`
PasswordRequirements string `toml:"password_requirements"`
EnableRefreshTokenRotation bool `toml:"enable_refresh_token_rotation"`
RefreshTokenReuseInterval uint `toml:"refresh_token_reuse_interval"`
EnableManualLinking bool `toml:"enable_manual_linking"`
EnableSignup bool `toml:"enable_signup"`
EnableAnonymousSignIns bool `toml:"enable_anonymous_sign_ins"`
SiteUrl string `toml:"site_url"`
AdditionalRedirectUrls []string `toml:"additional_redirect_urls"`
JwtExpiry uint `toml:"jwt_expiry"`
MinimumPasswordLength uint `toml:"minimum_password_length"`
PasswordRequirements PasswordRequirements `toml:"password_requirements"`
EnableRefreshTokenRotation bool `toml:"enable_refresh_token_rotation"`
RefreshTokenReuseInterval uint `toml:"refresh_token_reuse_interval"`
EnableManualLinking bool `toml:"enable_manual_linking"`
EnableSignup bool `toml:"enable_signup"`
EnableAnonymousSignIns bool `toml:"enable_anonymous_sign_ins"`

Hook hook `toml:"hook"`
MFA mfa `toml:"mfa"`
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ func (c *baseConfig) Validate(fsys fs.FS) error {
return errors.Errorf("Invalid config for auth.additional_redirect_urls[%d]: %v", i, err)
}
}
allowed := []PasswordRequirements{NoRequirements, LettersDigits, LowerUpperLettersDigits, LowerUpperLettersDigitsSymbols}
if !sliceContains(allowed, c.Auth.PasswordRequirements) {
return errors.Errorf("Invalid config for auth.password_requirements. Must be one of: %v", allowed)
}
if err := c.Auth.Hook.validate(); err != nil {
return err
}
Expand Down

0 comments on commit 0030a06

Please sign in to comment.