spnego: don't synthesise a GSSAPI blob from an empty token - #5170
Closed
itzzdev09 wants to merge 1 commit into
Closed
spnego: don't synthesise a GSSAPI blob from an empty token#5170itzzdev09 wants to merge 1 commit into
itzzdev09 wants to merge 1 commit into
Conversation
gpotter2
reviewed
Sep 11, 2026
gpotter2
reviewed
Sep 11, 2026
gpotter2
force-pushed
the
fix/spnego-empty-token
branch
2 times, most recently
from
September 11, 2026 19:17
40cdd99 to
66142e2
Compare
Dissecting an empty OCTET STRING built a sub-packet from b"". Constructing
an ASN1_Packet from empty bytes materialises that class's defaults, so
GSSAPI_BLOB(b"") yields the 10-byte SPNEGO OID header:
>>> raw(SPNEGO_Token())
b'\x04\x00'
>>> raw(SPNEGO_Token(raw(SPNEGO_Token())))
b'\x04\n\x60\x08\x06\x06\x2b\x06\x01\x05\x05\x02'
AI-Assisted: yes (Claude Code, Claude Opus 5)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5170 +/- ##
===========================================
- Coverage 80.83% 47.27% -33.57%
===========================================
Files 391 373 -18
Lines 97801 97437 -364
===========================================
- Hits 79056 46059 -32997
- Misses 18745 51378 +32633
🚀 New features to boost your workflow:
|
Member
|
Hi. Tests don't seem to pass. Considering this is all AI I will close. Please reopen once tests pass. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Dissecting an empty OCTET STRING builds a sub-packet from
b"". Constructing anASN1_Packetfrom empty bytes materialises that class's defaults, soGSSAPI_BLOB(b"")yields the 10-byte SPNEGO OID header:An empty
mechToken/mechListMICis legal, so parsing one off the wire and re-serialising it invented ten bytes that were never there.SPNEGO_MechListMIChad the same behaviour. Anything that parses and re-emits SPNEGO — relaying, rewriting, pcap round-trips — silently changed the bytes.The fix
Two sites, one cause:
_SPNEGO_Token_Field.m2ireturns the raw value when it is empty. It returnsdat.valrather than theASN1_STRINGbecausei2m()callsbytes()on the result, andbytes()of anASN1_STRINGre-encodes the BER header instead of yieldingb""— returning the string double-wraps to\x04\x02\x04\x00.ASN1F_STRING_ENCAPS.m2ikeeps the emptyASN1_STRINGinstead of callingself.cls(b""). This is the generic fix;SPNEGO_MechListMICreaches it, as do thekerberosandx509users of that field.ASN1F_STRING_PacketField.i2malready accepts either a packet or a raw string, so the empty case round-trips without further change.Non-empty values are untouched — a token with content still dissects to
GSSAPI_BLOBor the registered mech dissector.Tests
Four cases added to
test/scapy/layers/spnego.uts: the two empty round-trips, a non-empty token still yieldingGSSAPI_BLOB, and thenegTokenInit/negTokenRespcontainers. Two of the four fail onmaster; the other two are guards that pass in both arms, confirming existing behaviour is preserved.Run on
190b4ba3with the branch applied, and the same suites on an unmodifiedmasterworktree for comparison:x509's 46 failures are pre-existing onmasterin this checkout — a newercryptography(50.0.1) than it supports — and are byte-identical in both arms. I'm flagging them rather than hiding them; they are not caused by this change.flake8output on both touched modules is identical tomaster(7 pre-existing F401s in both, unchanged).Disclosure per CONTRIBUTING: prepared with AI assistance (Claude Code, Claude Opus 5). The bug was found by a build/dissect round-trip sweep over scapy's packet classes, and every number above comes from actually running the suites, in both arms, rather than from inspection.
🤖 Generated with Claude Code