cwe-369-divide-by-zero

star 1

Use this skill when you need to remediate CWE-369 (Divide By Zero) vulnerabilities in Java code. Triggers on SAST findings, security reviews, or when fixing divide by zero issues.

DevelopersCoffee By DevelopersCoffee schedule Updated 3/6/2026

name: cwe-369-divide-by-zero description: Use this skill when you need to remediate CWE-369 (Divide By Zero) vulnerabilities in Java code. Triggers on SAST findings, security reviews, or when fixing divide by zero issues. version: 1.0.0 license: MIT tags:

  • security
  • java
  • cwe-369
  • remediation
  • sast

CWE-369 Divide By Zero

Description

Divide By Zero

Reference: https://cwe.mitre.org/data/definitions/369.html

OWASP Category: A03:2021 – Injection


Vulnerable Pattern

❌ Example 1: Vulnerable Pattern

// VULNERABLE: No check for zero divisor
int result = total / count;

Why it's vulnerable: This pattern is vulnerable to Divide By Zero


Deterministic Fix

✅ Secure Implementation: Secure Implementation

// SECURE: Check divisor before division
if (count == 0) {
    throw new IllegalArgumentException("Division by zero");
    // Or return default value
    // return 0;
}
int result = total / count;

Why it's secure: Implements proper protection against Divide By Zero


Detection Pattern

Look for these patterns in your codebase:

# Find division operations
grep -rn "/[^/*]\\|% " --include="*.java" | grep -v "//"

Remediation Steps

  1. Always check divisor is not zero before division

  2. Handle zero case explicitly with default value or exception


Key Imports



Verification

After remediation:

  • Run SAST scanner to confirm vulnerability is resolved

  • Review all instances of the vulnerable pattern

  • Add unit tests that verify the secure implementation

  • Check for similar patterns in related code


Trigger Examples

Fix CWE-369 vulnerability
Resolve Divide By Zero issue
Secure this Java code against divide by zero
SAST reports CWE-369

Common Vulnerable Locations

Layer Files Patterns

| Controller | *Controller.java | User input handling |

| Service | *Service.java | Business logic |

| Repository | *Repository.java | Data access |


References


Source: Generated by Java CWE Security Skills Generator Last Updated: 2026-03-07

Install via CLI
npx skills add https://github.com/DevelopersCoffee/java-cwe-security-skills --skill cwe-369-divide-by-zero
Repository Details
star Stars 1
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator
DevelopersCoffee
DevelopersCoffee Explore all skills →