···
"github.com/go-chi/chi/v5"
···
instanceDID = "did:web:coves.local" // Default for development
119
-
communityService := communities.NewCommunityService(communityRepo, didGenerator, defaultPDS, instanceDID)
121
+
// V2: Extract instance domain for community handles
122
+
// IMPORTANT: This MUST match the domain in INSTANCE_DID for security
123
+
// We cannot allow arbitrary domains to prevent impersonation attacks
124
+
// Example attack: !leagueoflegends@riotgames.com on a non-Riot instance
125
+
var instanceDomain string
126
+
if strings.HasPrefix(instanceDID, "did:web:") {
127
+
// Extract domain from did:web (this is the authoritative source)
128
+
instanceDomain = strings.TrimPrefix(instanceDID, "did:web:")
130
+
// For non-web DIDs (e.g., did:plc), require explicit INSTANCE_DOMAIN
131
+
instanceDomain = os.Getenv("INSTANCE_DOMAIN")
132
+
if instanceDomain == "" {
133
+
log.Fatal("INSTANCE_DOMAIN must be set for non-web DIDs")
137
+
log.Printf("Instance domain: %s (extracted from DID: %s)", instanceDomain, instanceDID)
139
+
// V2: Initialize PDS account provisioner for communities
140
+
provisioner := communities.NewPDSAccountProvisioner(userService, instanceDomain, defaultPDS)
142
+
communityService := communities.NewCommunityService(communityRepo, didGenerator, defaultPDS, instanceDID, instanceDomain, provisioner)
// Authenticate Coves instance with PDS to enable community record writes
// The instance needs a PDS account to write community records it owns