Problem
The current HTTP endpoints in /cmd/server/handlers.go lack comprehensive input validation and proper URL encoding, which can lead to several issues:
-
Missing Key Validation: The GET, PUT, and DELETE handlers don't validate key parameters for:
- Empty strings
- Excessively long keys (no maximum length enforcement)
- Special characters that could cause encoding issues
-
URL Encoding Issue in forwardToLeader(): Keys and values aren't URL-encoded before forwarding to leader:
- Special characters in keys/values can break request forwarding
- Example: Keys with
&, =, ? characters will cause malformed URLs
-
Value Size Limits: No validation on value sizes, which could lead to:
- Memory exhaustion attacks
- Denial of service
-
Missing Request Timeout Context: HTTP requests could hang indefinitely
Solution
Implement a reusable validation middleware that:
- Validates key is not empty and has reasonable length (e.g., max 256 bytes)
- Validates value size (e.g., max 10MB)
- Properly URL-encodes parameters in forwarded requests
- Implements request context with timeout
Files Affected
cmd/server/handlers.go
cmd/server/proxy.go
- New file:
cmd/server/validation.go
Acceptance Criteria
Problem
The current HTTP endpoints in
/cmd/server/handlers.golack comprehensive input validation and proper URL encoding, which can lead to several issues:Missing Key Validation: The GET, PUT, and DELETE handlers don't validate key parameters for:
URL Encoding Issue in forwardToLeader(): Keys and values aren't URL-encoded before forwarding to leader:
&,=,?characters will cause malformed URLsValue Size Limits: No validation on value sizes, which could lead to:
Missing Request Timeout Context: HTTP requests could hang indefinitely
Solution
Implement a reusable validation middleware that:
Files Affected
cmd/server/handlers.gocmd/server/proxy.gocmd/server/validation.goAcceptance Criteria