v0.1.17: security hardening — 18/20 vulnerabilities fixed

Phase 1 (Critical):
- #1 JWT auth (done in v0.1.16)
- #2 Batch message size validation in send_message_batch.go
- #10 RLock in GetQueueUrlV1 (data race fix)

Phase 2 (AWS-compatible limits):
- #3 QueueName validation: max 80 chars, [a-zA-Z0-9_-](.fifo)?
- #4 WaitTimeSeconds clamped to 0-20
- #5 ReceiveMessageWaitTimeSeconds clamped to 0-20
- #6 DelaySeconds clamped to 0-900
- #7 VisibilityTimeout clamped to 0-43200
- #8 MaxNumberOfMessages clamped to 1-10
- #9 Message attributes limited to 10 per message
- #15 BatchEntryId length validated (max 80)
- #16 DeduplicationID length validated (max 128)
- #17 GroupID length validated (max 128)

Phase 3 (Per-tenant resource limits):
- #11 Max messages per queue (120K standard, 20K FIFO)
- #12 Global tenant limit (1000)
- #3.5 HTTP request body size limit (1MB via MaxBytesReader)

Phase 4 (Stability):
- #14 Duplicates map cleanup (already in PeriodicTasks)
- #13 FIFO group lock timeout (already in visibility timeout reset)
- #18 Redis size guard: skip save if >50MB

Skipped (Low, no real risk):
- #19 {account} URL param (informational only, not used for access)
- #20 ReceiptHandle format (self-validating UUID#UUID)

New file: app/gosqs/validation.go — centralized AWS SQS limits and validators
This commit is contained in:
Naeel
2026-04-10 18:58:40 +03:00
parent b9d434bcc5
commit e9a26f7975
11 changed files with 229 additions and 14 deletions
+10
View File
@@ -13,6 +13,9 @@ import (
"shared-sqs/app/persistence"
)
// MaxTenantsGlobal — глобальный лимит тенантов (защита от OOM, Fix #12)
const MaxTenantsGlobal = 1000
// Tenant — модель тенанта shared-sqs.
// AccessKey используется как идентификатор в AWS Authorization header.
type Tenant struct {
@@ -46,7 +49,14 @@ func NewTenantStore() *TenantStore {
}
// Create — создаёт нового тенанта, генерирует ключи, сохраняет в оба индекса.
// Fix #12: глобальный лимит тенантов — защита от OOM при массовом создании.
func (s *TenantStore) Create(name string, maxQueues int) (*Tenant, error) {
s.mu.RLock()
tenantCount := len(s.byID)
s.mu.RUnlock()
if tenantCount >= MaxTenantsGlobal {
return nil, fmt.Errorf("global tenant limit reached (%d)", MaxTenantsGlobal)
}
id, err := generateTenantID()
if err != nil {
return nil, fmt.Errorf("generate tenant id: %w", err)