sweep: fix missing view_count on HTML views, API expiry bounds, search ignoring custom slug (#33)
CI / test (push) Successful in 21s
CI / docker (push) Skipped

This commit is contained in:
2026-09-09 00:34:24 -05:00
parent cb23707125
commit 03600b2ed5
4 changed files with 139 additions and 1 deletions
+16
View File
@@ -167,6 +167,19 @@ func cryptorandRead(b []byte) (int, error) {
return cryptoRead(b)
}
// validExpiry reports whether an expires_in duration is in the accepted
// window. The UI restricts presets to 1 minute - 1 year (#48); the API must
// enforce the same bounds, otherwise negative/zero/absurd durations create
// pastes that are born expired (or effectively permanent).
const (
minExpiry = time.Minute
maxExpiry = 366 * 24 * time.Hour // 1 year (+ leap day headroom)
)
func validExpiry(d time.Duration) bool {
return d >= minExpiry && d <= maxExpiry
}
func (s *Store) CreatePaste(p *Paste) (*Paste, error) {
id := genSlug(6)
now := time.Now().Unix()
@@ -177,6 +190,9 @@ func (s *Store) CreatePaste(p *Paste) (*Paste, error) {
if err != nil {
return nil, fmt.Errorf("invalid expires_in: %w", err)
}
if !validExpiry(d) {
return nil, fmt.Errorf("expires_in must be between 1 minute and 1 year")
}
t := now + int64(d.Seconds())
expiresAt = &t
}