# Direct Map Access on Thread-Safe Struct - ID: go-direct-map-access - Severity: HIGH - CWE: Race Condition (CWE-362) - Languages: Go ## Description Direct access to map fields on structs that provide thread-safe accessor methods can cause race conditions. Use the provided accessor methods instead. ## Detection Message Direct access to map fields can cause race conditions in concurrent code. Maps in Go are not thread-safe, and concurrent reads/writes can cause runtime panics ("fatal error: concurrent map read and map write"). ## Remediation Use thread-safe accessor methods if available: ```go // Instead of: value := obj.MapField["key"] value, ok := obj.GetAttr("key") // Instead of: obj.MapField["key"] = value obj.SetAttr("key", value) ``` Or protect with mutex: ```go mu.RLock() value := obj.MapField["key"] mu.RUnlock() ``` ## Documentation [object Object] ## Related Rules - **Concurrent Slice Access** [HIGH]: - **Potential Race Condition** [MEDIUM]: - **WaitGroup Misuse** [HIGH]: - **Race Condition in Concurrent Operations** [HIGH]: - **Potential Race Condition** [MEDIUM]: