Secret leaks through serialization

Finds secrets that leak when a credential field on a dataclass, pydantic model or JS object meets code that logs or traces whole objects, searching the whole repository for the other half. Use when a change adds such a field or a wholesale sink.

SecurityPack: Sentry skills119 linessecret-serialization
Author
Source
getsentry/skills/skills/secret-serialization @ a582c51
License
Apache-2.0 · Copyright 2025 Functional Software, Inc. dba Sentry

About this skill

What it does

The skill finds credentials that leak because an object serializes itself and other code serializes whole objects. The leak has two halves that look harmless alone: a holder (a secret stored on a type with generated repr, asdict or model_dump) and a sink (a log, span, error report, cache or response that writes whole objects or every kwarg). Since the halves are often written months apart, it reports either one and searches the whole repository for the other.

A table shows what blocks which path: field(repr=False) hides a dataclass field from repr but not asdict; Pydantic needs both repr=False and exclude=True; JavaScript #private blocks everything, TypeScript private nothing. vars(), __dict__ and pickle reach every stored value and are fixed at the sink.

A finding is high when the secret reaches a sink anywhere, even if one half predates the diff. Each comes with a fix and a test asserting the secret is absent from the sink's serializer output.

references/python.md and references/javascript-typescript.md hold per-language tables and examples, from pydantic and the Sentry SDK to util.inspect and pino. SOURCES.md traces the skill to a Sentry incident where a shared secret reached tracing spans; SPEC.md is the maintainers' contract. Its frontmatter allows only Read, Grep, Glob.

When to use it, and when not

Use it when a change puts a credential on a dataclass, model or client object, or logs or traces whole objects. Python and JavaScript/TypeScript only.

Sentry's spec calls it opt-in: it flags an unprotected field before any sink is found, which is noisy as a default review. Hardcoded secrets, .env files and tokens written straight into log lines are out of scope.

How to run it

The install command below puts the folder in place. The agent picks the skill up by its description; to call it yourself:

  • Claude Code: /secret-serialization, or ask for the skill by name.
  • Codex: $secret-serialization.
  • Cursor: type / in the Agent chat and pick secret-serialization.

Example: /secret-serialization The webhook secret moved onto the client dataclass; can it reach spans or logs?

How it differs from similar skills

Security review, Sentry takes the direct leaks this skill leaves out; the split is deliberate. Env and config audit from our catalog finds hardcoded secrets and checks git history. Security review from our catalog lists secrets in logs as one checklist item; it has the same security-review name as Sentry's, so only one of the two fits in a skills folder.

Install

Run one command — it saves SKILL.md and the files it uses into your agent's skills folder. Claude Code and Codex pick up a new skill without a restart; if it does not show up, restart the agent.

Claude Code — macOS, Linux
curl -fsSL --create-dirs -o ~/.claude/skills/secret-serialization/SKILL.md https://anymodel.org/en/skills/sentry/secret-serialization/SKILL.md -o ~/.claude/skills/secret-serialization/LICENSE https://anymodel.org/en/skills/sentry/secret-serialization/LICENSE -o ~/.claude/skills/secret-serialization/SOURCES.md https://anymodel.org/en/skills/sentry/secret-serialization/SOURCES.md -o ~/.claude/skills/secret-serialization/SPEC.md https://anymodel.org/en/skills/sentry/secret-serialization/SPEC.md -o ~/.claude/skills/secret-serialization/references/javascript-typescript.md https://anymodel.org/en/skills/sentry/secret-serialization/references/javascript-typescript.md -o ~/.claude/skills/secret-serialization/references/python.md https://anymodel.org/en/skills/sentry/secret-serialization/references/python.md
Codex, Cursor — macOS, Linux
curl -fsSL --create-dirs -o ~/.agents/skills/secret-serialization/SKILL.md https://anymodel.org/en/skills/sentry/secret-serialization/SKILL.md -o ~/.agents/skills/secret-serialization/LICENSE https://anymodel.org/en/skills/sentry/secret-serialization/LICENSE -o ~/.agents/skills/secret-serialization/SOURCES.md https://anymodel.org/en/skills/sentry/secret-serialization/SOURCES.md -o ~/.agents/skills/secret-serialization/SPEC.md https://anymodel.org/en/skills/sentry/secret-serialization/SPEC.md -o ~/.agents/skills/secret-serialization/references/javascript-typescript.md https://anymodel.org/en/skills/sentry/secret-serialization/references/javascript-typescript.md -o ~/.agents/skills/secret-serialization/references/python.md https://anymodel.org/en/skills/sentry/secret-serialization/references/python.md
Claude Code — Windows PowerShell
foreach ($f in 'SKILL.md','LICENSE','SOURCES.md','SPEC.md','references/javascript-typescript.md','references/python.md') { $p = Join-Path "$HOME\.claude\skills\secret-serialization" $f; New-Item -ItemType Directory -Force (Split-Path $p) | Out-Null; Invoke-WebRequest "https://anymodel.org/en/skills/sentry/secret-serialization/$f" -UseBasicParsing -OutFile $p }
Codex, Cursor — Windows PowerShell
foreach ($f in 'SKILL.md','LICENSE','SOURCES.md','SPEC.md','references/javascript-typescript.md','references/python.md') { $p = Join-Path "$HOME\.agents\skills\secret-serialization" $f; New-Item -ItemType Directory -Force (Split-Path $p) | Out-Null; Invoke-WebRequest "https://anymodel.org/en/skills/sentry/secret-serialization/$f" -UseBasicParsing -OutFile $p }

Any other agent: save the file into its skills folder, or give it the link to the file: https://anymodel.org/en/skills/sentry/secret-serialization/SKILL.md

SKILL.md

Raw

Secret Serialization Review

Find credentials that can leak because a type serializes itself and something upstream serializes whole objects.

A leak usually needs two changes that each look safe alone:

  1. Holder: a credential is stored as a field on a type with generated repr, str, asdict, model_dump, toJSON, or property enumeration.
  2. Sink: logging, tracing, error reporting, caching, or a response serializes whole objects or every kwarg (str(value), span.set_data(key, obj), logger.info("%s", obj), JSON.stringify(args)).

The two sides are often written months apart by different authors. Report either side on its own. Always search the existing tree for the other side, because it is frequently already on the default branch and absent from the diff.

Boundary

  • This skill covers indirect leaks through generated serialization and wholesale sinks.
  • Direct leaks, such as interpolating a token into a log message, belong to security-review. Report them here only when they come from a changed wholesale sink.
  • Hardcoded secret literals and committed .env files are out of scope.

References

Reference Read When
references/python.md Reviewing Python dataclasses, attrs, pydantic, NamedTuple, msgspec, logging, Sentry SDK, or OpenTelemetry code
references/javascript-typescript.md Reviewing JavaScript or TypeScript classes, config objects, JSON.stringify, util.inspect, pino or winston, or Sentry and OpenTelemetry spans

Credential Fields

Treat a field as credential-bearing when its name, type, or source says so:

  • Names containing secret, token, password, passwd, pwd, api_key, apikey, access_key, private_key, signing_key, client_secret, bearer, credential, authorization, auth_header, cookie, session_key, dsn, connection_string, webhook_secret, hmac, or refresh_token.
  • Types such as SecretStr, SecretBytes, or wrappers around them.
  • Values assigned from environment variables, a secrets manager, or a constructor argument named like the above.

Explicit Exclusion

Separate two kinds of path:

  • Generated paths are produced by the type itself: __repr__ and __str__, asdict, model_dump, toJSON, and own-enumerable-property walks (JSON.stringify, util.inspect, spread). They are the holder's responsibility.
  • Raw attribute access reads the stored value directly: vars(obj), obj.__dict__, pickle, json.dumps(obj, default=vars). Every stored attribute is exposed this way, whatever flags the field has. Treat these only as sinks: report them when a sink in the repository applies one to a credential-bearing instance.

A field is fully excluded when every generated path its type has is blocked, whether by one mechanism or several together. A field is partially excluded when at least one generated path still includes it. No field-level mechanism defeats raw attribute access. Only not storing the value does, so fix raw attribute findings at the sink.

Mechanism Blocks Still includes the field
dataclasses.field(repr=False), attrs.field(repr=False) __repr__, __str__ asdict, astuple, raw access
Pydantic Field(repr=False) __repr__, __str__ model_dump, model_dump_json, response serialization, raw access
Pydantic Field(exclude=True) model_dump, model_dump_json, response serialization __repr__, __str__, raw access
Pydantic Field(repr=False, exclude=True) Every generated path Raw access
JavaScript #private field Every generated path Nothing outside the class body
Object.defineProperty(..., { enumerable: false }) Every generated path Explicit property reads, Object.getOwnPropertyNames
Hand-written __repr__, __str__, toJSON, or [util.inspect.custom] that omits the field Only the path it overrides (a __repr__ also serves str() when there is no __str__) Every other generated path, raw access
Redacting wrapper: SecretStr, SecretBytes, a project Redacted[T] Every generated path pickle and recursive __dict__ walks such as default=vars, which reach the value stored inside the wrapper
Not stored on the object: read inside the method, or held in a closure Everything Nothing

Do not treat underscore naming, TypeScript private, __slots__, type annotations, comments, dataclass(init=False), or a custom __init__ that still assigns the field as blocking any path.

Investigation Process

  1. Read the changed hunk. Find new or modified credential fields on auto-serializing types, and new or modified code that serializes objects or kwargs into logs, spans, error context, caches, queues, or responses.
  2. For each credential field, read the full class, decorators, base classes, and model config. List every generated path and check which ones the field's mechanisms block, using the table above.
  3. Grep for where instances are constructed and passed. Instances handed to decorators, **kwargs, tool call arguments, task payloads, or middleware reach generic sinks.
  4. Grep the whole repository for sinks that can see those instances, not only the diff. Useful patterns: str(value), repr(, asdict(, model_dump(, set_data(, set_attribute(, set_context(, set_extra(, JSON.stringify(, util.inspect(, loggers called with objects, and raw attribute access (vars(, __dict__, pickle.dumps(, default=vars).
  5. For each changed sink, check for a key allowlist, redaction keyed on credential names, or a filter that replaces objects with their type name. Then grep for callers that pass credential-bearing objects into it.
  6. Look at tests only to see whether one asserts the credential is absent from the serialized form. A missing test is fix guidance, not a finding.
  7. Confirm the code ships. Skip fixtures, examples, generated code, and test-only helpers.

What To Report

Category Report When
Unexcluded credential field A credential field is added or moved onto a type with generated serialization, and no mechanism blocks any of its generated paths.
Partial exclusion At least one generated path still includes the field, and a sink in the repository uses that path on instances of the type.
Raw attribute sink A sink applies vars, __dict__, pickle, or default=vars to an instance that stores a credential, even if the field is fully excluded or wrapped.
Credential moved onto a holder A refactor moves a credential from a lazy read or closure onto an object field.
Wholesale serialization sink New or changed telemetry, logging, error-context, cache, or response code serializes every kwarg, every attribute, or whole objects without an allowlist or redaction.
Sink loses its filter A change removes or weakens redaction, an allowlist, or object-to-type-name replacement in an existing sink.
Object passed to telemetry A client, config, or settings object is passed to a span, log, or error-context call that stringifies it.

Severity

Level Use For
high The credential reaches a sink anywhere in the repository: log line, span attribute, error event, cache entry, persisted row, queue payload, or API response. The other side may predate the diff. Also a new wholesale sink whose existing callers pass credential-bearing objects.
medium An unexcluded credential field whose instances leave the constructing module, after a repository search found no sink. Also a wholesale sink with no allowlist and no traced credential-bearing caller.
low An unexcluded credential field whose instances never leave the constructing scope.
  • Do not downgrade because the sink or the holder is outside the diff. That is the normal shape of this bug.
  • Choose the lower severity when reachability depends on unproven preconditions.

What Not To Report

  • Fully excluded fields, unless a raw attribute sink receives the instance.
  • Partial exclusions when no sink in the repository uses the unblocked path.
  • Credentials read inside a method and never stored on the instance.
  • Placeholder or fake values in tests, fixtures, or examples.
  • Types with no generated serialization and no __dict__ or enumeration sink.
  • Sinks that already allowlist scalar keys, redact by credential name, or replace objects with a type name.
  • Pre-existing fields and sinks the diff does not touch, unless the diff connects them.
  • Style, naming, or missing-test-only observations.

Fix Guidance

Include one concrete fix per finding:

  • Holder: block every generated path, wrap the value in a redacting type, or stop storing it on the object.
  • Raw attribute sink: serialize an explicit allowlisted dict instead of the instance, or stop storing the credential on it. A field flag or wrapper does not fix it.
  • Sink: allowlist scalar keys, redact keys matching credential names, and record type(value).__name__ instead of str(value) for non-scalar values.
  • Regression test: serialize an instance with the same serializer the sink uses (for example sentry_sdk.serializer.serialize, json.dumps(asdict(obj)), JSON.stringify(obj), util.inspect(obj)) and assert the credential string is absent.

Finding Format

  • Title: name the field or sink and the leak path, for example "_shared_secret included in RpcClient dataclass repr".
  • Description: one or two sentences naming the generated path that exposes the credential, where instances travel, and the fix.
  • Evidence: 2 to 5 bullets naming the class, decorator, generated paths checked, the exclusion looked for, and every sink or caller traced, including those outside the diff.

Connect through AnyModel API

This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.

More from the pack Sentry skills

AGENTS.md and CLAUDE.md writer

Writes or trims a repository's AGENTS.md to under 60 lines of commands, conventions and pointers to existing docs, checks every path, and makes CLAUDE.md a symlink to it. Use when a repo needs agent instructions or its current file has grown long or stale.

Claude Code settings audit

Detects a repository's stack and proposes a Claude Code settings.json allow list of read-only commands for the tools it actually uses, plus docs domains and Sentry or Linear MCP entries. Use when setting up Claude Code permissions or auditing existing ones.

Code review, Sentry practices

Reviews a change by Sentry's guidelines: runtime errors, performance and N+1 queries, side effects, compatibility, security, design and tests, with a polite tone and approval once only minor issues remain. Use when reviewing a pull request or branch.

Code simplifier

Simplifies recently changed code without changing behaviour: less nesting, no nested ternaries, clearer names, no redundant abstractions, while following CLAUDE.md conventions. Use when code works but reads heavier than it should and needs a cleanup pass.

Conventional commit messages

Commits in Sentry's Conventional Commits style: a feature branch instead of main, a typed capitalised subject up to 70 characters, Fixes or Refs footers, no personal data. Use when asked to commit changes or draft a commit message.

Django access control review

Audits Django and DRF code for IDOR and broken access control by learning the app's authorization model and tracing each endpoint from ID to query, reporting only confirmed gaps with enforcing fixes. Use when reviewing views, viewsets or tenant isolation.

Find bugs in branch changes

Reviews the commits on the current branch for security holes, bugs and quality issues with an eleven-item checklist and reports verified findings with file, line, severity and fix, without editing code. Use when you want a security-first pass before a PR.

GitHub Actions security review

Audits GitHub Actions workflows for attacks an outsider without write access can run: pwn requests, expression injection, comment commands, token theft, poisoned agent configs, unpinned actions. Use when reviewing CI security or changing workflows.

Iterate a PR until CI is green

Drives an open PR to green: fixes failing CI and high and medium review comments, verifies locally, commits, pushes and repeats, stopping at human approval or draft gates. Use when a PR is red or has review feedback to work through.

PR title and description writer

Writes or refreshes a PR title in Sentry's conventional format and a short reviewer-facing description without template headings or test logs, then opens a draft or updates the PR. Use when opening a PR or after commits change its scope.

Prompt optimizer

Writes, repairs or ports system and agent prompts against a small eval set, comparing candidate rewrites on the same cases and checking the winner on held-out ones. Use when a prompt is unreliable, moves to another model family or needs evals.

SECURITY_MODEL.md for review tools

Writes and maintains SECURITY_MODEL.md, telling security review tools a repository's exposure, invariants, reportable finding classes and owner-confirmed exclusions, with a script that flags stale references. Use when preparing a repo for automated review.

Agent skill security scanner

Audits an agent skill before installation: a static scan for prompt injection, hidden Unicode, secrets, risky scripts and structural traps, then a review of intent and permissions ending in a verdict. Use when a skill comes from an outside source.

Skill writer by the Agent Skills spec

Creates and improves agent skills by Sentry's workflow: sources with provenance, the simplest execution shape, SPEC.md and SOURCES.md, precision passes after each change and a structural validator. Use when building a skill that a team will maintain.

Security review, Sentry

Reviews a file, diff or component for exploitable vulnerabilities with OWASP-based references, researches the codebase before flagging and reports only findings reached by attacker-controlled input. Use when a change needs a low-noise security review.

Django performance review

Reviews Django and DRF code for N+1 queries, unbounded querysets, missing indexes and write loops, validating table size and hot paths before reporting. Use when a Django view or endpoint is slow or a change touches large tables.