Skip to content
6 changes: 5 additions & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ func setupMiddleware(app *fiber.App, sentryHandler fiber.Handler, cfg *config.Co
app.Use(logger.New(logger.Config{
Format: "[${time}] ${status} - ${latency} ${method} ${path}\n",
}))

// Log CORS origins for debugging
log.Info().Strs("cors_origins", cfg.CORSOrigins).Msg("CORS configured with origins")

app.Use(cors.New(cors.Config{
AllowOrigins: strings.Join(cfg.CORSOrigins, ","),
AllowOrigins: strings.Join(cfg.CORSOrigins, ", "),
AllowHeaders: "Origin, Content-Type, Accept, Authorization, X-API-Key",
AllowMethods: "GET, POST, PUT, DELETE, OPTIONS, PATCH",
AllowCredentials: true,
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Load() (*Config, error) {
DatabaseURL: os.Getenv("DATABASE_URL"),
RedisURL: getEnv("REDIS_URL", "localhost:6379"),
APIKey: os.Getenv("BACKEND_API_KEY"),
CORSOrigins: parseCORSOrigins(getEnv("CORS_ORIGINS", "https://nodebyte.host")),
CORSOrigins: parseCORSOrigins(getEnv("CORS_ORIGINS", "http://localhost:3000,https://nodebyte.host")),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The default CORS_ORIGINS includes http://localhost:3000. With AllowCredentials: true, this is a security risk if the environment variable is not explicitly set in production.
Severity: MEDIUM

Suggested Fix

Remove http://localhost:3000 from the default CORS_ORIGINS value. Alternatively, implement environment-aware defaults, providing a different, more restrictive set of origins for production environments compared to development. This ensures development origins are not accidentally enabled in production.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: internal/config/config.go#L72

Potential issue: The default value for `CORS_ORIGINS` was changed to include
`http://localhost:3000`. This origin is now allowed by default in all environments. The
CORS configuration in `cmd/api/main.go` has `AllowCredentials: true` hardcoded. If the
`CORS_ORIGINS` environment variable is not explicitly set in a production deployment,
the API will accept credentialed requests from `http://localhost:3000`. This is a
security misconfiguration that violates the principle of least privilege by including a
development-specific origin in the production default settings.

Did we get this right? 👍 / 👎 to inform future reviews.


// Panel settings
PterodactylURL: os.Getenv("PTERODACTYL_URL"),
Expand Down
Loading