 131868bdca
			
		
	
	131868bdca
	
	
	
		
			
			Major security, observability, and configuration improvements:
## Security Hardening
- Implemented configurable CORS (no more wildcards)
- Added comprehensive auth middleware for admin endpoints
- Enhanced webhook HMAC validation
- Added input validation and rate limiting
- Security headers and CSP policies
## Configuration Management
- Made N8N webhook URL configurable (WHOOSH_N8N_BASE_URL)
- Replaced all hardcoded endpoints with environment variables
- Added feature flags for LLM vs heuristic composition
- Gitea fetch hardening with EAGER_FILTER and FULL_RESCAN options
## API Completeness
- Implemented GetCouncilComposition function
- Added GET /api/v1/councils/{id} endpoint
- Council artifacts API (POST/GET /api/v1/councils/{id}/artifacts)
- /admin/health/details endpoint with component status
- Database lookup for repository URLs (no hardcoded fallbacks)
## Observability & Performance
- Added OpenTelemetry distributed tracing with goal/pulse correlation
- Performance optimization database indexes
- Comprehensive health monitoring
- Enhanced logging and error handling
## Infrastructure
- Production-ready P2P discovery (replaces mock implementation)
- Removed unused Redis configuration
- Enhanced Docker Swarm integration
- Added migration files for performance indexes
## Code Quality
- Comprehensive input validation
- Graceful error handling and failsafe fallbacks
- Backwards compatibility maintained
- Following security best practices
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
		
	
		
			
				
	
	
		
			63 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package middleware
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"net/http"
 | |
| 
 | |
| 	"github.com/go-chi/chi/v5"
 | |
| )
 | |
| 
 | |
| // StripSlashes is a middleware that will match request paths with a trailing
 | |
| // slash, strip it from the path and continue routing through the mux, if a route
 | |
| // matches, then it will serve the handler.
 | |
| func StripSlashes(next http.Handler) http.Handler {
 | |
| 	fn := func(w http.ResponseWriter, r *http.Request) {
 | |
| 		var path string
 | |
| 		rctx := chi.RouteContext(r.Context())
 | |
| 		if rctx != nil && rctx.RoutePath != "" {
 | |
| 			path = rctx.RoutePath
 | |
| 		} else {
 | |
| 			path = r.URL.Path
 | |
| 		}
 | |
| 		if len(path) > 1 && path[len(path)-1] == '/' {
 | |
| 			newPath := path[:len(path)-1]
 | |
| 			if rctx == nil {
 | |
| 				r.URL.Path = newPath
 | |
| 			} else {
 | |
| 				rctx.RoutePath = newPath
 | |
| 			}
 | |
| 		}
 | |
| 		next.ServeHTTP(w, r)
 | |
| 	}
 | |
| 	return http.HandlerFunc(fn)
 | |
| }
 | |
| 
 | |
| // RedirectSlashes is a middleware that will match request paths with a trailing
 | |
| // slash and redirect to the same path, less the trailing slash.
 | |
| //
 | |
| // NOTE: RedirectSlashes middleware is *incompatible* with http.FileServer,
 | |
| // see https://github.com/go-chi/chi/issues/343
 | |
| func RedirectSlashes(next http.Handler) http.Handler {
 | |
| 	fn := func(w http.ResponseWriter, r *http.Request) {
 | |
| 		var path string
 | |
| 		rctx := chi.RouteContext(r.Context())
 | |
| 		if rctx != nil && rctx.RoutePath != "" {
 | |
| 			path = rctx.RoutePath
 | |
| 		} else {
 | |
| 			path = r.URL.Path
 | |
| 		}
 | |
| 		if len(path) > 1 && path[len(path)-1] == '/' {
 | |
| 			if r.URL.RawQuery != "" {
 | |
| 				path = fmt.Sprintf("%s?%s", path[:len(path)-1], r.URL.RawQuery)
 | |
| 			} else {
 | |
| 				path = path[:len(path)-1]
 | |
| 			}
 | |
| 			redirectURL := fmt.Sprintf("//%s%s", r.Host, path)
 | |
| 			http.Redirect(w, r, redirectURL, 301)
 | |
| 			return
 | |
| 		}
 | |
| 		next.ServeHTTP(w, r)
 | |
| 	}
 | |
| 	return http.HandlerFunc(fn)
 | |
| }
 |