JuliusBrussee/caveman · error

production requires to contain at least 32 characters

Error message

production requires %s to contain at least 32 characters

What it means

validateProductionTextSecrets requires each production text secret to be at least 32 bytes long after trimming; shorter values get 'production requires %s to contain at least 32 characters'. It enforces a minimum entropy floor so production secrets cannot be brute-forced.

Solutions

  1. Replace the secret with a value of at least 32 characters (e.g. `openssl rand -base64 48`).
  2. Check for trimming/truncation in your deployment tooling — the check runs on strings.TrimSpace(os.Getenv(name)).
  3. Rotate dependent systems (tokens signed with the old key) after rotating the secret.
  4. If this is not production, use local mode which does not enforce the length floor.

Example fix

// before
export CAVE_JWT_SIGNING_KEY="short-key"
// error: production requires CAVE_JWT_SIGNING_KEY to contain at least 32 characters

// after
export CAVE_JWT_SIGNING_KEY="$(openssl rand -base64 48)"  # 64 chars
Defensive patterns

Strategy: validation

Validate before calling

func checkSecretLength(name string) error {
    if len(strings.TrimSpace(os.Getenv(name))) < 32 {
        return fmt.Errorf("%s must be at least 32 characters", name)
    }
    return nil
}

Try / catch

if err := env.RefuseProductionDefaults(); err != nil {
    if strings.Contains(err.Error(), "at least 32 characters") {
        log.Fatalf("secret too short: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: RefuseProductionDefaults / RefuseGatewayProductionDefaults runs while CAVE_JWT_SIGNING_KEY or CAVE_BOOTSTRAP_TOKEN is set to a non-empty, non-default string shorter than 32 characters.

Common situations: Hand-typed secrets like 'my-dev-key-123'; keys truncated by a secrets-manager template; older deployments with short secrets hitting the new validation after upgrade.

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/8b4edb9b823ac1a5. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/env/env.go:104

	if err := validateProductionTextSecrets([]string{"CAVE_KEY_HASH_PEPPER"}); err != nil {
		return err
	}
	if Bool("CAVE_REPLAY_ENABLED", false) {
		if err := validateProductionTextSecrets([]string{"CAVE_ROUTER_REPLAY_TOKEN"}); err != nil {
			return err
		}
	}
	return validateProductionPublicURL()
}

func validateProductionTextSecrets(names []string) error {
	for _, name := range names {
		v := strings.TrimSpace(os.Getenv(name))
		if v == "" || v == "generated" || strings.Contains(strings.ToLower(v), "changeme") {
			return fmt.Errorf("production refuses default or empty %s", name)
		}
		if len(v) < 32 {
			return fmt.Errorf("production requires %s to contain at least 32 characters", name)
		}
		if distinctBytes([]byte(v)) < 8 {
			return fmt.Errorf("production refuses low-diversity %s", name)
		}
	}
	return nil
}

func validateProductionPublicURL() error {
	publicURL := strings.TrimSpace(os.Getenv("CAVE_PUBLIC_URL"))
	u, err := url.Parse(publicURL)
	if err != nil || u.Scheme != "https" || u.Hostname() == "" || u.User != nil || u.RawQuery != "" || u.Fragment != "" || (u.Path != "" && u.Path != "/") {
		return fmt.Errorf("production requires CAVE_PUBLIC_URL to be an HTTPS origin without credentials, path, query, or fragment")
	}
	return nil
}

func distinctBytes(value []byte) int {

View on GitHub (pinned to 3ee70a1026)