mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6520] [MERGED] fix(nodetoken): make the corrupt-ciphertext test corrupt deterministically #6327
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6327
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6520
Author: @BlindMaster24
Created: 9/14/2026
Status: ✅ Merged
Merged: 9/14/2026
Merged by: @MHSanaei
Base:
main← Head:fix/nodetoken-deterministic-corruption📝 Commits (2)
6fc7b14fix(nodetoken): make the corrupt-ciphertext test corrupt deterministically5ea96a1style(nodetoken): trim the helper comment to the two-line limit📊 Changes
1 file changed (+14 additions, -1 deletions)
View changed files
📝
internal/crypto/nodetoken/nodetoken_test.go(+14 -1)📄 Description
Summary
TestEncryptedNeverFallsBackToPlaintextcorrupts the ciphertext by replacing the last two characters of the base64 body with"AA". On average once every ~300 runs that edit changes nothing, and the test fails on a codec that is working exactly as designed. The corruption now flips a bit of the decoded blob instead.Why
Codec.EncryptBoundstoresbase64.RawURLEncodingof annonce(12) || ciphertext || tag(16)blob. For the 31-byte blob this test produces, the encoding ends in a 2-character group: the first character carries 6 significant bits of the last byte, the second carries only 2 — its low 4 bits are always zero and are ignored by the decoder.So
enc[:len(enc)-2] + "AA"decodes to the original bytes whenever the final byte of the GCM tag is0x00, i.e. 1 run in 256. The assertion then reads a tag that was never touched and the codec correctly falls back to… no fallback at all, which is precisely what the test is about, so the test reports a failure that is entirely its own.Measured on this checkout, over 50 000 encryptions, comparing the decoded bytes before and after the edit:
and running the test itself 5000 times on the unmodified code: 19 failures, all of them
nodetoken_test.go:101.This is not theoretical: CI on #6519 failed
go-teston exactly this test withcorrupted ciphertext must fail, not fall back to plaintext, whilerace,golangci, the frontend job and every build passed. A flaky red on an unrelated PR costs a maintainer a real investigation, and re-running the job to get green hides it.Type of change
Areas affected
(Multi-node token encryption at rest —
internal/crypto/nodetoken.)How was this tested?
The change is verified by repetition, since the bug is a probability:
go test ./internal/crypto/nodetoken/ -run TestEncryptedNeverFallsBackToPlaintext -count=5000→ 19 failures-count=20000→ 0 failuresgo test ./internal/crypto/nodetoken/andgofmtclean(The second assertion in the test — an unknown key id — is a literal prefix replacement and was already deterministic; only the trailing-character edit was fragile.)
Screenshots / recordings
N/A.
Breaking changes
None — test-only.
Checklist
go build ./...and the test suite pass locally. (TestFileKeySourceRejectsLoosePermsfails on a Windows checkout becausechmod 0600is not reported there; it passes on Linux, which is where CI runs.)npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.