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
- Cap the password field client-side (input maxlength / server-side length check) to 1024 bytes before calling ValidatePassword.
- Detect and reject token-like inputs: if the 'password' looks like a JWT/API key, direct the user to the token field instead.
- 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.
- 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
- Set maxlength=1024 (bytes-aware) on password inputs.
- Reject request bodies over a sane size at the HTTP layer.
- Detect pasted JWT/API-key shapes and route them to token fields.
- Log (without contents) oversized password attempts to spot abuse.
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
- password must be at least
- arm must be or
- CAVEMAN_CCR_MAX_BYTES must be a positive integer
- ccr max storage bytes must be positive
- ccr: unknown lifecycle
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)