# NULL Pointer Dereference (CWE-476) A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL. **Stack:** Go - Prevalence: 보통 2개 언어 지원 - Impact: 보통 검토 권장 - Prevention: 문서화됨 2개의 수정 예시 **OWASP:** Insecure Design (A04:2021-Insecure Design) - #4 ## Description NULL pointer dereferences typically cause the application to crash. In some cases, they may be exploitable for denial of service or potentially for code execution. ## Prevention ### Go Use the two-value form of type assertion or type switch to handle failures gracefully ## Consequences - DoS: 충돌/종료/재시작 ## Mitigations - 포인터를 역참조하기 전에 확인하세요 - 널 포인터 문제를 방지하는 언어 기능을 활용하세요 - null 반환에 대한 적절한 오류 처리를 구현하세요 ## Detection - Total rules: 2 - Languages: go, typescript ## Rules by Language ### Go (1 rules) - **Unsafe Type Assertion Without Ok Check** [MEDIUM]: Type assertion without two-value form can panic at runtime. - Remediation: Use the two-value form of type assertion to handle failures gracefully. ```go result, ok := data.(map[string]interface{}) if !ok { return errors.New("invalid data type") } ``` Learn more: https://shoulder.dev/learn/go/cwe-476/unsafe-type-assertion