Skip to content

VNX-1254: Incorrect Comparison Logic Granularity

A secret (a MAC, HMAC, signature, digest, hash, token, key, password, OTP.

Updated 05 Nov 2026Markdown
Field Value
Rule ID VNX-1254
Severity Low
SARIF level note
Kind sast
Languages Java
CWE CWE-1254
CAPEC CAPEC-66
ATT&CK T1190
CWSS vector CWSS:1.0/TI:L/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L
Tags timing comparison early-exit java cwe-1254
Source internal/sast/rules/vnx-1254.rego

Overview

VNX-1254 maps to CWE-1254: Incorrect Comparison Logic Granularity.

Why this matters

A loop that compares a MAC, signature or token one element at a time and returns at the first mismatch takes longer the more leading bytes are right. By timing many requests an attacker can recover a valid value byte by byte.

What gets flagged

for (int i = 0; i < expectedMac.length; i++) {
    if (expectedMac[i] != providedMac[i]) return false;
}

for (int i = 0; i < storedToken.length(); i++) {
    if (storedToken.charAt(i) != presented.charAt(i)) {
        return false;
    }
}

Not flagged: diff |= a[i] ^ b[i] followed by one test, MessageDigest.isEqual(a, b), loops over values that are not secrets.

Remediation

  1. Compare secrets with MessageDigest.isEqual(expected, actual).
  2. If you must write the loop, accumulate differences over the whole length and test once at the end.

References

Suppressing this rule

Put a nosec comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file’s language (#, //, -- or ;):

# nosec vnx-1254
// nosec vnx-1254

Or record an ignore rule: vulnetix ignore add --rule vnx-1254 --reason "...". See Suppressing findings.

esc
↑ ↓ move↵ openSearches in your browser. A key like autonomy.max or a code like threshold_required jumps straight to it.