Skip to content

fix(#5705): mask private-key blocks that span JSON members or records - #1

Closed
andrewevansrh wants to merge 1 commit into
agent/5705-json-sanitizerfrom
agent/5705-spanning-private-keys
Closed

andrewevansrh wants to merge 1 commit into
agent/5705-json-sanitizerfrom
agent/5705-spanning-private-keys

Conversation

@andrewevansrh

Copy link
Copy Markdown
Owner

Summary

Part 2 of 3 split out of fullsend-ai#9699 (part 1: fullsend-ai#10082).

A JSON document can carry a private key one fragment per member: BEGIN in one
string, body lines in the next, END in a third. Masking any single member
removes the marker the block's own pattern needs, and the written-bytes scan that
runs after the rewrite sees no block any more, so the body was written back in
clear text.

Base: agent/5705-json-sanitizer (part 1, fullsend-ai#10082). Review the diff against
that branch; only that delta is this PR. It is opened in the fork because a
stacked PR's base branch has to live in the repository the PR is opened in, and
the base branch is not in fullsend-ai/fullsend. This one will be retargeted to
main once part 1 lands.

What changed

  • jsonsanitize.go detects a private-key block that spans members or records on
    a decoded view of the document or stream, before anything is rewritten, and
    neutralizes it where it lives:
    • the boundary members always carry marker text and are masked, even when a
      marker is split across two members and neither fragment looks like one alone;
    • a member in between is masked when it carries a marker, a run that looks like
      PEM body material, or joins with its neighbours into text that does;
    • object keys keep their names unless the name itself is block content, so a
      review that merely quotes the PEM header in one finding and the footer in
      another keeps the shape and enum values review-result.schema.json requires
      instead of failing schema validation and being dropped;
    • records carrying part of a block across a record boundary are replaced with a
      fail-closed marker, because the record framing cannot be rewritten.
  • A body split so that one-character and longer chunks alternate is a known
    residual; uniform chunks and complete body lines are masked.

Verification

  • go test ./internal/security/
  • make lint

Note: Generated with assistance from DeepSeek V4.1 Flash

… or records

A JSON document can carry a private key one fragment per member: BEGIN in
one string, body lines in the next, END in a third. Masking any single
member removes the marker the block's own pattern needs, and the bytes
scan that runs after the rewrite sees no block any more, so the body was
written back in clear text.

Such a block is now detected on a decoded view of the document or stream,
before anything is rewritten, and neutralized member by member. The
boundary members always carry marker text and are masked even when a
marker is split across two of them; a member in between is masked when it
carries a marker, a run that looks like PEM body material, or joins with
its neighbours into text that does. Object keys keep their names unless
the name itself is block content, so a review that merely quotes the PEM
header in one finding and the footer in another keeps the shape and the
enum values review-result.schema.json requires, instead of being dropped
by schema validation. Records carrying part of a block across a record
boundary are replaced with a fail-closed marker, because the record
framing cannot be rewritten.

A body split so that one-character and longer chunks alternate is a known
residual; uniform chunks and complete body lines are masked.

Signed-off-by: anevans <anevans@redhat.com>
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

⚠️ Fullsend review agent did not run

The agent could not start because of a token mint failure.

View the workflow run

@andrewevansrh

Copy link
Copy Markdown
Owner Author

Moved to fullsend-ai#10084 so the stack lands upstream in order.

Note: Generated with assistance from DeepSeek V4.1 Flash

This branch was successfully deployed

1 active deployment
forgejo-dev — 53cdfed3 Deployed Dec 3, 2026 by andrewevansrh via forgejo-behaviour #4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant