# VNX-347: Improper Verification of Cryptographic Signature

A signature or MAC check whose result is discarded, or whose failure is caught and swallowed, so forged data is processed as genuine. Java, Go.

| Field | Value |
|---|---|
| Rule ID | `VNX-347` |
| Severity | High |
| SARIF level | `error` |
| Kind | `sast` |
| Languages | Go, Java, JavaScript / TypeScript, Python |
| CWE | [CWE-347](https://cwe.mitre.org/data/definitions/347.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:H/AP:A/AL:A/IC:N/FC:LT/RP:N/RL:A/AV:I/AS:N/IN:A/SC:A/BI:H/DI:H/EX:H/EC:N/P:H` |
| Tags | `signature` `crypto` `cwe-347` |
| Source | [`internal/sast/rules/vnx-347.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-347.rego) |

## Overview

VNX-347 maps to [CWE-347: Improper Verification of Cryptographic Signature](https://cwe.mitre.org/data/definitions/347.html). It reports code that runs a signature or MAC check and then ignores the outcome:

- **Result discarded** (the call is a bare statement): Java `java.security.Signature.verify()`; Go `ed25519.Verify`, `ecdsa.Verify`/`VerifyASN1`, `hmac.Equal`, `subtle.ConstantTimeCompare`, `rsa.VerifyPKCS1v15`/`VerifyPSS` (also assigned to `_`); Node.js `verify()` on a `createVerify()` object, `crypto.verify()` without a callback, `crypto.timingSafeEqual()`, `crypto.subtle.verify()`, the jws package's boolean `jws.verify()`; Python `hmac.compare_digest()`.
- **Failure swallowed**: Python `except InvalidSignature`/`BadSignature`/`BadSignatureError`/`InvalidSignatureError` (or a bare/`Exception` handler around a `.verify()` statement) whose body is only `pass`, `...` or a log call; Java `catch (SignatureException | SignatureVerificationException | InvalidSignatureException | JWTVerificationException | JwtException ...)` (or `Exception` around a `.verify()` statement) whose block is empty or only logs.

## Why this matters

A verification that nobody checks is no verification: a forged update, webhook, licence or token is accepted exactly as a genuine one. The bug survives review because the verify call is visibly there.

Not reported: a Python handler whose `try` body only assigns the verified value to names set to `None`/`False`/empty just above it (`user_id = None; try: user_id = s.loads(v) except BadSignature: pass` fails closed; a default holding the unverified input is still reported); results that are tested, assigned, returned or passed on (including an assignment split over two lines); calls that throw on failure (jsonwebtoken `jwt.verify`, auth0 `JWTVerifier.verify`) outside a swallowing handler; `crypto.verify` with a callback; handlers that raise, return or rethrow; empty catches around code that verifies nothing; comments and string literals. Disabled TLS certificate validation is [VNX-CRYPTO-005](/sast/rules/vnx-crypto-005.md)'s concern and disabled JWT verification [VNX-JWT-001](/sast/rules/vnx-jwt-001.md)'s.

## What gets flagged

```java
sig.update(payload);
sig.verify(sigBytes);
return payload;
```

```go
ed25519.Verify(pub, body, sig)
_ = rsa.VerifyPKCS1v15(pub, crypto.SHA256, digest, sig)
```

```javascript
verifier.verify(publicKey, signature, "base64");
crypto.timingSafeEqual(digest, Buffer.from(req.get("X-Signature"), "hex"));
```

```python
try:
    public_key.verify(signature, blob)
except InvalidSignature:
    pass
```

## Remediation

1. Test the result and stop on failure: `if (!sig.verify(s)) throw ...`, `if !ed25519.Verify(...) { return err }`, `if not hmac.compare_digest(...): abort(401)`.
2. In a handler for a signature failure, reject the input: raise, return an error, or abort the request.

## References

- [CWE-347: Improper Verification of Cryptographic Signature](https://cwe.mitre.org/data/definitions/347.html)
- [CWE-252: Unchecked Return Value](https://cwe.mitre.org/data/definitions/252.html)

## 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 `;`):

```text
# nosec vnx-347
// nosec vnx-347
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-347 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
