Skip to content

feat(thrift): add Thrift serialization and deserialization operations#2481

Open
engin0223 wants to merge 19 commits into
gchq:masterfrom
engin0223:new
Open

feat(thrift): add Thrift serialization and deserialization operations#2481
engin0223 wants to merge 19 commits into
gchq:masterfrom
engin0223:new

Conversation

@engin0223

Copy link
Copy Markdown

Description
This pull request introduces two new operations to CyberChef: Thrift Deserialize and Thrift Serialize.

Similar to the existing Protobuf implementation, these operations work in a schema-less mode, inferring fields and data types directly from the wire encoding.

Key additions:

  • Thrift Deserialize: Decodes a raw Thrift binary/compact blob or TJSON stream into a clean, human-readable JSON structure detailing field IDs, types, and values.
  • Thrift Serialize: Takes a structured JSON payload and encodes it back into the selected Thrift protocol format.
  • Protocol Support: Added a dropdown configuration to support TBinaryProtocol, TCompactProtocol, and TJSONProtocol.

Existing Issue
Closes #2374

AI disclosure
I used Gemini 3.1 Pro to assist with the code. I have thoroughly reviewed, tested, and verified all the code submitted and fully understand its implementation.

Test Coverage
Added structured automated unit tests under CyberChef's test framework using TestRegister.addTests(). The test suite handles 4-space indented JSON formatting verification and explicitly covers:

  • TBinaryProtocol Serialization & Deserialization Symmetry: Validates that serialization and deserialization seamlessly match for basic data types (I32, BINARY, BOOL).
  • Complex Data Types: Specifically covers nesting arrays inside lists (List of I32) validating element type sizes (0x08) and lengths inside the wire stream.
  • TCompactProtocol Layouts: Validates variable-length delta tracking, compact field headers, and structural stream stops (0x00).
  • ZigZag / Varint Encoding Verification: Includes distinct edge-case tests validating that negative integers (e.g., -1337) are properly transformed via ZigZag calculations to match wire-level expectations (f1 14).

@GCHQDeveloper581 GCHQDeveloper581 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a single, "sunny day" test for each operation to tests/browser/02_ops.js please.

Comment thread src/core/operations/ThriftDeserialize.mjs
engin0223 and others added 10 commits June 5, 2026 14:10
- Moved binary and compact protocol parsing logic from ThriftDeserialize and ThriftSerialize classes to utility functions in Thrift.mjs.
- Updated ThriftDeserialize to use new parseBinaryProtocol and parseCompactProtocol functions.
- Simplified ThriftSerialize by utilizing buildBinaryStruct and writeValue functions for serialization.
- Added comprehensive tests for Thrift serialization and deserialization, covering various data types and structures.
- Ensured proper handling of edge cases in readVarint and fromZigZag functions.
- Moved binary and compact protocol parsing logic from ThriftDeserialize and ThriftSerialize classes to utility functions in Thrift.mjs.
- Updated ThriftDeserialize to use new parseBinaryProtocol and parseCompactProtocol functions.
- Simplified ThriftSerialize by utilizing buildBinaryStruct and writeValue functions for serialization.
- Added comprehensive tests for Thrift serialization and deserialization, covering various data types and structures.
- Ensured proper handling of edge cases in readVarint and fromZigZag functions.
…ation to prevent element was not found error
Comment thread tests/node/tests/lib/Thrift.mjs
Comment thread src/core/operations/ThriftDeserialize.mjs Outdated
Comment thread src/core/operations/ThriftSerialize.mjs Outdated
@engin0223 engin0223 closed this Jun 6, 2026
@engin0223 engin0223 deleted the new branch June 6, 2026 10:48
@engin0223 engin0223 restored the new branch June 6, 2026 10:49
@engin0223 engin0223 reopened this Jun 6, 2026

@GCHQDeveloper581 GCHQDeveloper581 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operations tests were not previously connected. I've connected these and some tests now fail.

In manual testing I found a LIST could not be round-tripped correctly (it looks like the inner object (elementType/elements) is omitted when deserializing and instead the list elements presented as the value). I've added a (currently failing) test for this case.

SET and MAP also fail in a similar fashion (but I haven't provided test cases for these)

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.

Feature Request: Add Thrift Serialization / Deserialization operations

2 participants