Skip to content
This repository was archived by the owner on Apr 4, 2026. It is now read-only.

fix: sanitize null bytes from messages.body JSON for PostgreSQL#76

Merged
christopherwxyz merged 1 commit into
mainfrom
fix/sanitize-unicode-for-postgres
Jan 3, 2026
Merged

fix: sanitize null bytes from messages.body JSON for PostgreSQL#76
christopherwxyz merged 1 commit into
mainfrom
fix/sanitize-unicode-for-postgres

Conversation

@christopherwxyz

Copy link
Copy Markdown
Contributor

Summary

PostgreSQL jsonb rejects \u0000 escape sequences. Protobuf strings are length-delimited and can contain null bytes, which Farcaster Hub accepts. When serialized to JSON via serde_json, null bytes become \u0000 and PostgreSQL rejects them.

This PR walks the serde_json::Value tree and strips null bytes from decoded strings before insertion. This approach avoids the pitfall of simple string replacement which can corrupt valid escape sequences like \\u0000.

Changes

  • Add sanitize_json_for_postgres() in src/core/util.rs
  • Apply sanitization to messages.body JSON in both single and batch inserts
  • Add 6 unit tests

Test plan

  • cargo test sanitize passes
  • cargo clippy passes

Protobuf strings are length-delimited and can contain null bytes.
Farcaster Hub accepts casts with null bytes, but PostgreSQL jsonb
rejects \u0000 escape sequences.

This walks the serde_json::Value tree and strips null bytes from
decoded strings, avoiding the pitfall of simple string replacement
which can corrupt valid escape sequences like \\u0000.
@christopherwxyz
christopherwxyz merged commit 95ba4e8 into main Jan 3, 2026
2 checks passed
@christopherwxyz
christopherwxyz deleted the fix/sanitize-unicode-for-postgres branch January 3, 2026 18:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant