JuliusBrussee/caveman · error

password must be at most

Error message

password must be at most %d bytes

What it means

ValidatePassword rejects passwords longer than MaxPasswordBytes (1024). This upper bound prevents pathological inputs from being fed into key-derivation (which is deliberately expensive) and protects against memory/DoS abuse. Because the check is on bytes, a very long passphrase of multibyte characters can trip it even with a modest character count.

Solutions

  1. Cap the password field client-side (input maxlength / server-side length check) to 1024 bytes before calling ValidatePassword.
  2. Detect and reject token-like inputs: if the 'password' looks like a JWT/API key, direct the user to the token field instead.
  3. If long passphrases are legitimate, hash them (e.g. SHA-256) to a fixed size before validation per your policy — but prefer enforcing a sane passphrase limit.
  4. Review request body limits at the HTTP layer so oversized payloads are rejected before reaching password validation.

Example fix

// before
pw := readBody(r)
if err := security.ValidatePassword(pw); err != nil { ... } // password must be at most 1024 bytes

// after
if len(pw) > security.MaxPasswordBytes {
    http.Error(w, fmt.Sprintf("password must be at most %d bytes", security.MaxPasswordBytes), http.StatusBadRequest)
    return
}
if err := security.ValidatePassword(pw); err != nil { ... }
Defensive patterns

Strategy: validation

Validate before calling

if len([]byte(password)) > security.MaxPasswordBytes {
    return fmt.Errorf("password must be at most %d bytes", security.MaxPasswordBytes)
}

Type guard

func withinMaxLength(pw string) bool { return len(pw) <= security.MaxPasswordBytes }

Try / catch

if err := security.ValidatePassword(pw); err != nil {
    if strings.Contains(err.Error(), "at most") {
        return fmt.Errorf("input rejected as a password (too long) — did you paste a key or token?")
    }
    return err
}

Prevention

When it happens

Trigger: Calling ValidatePassword with a string longer than 1024 bytes — pasted API keys/JWTs used as passwords, generated keys or hex dumps submitted into the password field, or fuzz/abuse traffic sending megabyte bodies.

Common situations: Users pasting a full secret or token into a 'passphrase' field; scripts passing entire files as passwords; clients without maxlength attributes on the password input.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at shared/platform/security/keys.go:25

	"encoding/base64"
	"encoding/hex"
	"fmt"
	"strings"

	"golang.org/x/crypto/argon2"
)

const (
	MinPasswordBytes = 12
	MaxPasswordBytes = 1024
)

func ValidatePassword(password string) error {
	if len(password) < MinPasswordBytes {
		return fmt.Errorf("password must be at least %d bytes", MinPasswordBytes)
	}
	if len(password) > MaxPasswordBytes {
		return fmt.Errorf("password must be at most %d bytes", MaxPasswordBytes)
	}
	return nil
}

func GenerateProjectKey() (string, string, error) {
	raw := make([]byte, 32)
	if _, err := rand.Read(raw); err != nil {
		return "", "", err
	}
	secret := base64.RawURLEncoding.EncodeToString(raw)
	full := "cave_live_" + secret[:12] + "_" + secret[12:]
	return full, secret[:12], nil
}

func HashProjectKey(pepper, full string) string {
	mac := hmac.New(sha256.New, []byte(pepper))
	mac.Write([]byte(full))
	return hex.EncodeToString(mac.Sum(nil))

View on GitHub (pinned to 3ee70a1026)