 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>
		
	
		
			
				
	
	
		
			110 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package jwt
 | |
| 
 | |
| import (
 | |
| 	"encoding/json"
 | |
| 	"fmt"
 | |
| )
 | |
| 
 | |
| // MapClaims is a claims type that uses the map[string]any for JSON
 | |
| // decoding. This is the default claims type if you don't supply one
 | |
| type MapClaims map[string]any
 | |
| 
 | |
| // GetExpirationTime implements the Claims interface.
 | |
| func (m MapClaims) GetExpirationTime() (*NumericDate, error) {
 | |
| 	return m.parseNumericDate("exp")
 | |
| }
 | |
| 
 | |
| // GetNotBefore implements the Claims interface.
 | |
| func (m MapClaims) GetNotBefore() (*NumericDate, error) {
 | |
| 	return m.parseNumericDate("nbf")
 | |
| }
 | |
| 
 | |
| // GetIssuedAt implements the Claims interface.
 | |
| func (m MapClaims) GetIssuedAt() (*NumericDate, error) {
 | |
| 	return m.parseNumericDate("iat")
 | |
| }
 | |
| 
 | |
| // GetAudience implements the Claims interface.
 | |
| func (m MapClaims) GetAudience() (ClaimStrings, error) {
 | |
| 	return m.parseClaimsString("aud")
 | |
| }
 | |
| 
 | |
| // GetIssuer implements the Claims interface.
 | |
| func (m MapClaims) GetIssuer() (string, error) {
 | |
| 	return m.parseString("iss")
 | |
| }
 | |
| 
 | |
| // GetSubject implements the Claims interface.
 | |
| func (m MapClaims) GetSubject() (string, error) {
 | |
| 	return m.parseString("sub")
 | |
| }
 | |
| 
 | |
| // parseNumericDate tries to parse a key in the map claims type as a number
 | |
| // date. This will succeed, if the underlying type is either a [float64] or a
 | |
| // [json.Number]. Otherwise, nil will be returned.
 | |
| func (m MapClaims) parseNumericDate(key string) (*NumericDate, error) {
 | |
| 	v, ok := m[key]
 | |
| 	if !ok {
 | |
| 		return nil, nil
 | |
| 	}
 | |
| 
 | |
| 	switch exp := v.(type) {
 | |
| 	case float64:
 | |
| 		if exp == 0 {
 | |
| 			return nil, nil
 | |
| 		}
 | |
| 
 | |
| 		return newNumericDateFromSeconds(exp), nil
 | |
| 	case json.Number:
 | |
| 		v, _ := exp.Float64()
 | |
| 
 | |
| 		return newNumericDateFromSeconds(v), nil
 | |
| 	}
 | |
| 
 | |
| 	return nil, newError(fmt.Sprintf("%s is invalid", key), ErrInvalidType)
 | |
| }
 | |
| 
 | |
| // parseClaimsString tries to parse a key in the map claims type as a
 | |
| // [ClaimsStrings] type, which can either be a string or an array of string.
 | |
| func (m MapClaims) parseClaimsString(key string) (ClaimStrings, error) {
 | |
| 	var cs []string
 | |
| 	switch v := m[key].(type) {
 | |
| 	case string:
 | |
| 		cs = append(cs, v)
 | |
| 	case []string:
 | |
| 		cs = v
 | |
| 	case []any:
 | |
| 		for _, a := range v {
 | |
| 			vs, ok := a.(string)
 | |
| 			if !ok {
 | |
| 				return nil, newError(fmt.Sprintf("%s is invalid", key), ErrInvalidType)
 | |
| 			}
 | |
| 			cs = append(cs, vs)
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	return cs, nil
 | |
| }
 | |
| 
 | |
| // parseString tries to parse a key in the map claims type as a [string] type.
 | |
| // If the key does not exist, an empty string is returned. If the key has the
 | |
| // wrong type, an error is returned.
 | |
| func (m MapClaims) parseString(key string) (string, error) {
 | |
| 	var (
 | |
| 		ok  bool
 | |
| 		raw any
 | |
| 		iss string
 | |
| 	)
 | |
| 	raw, ok = m[key]
 | |
| 	if !ok {
 | |
| 		return "", nil
 | |
| 	}
 | |
| 
 | |
| 	iss, ok = raw.(string)
 | |
| 	if !ok {
 | |
| 		return "", newError(fmt.Sprintf("%s is invalid", key), ErrInvalidType)
 | |
| 	}
 | |
| 
 | |
| 	return iss, nil
 | |
| }
 |