Skip to content

Prevent V1 ciphertext from colliding with V2 detection - #167

Merged
BenCodez merged 13 commits into
masterfrom
fix/protocol-detection-collision-20260827
Aug 27, 2026
Merged

Prevent V1 ciphertext from colliding with V2 detection#167
BenCodez merged 13 commits into
masterfrom
fix/protocol-detection-collision-20260827

Conversation

@BenCodez

@BenCodez BenCodez commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • treat 0x733A and direct-JSON matches as V2 candidates rather than assuming the classification is unambiguous
  • buffer framed V2 packets to exactly their declared 4 + payloadLength boundary and parse them once
  • reject complete malformed/authentication-failing frames without waiting for the normal five-second socket timeout
  • give an ambiguous, incomplete 256-byte V1 candidate one absolute 250 ms TCP-fragment deadline, then restore the original timeout
  • recompute each socket read timeout from the remaining total deadline so slow trickles cannot extend it
  • scan unframed JSON incrementally in one pass while retaining every consumed byte for possible V1 fallback
  • parse unframed V2 only through the detected outer-object boundary, keeping any same-chunk suffix in the collision candidate
  • attempt V1 fallback only when V1 is enabled, preserving the DisableV1 security boundary
  • continue accepting legal leading whitespace in framed V2 JSON
  • cap unframed V2 candidate buffering at 65,539 bytes

Why

Jenkins build 847 reached compilation and tests successfully after #166 fixed Maven repository resolution, then failed intermittently in VoteReceiverTest.testDetectV1VoteProtocol:

expected: <V1> but was: <V2>

RSA/PKCS#1 ciphertext is randomized. A valid V1 block can therefore begin with either the V2 0x733A magic or {, making prefix-only detection inherently ambiguous.

TCP has no message boundary that can distinguish a complete short V2 frame from the first fragment of a 256-byte V1 ciphertext. The parser therefore uses a narrowly bounded 250 ms grace deadline only after an apparent V2 candidate fails. This permits ordinary segmentation to complete the V1 block without allowing byte trickles to reset the timeout or occupy a worker for the normal five seconds.

Framed V2 reads otherwise honor the declared length and parse once. Unframed JSON uses a stateful boundary scanner rather than repeatedly copying, decoding, and parsing the accumulated prefix.

Validation

  • GitHub Actions mvn -B -f VotifierPlus/pom.xml package: passed on commit 671bc32
  • slow-trickle test sends one byte every 100 ms and remains constrained by the single 250 ms total deadline
  • bulk-read test preserves ciphertext bytes consumed after an apparent early JSON boundary
  • delayed-fragment, exact-frame, byte-wise fragmentation, disabled-V1, leading-whitespace, and ordinary protocol tests pass
  • all eight Codex review findings addressed, replied to, and resolved
  • git diff --check passes

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5232ae520

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread VotifierPlus/src/main/java/com/vexsoftware/votifier/net/VoteParser.java Outdated
Comment thread VotifierPlus/src/main/java/com/vexsoftware/votifier/net/VoteParser.java Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8215bbbbcb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread VotifierPlus/src/main/java/com/vexsoftware/votifier/net/VoteParser.java Outdated

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 8215bbbbcb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Owner Author

@codex review

Please review the new head b352edb, especially the fragmented-stream candidate buffering and 256-byte V1 fallback boundary.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b352edbf0d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread VotifierPlus/src/main/java/com/vexsoftware/votifier/net/VoteParser.java Outdated
Comment thread VotifierPlus/src/main/java/com/vexsoftware/votifier/net/VoteParser.java Outdated

Copy link
Copy Markdown
Owner Author

@codex review

Please review head 8281ff4, focusing on exact framed-V2 boundaries, the single-pass unframed JSON scanner, and preservation of the 256-byte V1 collision fallback.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8281ff4523

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread VotifierPlus/src/main/java/com/vexsoftware/votifier/net/VoteParser.java Outdated

Copy link
Copy Markdown
Owner Author

@codex review

Please review head 32b47f1, especially the 250 ms socket-timeout handoff for delayed V1 collision fragments and restoration of the original timeout.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 32b47f1d71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread VotifierPlus/src/main/java/com/vexsoftware/votifier/net/VoteParser.java Outdated
Comment thread VotifierPlus/src/main/java/com/vexsoftware/votifier/net/VoteParser.java Outdated

Copy link
Copy Markdown
Owner Author

@codex review

Please review head 671bc32, focusing on the absolute collision-grace deadline and preservation of bytes consumed beyond an unframed JSON boundary.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 671bc32fe1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@BenCodez
BenCodez merged commit 0679e45 into master Aug 27, 2026
1 check passed
@BenCodez
BenCodez deleted the fix/protocol-detection-collision-20260827 branch August 27, 2026 02:33
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