Join our Newsletter — 33% off our NHI Course

What causes a serialisable class containing sensitive data?

It happens when a serialisable class includes secrets that can be written to streams, files, or messages. Serialisation can spread sensitive data beyond its intended boundary and leave it available to attackers or unintended recipients. Exclude secrets from serialised state, encrypt where required, and review what fields are actually transferred.

Why a serialisable class becomes a sensitive-data problem

A class becomes risky when its serialisable fields include secrets, credentials, tokens, personal data, or other information that should not leave process memory. Once that object is written out, the data can be duplicated into logs, caches, message queues, or snapshots, which expands the exposure surface far beyond the original runtime boundary.

The important issue is not serialization itself, but what the object graph contains and where it can travel. A class that was safe in memory can become unsafe if its default serialisation path captures fields that were never intended for persistence or transport.

That is why sensitive state should be treated as an explicit design decision. If a field is only needed at runtime, keep it out of serialised state, or make sure the serialisation format deliberately excludes it.

What usually causes the exposure

The most common cause is accidental inclusion of sensitive fields in the serialised representation. That can happen through default serialization, helper libraries that serialise every property, or object models that mix operational data with secrets and session material.

Another frequent cause is assuming that a field is transient in practice when it is not. If developers do not review which members are actually emitted, the class may preserve passwords, API keys, session identifiers, access tokens, private keys, or internal configuration values that later appear in files or messages.

CWE Top 25 Guide is useful here because the weakness is often a failure to control what information leaves the object boundary, not a flaw in the serializer alone. For practitioners, the check is whether the serialised form contains anything that should remain secret, minimal, or ephemeral.

How to reduce the chance of leakage

Start by separating sensitive runtime data from state that is meant to persist or transit. Use explicit field selection, custom serialization rules, or DTO-style models so that only approved data is transferred.

Where sensitive content must be stored or moved, protect it with encryption and strict key handling rather than relying on obscurity. Encryption Guide is the right companion when the design requires sensitive data to cross trust boundaries, while Tokenisation and Data Masking Guide helps when the better answer is to replace the secret with a non-sensitive surrogate.

Reviewing serialization should be part of secure coding, because a class can be functionally correct yet still leak more than it should. The safest design is usually the one that serialises the smallest possible representation and reconstructs sensitive values only when absolutely necessary.

Risk and Threat Considerations

Serialised sensitive data creates a durable copy that can outlive the original process, move across systems, and be recovered later from storage, backups, queues, or debug artefacts. That makes accidental leakage and post-compromise retrieval the two main hazards.

Failure mechanism: The object model includes fields that are written automatically or too broadly, so secrets leave the intended trust boundary and remain readable in downstream artefacts.

Impact: Attackers or unintended recipients can recover credentials, tokens, or other sensitive values and use them for impersonation, lateral access, or data exposure.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP ASVS and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
OWASP ASVS V14 — Data Protection Sensitive fields in serialized objects are a data protection issue.
Recommendation — Minimise serialized fields and protect sensitive values before they leave the process boundary.
NIST SP 800-53 Rev 5 SC-28 — Protection of Information at Rest Serialized data is often stored or queued and needs protection at rest.
IA-5 — Authenticator Management Secrets in serializable state often include authenticators that must be controlled.
Recommendation — Encrypt stored serialized data and protect the medium that holds it. Exclude authenticators from serialised state and rotate any exposed secret material.

Practitioner Guidance

What to verify: Confirm the exact serialized payload, not just the source class definition. Test what reaches disk, the wire, logs, queues, and replay tools, because that is where hidden leakage usually appears.

Common mistake: Treating “encrypted somewhere downstream” as a substitute for minimising the serialised object. Encryption helps, but it does not fix unnecessary disclosure of sensitive fields to every consumer in the path.

Practitioner takeaway: The decisive control is scope, only serialise what another system truly needs, and treat every extra field as a potential secret exposure until proven otherwise.