feat(api): Add setup wizard endpoints for installer#70
Conversation
Add setup flow endpoints for the installer UI to configure: - System validation checks - Domain configuration - CORS/UI origin settings - Initial user creation Note: Dynamic CORS middleware included but may be removed if installer UI is served from same origin. Signed-off-by: nfebe <fenn25.fn@gmail.com>
Code Review SummaryThis pull request introduces a comprehensive initial setup flow for the agent, encapsulated within the new 🚀 Key Improvements
🚨 Critical Issues
|
| bytes := make([]byte, length) | ||
| if _, err := rand.Read(bytes); err != nil { | ||
| fallback := make([]byte, length) | ||
| for i := range fallback { | ||
| fallback[i] = byte(os.Getpid()>>i) ^ byte(time.Now().UnixNano()>>i) | ||
| } | ||
| return hex.EncodeToString(fallback) | ||
| } |
There was a problem hiding this comment.
The fallback for cryptoRand.Read in generateSecret uses os.Getpid() and time.Now().UnixNano(), which provide very low entropy. While cryptoRand.Read failing is rare, if it does, the generated JWT secret would be predictable, posing a significant security risk. It's generally better to let cryptoRand.Read fail and return an error for critical security functions like secret generation, rather than using a weak fallback.
| bytes := make([]byte, length) | |
| if _, err := rand.Read(bytes); err != nil { | |
| fallback := make([]byte, length) | |
| for i := range fallback { | |
| fallback[i] = byte(os.Getpid()>>i) ^ byte(time.Now().UnixNano()>>i) | |
| } | |
| return hex.EncodeToString(fallback) | |
| } | |
| func generateSecret(length int) string { | |
| bytes := make([]byte, length) | |
| if _, err := rand.Read(bytes); err != nil { | |
| // Log the error and potentially panic or return an empty string/error | |
| // to prevent using a weak secret. | |
| log.Fatalf("Failed to generate secure random bytes for JWT secret: %v", err) | |
| return "" | |
| } | |
| return hex.EncodeToString(bytes) | |
| } |
Add setup flow endpoints for the installer UI to configure:
Note: Dynamic CORS middleware included but may be removed if installer UI is served from same origin.