# VNX-1070: Serializable Data Element Containing non-Serializable Item Elements

An instance field of a JDK type that is never serializable (Thread, Socket, streams, JDBC Connection, ExecutorService, Optional, Logger and similar).

| Field | Value |
|---|---|
| Rule ID | `VNX-1070` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | Java |
| CWE | [CWE-1070](https://cwe.mitre.org/data/definitions/1070.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: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 | `serializable-data-element` `cwe-1070` |
| Source | [`internal/sast/rules/vnx-1070.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-1070.rego) |

## Overview

VNX-1070 maps to [CWE-1070: Serializable Data Element Containing non-Serializable Item Elements](https://cwe.mitre.org/data/definitions/1070.html). Inside a Java class whose own header implements `Serializable` (the nearest enclosing class declaration), it reports an instance field declared with an access modifier (after any annotations, with one or several names), neither `static` nor `transient`, whose type is a JDK type that is never serializable: `Thread`, sockets and socket channels, `InputStream`/`OutputStream`, `Reader`/`Writer` and their common subclasses, JDBC `Connection`/`Statement`/`ResultSet`/`DataSource`, `EntityManager`, `ExecutorService`/`Executor`, `Optional` and `Stream`, `Logger`, `HttpClient`, `URLConnection`, `Process`, `ClassLoader`.

It does not report static or transient fields, fields of another class in the same file that is not `Serializable`, classes that are serializable only through a superclass, a simple name imported from a non-JDK package (`com.acme.Process`, `org.slf4j.Logger`), the JDBC names (`Connection`, `Statement`, `ResultSet`, `DataSource`) in a file that never mentions `java.sql`/`javax.sql` (a bank `Statement`), local variables, package-private fields with no modifier (a documented gap), project-defined types (whose serializability one file cannot show), comments or string literals.

## Why this matters

Serialising the object throws `NotSerializableException` at run time, typically when a session is replicated or a message is queued, or silently loses the resource when a custom `writeObject` skips it.

## What gets flagged

```java
public class Session implements Serializable {
    private Socket socket;                                         // FLAGGED
    private Optional<String> nickname = Optional.empty();          // FLAGGED
    private volatile Thread refresher;                             // FLAGGED
    @JsonIgnore private Logger auditLog = Logger.getLogger("a");  // FLAGGED
    private static final Logger LOG = Logger.getLogger("s");       // not flagged (static)
    private transient Connection connection;                       // not flagged (transient)
}
```

## Remediation

1. Mark the field `transient` and re-create it in `readObject` or lazily on first use.
2. Or keep only serializable state (the host and port, not the socket).

## References

- [CWE-1070: Serializable Data Element Containing non-Serializable Item Elements](https://cwe.mitre.org/data/definitions/1070.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-1070
// nosec vnx-1070
```

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