 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>
		
	
		
			
				
	
	
		
			79 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package nkeys
 | |
| 
 | |
| import (
 | |
| 	"bytes"
 | |
| 	"regexp"
 | |
| 	"strings"
 | |
| )
 | |
| 
 | |
| var userConfigRE = regexp.MustCompile(`\s*(?:(?:[-]{3,}.*[-]{3,}\r?\n)([\w\-.=]+)(?:\r?\n[-]{3,}.*[-]{3,}\r?\n))`)
 | |
| 
 | |
| // ParseDecoratedJWT takes a creds file and returns the JWT portion.
 | |
| func ParseDecoratedJWT(contents []byte) (string, error) {
 | |
| 	items := userConfigRE.FindAllSubmatch(contents, -1)
 | |
| 	if len(items) == 0 {
 | |
| 		return string(contents), nil
 | |
| 	}
 | |
| 	// First result should be the user JWT.
 | |
| 	// We copy here so that if the file contained a seed file too we wipe appropriately.
 | |
| 	raw := items[0][1]
 | |
| 	tmp := make([]byte, len(raw))
 | |
| 	copy(tmp, raw)
 | |
| 	return strings.TrimSpace(string(tmp)), nil
 | |
| }
 | |
| 
 | |
| // ParseDecoratedNKey takes a creds file, finds the NKey portion and creates a
 | |
| // key pair from it.
 | |
| func ParseDecoratedNKey(contents []byte) (KeyPair, error) {
 | |
| 	var seed []byte
 | |
| 
 | |
| 	items := userConfigRE.FindAllSubmatch(contents, -1)
 | |
| 	if len(items) > 1 {
 | |
| 		seed = items[1][1]
 | |
| 	} else {
 | |
| 		lines := bytes.Split(contents, []byte("\n"))
 | |
| 		for _, line := range lines {
 | |
| 			if bytes.HasPrefix(bytes.TrimSpace(line), []byte("SO")) ||
 | |
| 				bytes.HasPrefix(bytes.TrimSpace(line), []byte("SA")) ||
 | |
| 				bytes.HasPrefix(bytes.TrimSpace(line), []byte("SU")) {
 | |
| 				seed = line
 | |
| 				break
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	if seed == nil {
 | |
| 		return nil, ErrNoSeedFound
 | |
| 	}
 | |
| 	if !bytes.HasPrefix(seed, []byte("SO")) &&
 | |
| 		!bytes.HasPrefix(seed, []byte("SA")) &&
 | |
| 		!bytes.HasPrefix(seed, []byte("SU")) {
 | |
| 		return nil, ErrInvalidNkeySeed
 | |
| 	}
 | |
| 	kp, err := FromSeed(seed)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return kp, nil
 | |
| }
 | |
| 
 | |
| // ParseDecoratedUserNKey takes a creds file, finds the NKey portion and creates a
 | |
| // key pair from it. Similar to ParseDecoratedNKey but fails for non-user keys.
 | |
| func ParseDecoratedUserNKey(contents []byte) (KeyPair, error) {
 | |
| 	nk, err := ParseDecoratedNKey(contents)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	seed, err := nk.Seed()
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	if !bytes.HasPrefix(seed, []byte("SU")) {
 | |
| 		return nil, ErrInvalidUserSeed
 | |
| 	}
 | |
| 	kp, err := FromSeed(seed)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return kp, nil
 | |
| }
 |