-
Notifications
You must be signed in to change notification settings - Fork 445
fix: rework FeatureExt generation #1718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The fabric login test was passing `isFabric: true` to Login7Payload constructor, but this parameter doesn't exist in the Options interface. The test was using `as any` to bypass TypeScript type checking. This parameter was originally planned as part of PR #1668 for Microsoft Fabric support, but was removed per David Engel's commit which showed that the Fabric-related changes work for all endpoints without needing a special flag. Cleanup from PR #1668 (feat: support Azure SQL Database in Microsoft Fabric).
Per the MS-TDS specification section 2.2.6.4, the LOGIN7 message structure must be: 1. Fixed header (36 bytes) 2. OffsetLength section (58 bytes) 3. Data section (variable-length content) 4. FeatureExt section (at the END, after all other variable data) The previous implementation incorrectly placed the FeatureExt data IN THE MIDDLE of the variable data section (after ServerName, before LibraryName). This caused Microsoft Fabric to reject the LOGIN7 packet since Fabric has stricter packet validation. Changes: - cbExtension now correctly set to 4 (just the ibFeatureExtLong pointer size), not 4 + extensions.length - ibFeatureExtLong now points to the actual end of the packet where FeatureExt data is placed - FeatureExt data is appended at the very end, after all other variable-length data (LibraryName, Language, Database, SSPI, AttachDbFile, ChangePassword) This should resolve connection issues with Microsoft Fabric (issue #1563).
Code Review - PR #1718SummaryThis PR contains two commits that clean up and fix the LOGIN7 packet generation for Microsoft Fabric compatibility. The changes address issue #1563 where connections to Microsoft Fabric were failing with ✅ Strengths
🔍 Potential Issues & QuestionsCritical - Variable Data Offset TrackingLocation: src/login7-payload.ts:263-270, 338, 352-378 There's a potential bug with // Line 338: SSPI buffer is added
buffers.push(this.sspi);
// BUT dataOffset is NOT incremented here!
// Later, at line 382-386, we calculate ibFeatureExtLong:
extensionOffsetBuffer.writeUInt32LE(dataOffset, 0);Problem: If Impact: This could cause connection failures when using SSPI/Windows authentication with TDS 7.4+. Suggested Fix: if (this.sspi) {
if (this.sspi.length > 65535) {
offset = fixedData.writeUInt16LE(65535, offset);
} else {
offset = fixedData.writeUInt16LE(this.sspi.length, offset);
}
buffers.push(this.sspi);
dataOffset += this.sspi.length; // ADD THIS LINE
} else {
offset = fixedData.writeUInt16LE(0, offset);
}Question - Test CoverageThe existing test at line 267-287 calculates 4 + // Extension offset
1 + (1 + 4 + 1) + (1 + 4 + 1) + 1; // Feature extDoes this test actually verify that:
Suggestion: Consider adding an assertion that actually reads the offset value from the packet and verifies it points to the correct location. Minor - cbExtension Comment AccuracyLocation: src/login7-payload.ts:259-260 The comment states:
However, according to MS-TDS spec, Suggested rewording: // (cchUnused / cbExtension): 2-byte
// For TDS 7.4+, cbExtension is the size of the ibFeatureExtLong offset pointer (4 bytes).
// The actual FeatureExt data is appended at the end and pointed to by ibFeatureExtLong.🧪 Test Coverage AssessmentGood:
Missing:
Recommendation: Add a test that:
🔒 Security ConsiderationsNo security issues identified. The changes:
⚡ Performance ConsiderationsPositive:
Neutral:
📋 Recommendations
✨ Overall AssessmentThis is a well-researched fix that addresses a real compatibility issue with Microsoft Fabric. The approach is correct per the MS-TDS specification, and the code is well-documented. However, there appears to be a critical bug with The test cleanup is appropriate and removes technical debt from PR #1668. Recommendation: Request changes to fix the SSPI offset tracking issue before merging. |
When SSPI data was added to the buffers array, dataOffset was not being incremented to account for its length. This caused incorrect offset calculations for subsequent fields (attachDbFile, changePassword) and the FeatureExt pointer. This bug was identified in the code review of PR #1718.
Code Review - PR #1718: Fix FeatureExt GenerationThank you for this comprehensive fix! This PR addresses a critical issue with Microsoft Fabric connections by correctly implementing the MS-TDS specification for LOGIN7 packet structure. I've conducted a thorough review of the changes. SummaryThis PR makes three important fixes:
Detailed Analysis✅ Strengths
🔍 Issues & Concerns1. Missing Test Coverage for SSPI + FeatureExt CombinationIssue: There's no test case that validates the combination of SSPI data with TDS 7.4+ (which includes FeatureExt). Impact: The critical bug fix in commit 3 (SSPI dataOffset increment) would not be caught by the existing tests. The existing tests:
Recommendation: Add a test case for TDS 7.4+ with SSPI data to ensure the dataOffset increment fix works correctly. 2. Potential Edge Case: Empty FeatureExtCode location: if (this.tdsVersion >= versions['7_4']) {
featureExtData = this.buildFeatureExt();
// cbExtension = 4 (just the ibFeatureExtLong pointer size)
offset = fixedData.writeUInt16LE(4, offset);
// Reserve space for the 4-byte offset pointer
extensionOffsetBuffer = Buffer.alloc(4);
buffers.push(extensionOffsetBuffer);
dataOffset += 4;
}Question: What happens if 3. Code Clarity: Variable NamingCode location: The variables 🔒 Security Assessment✅ No security concerns identified
⚡ Performance Considerations✅ Performance impact is minimal
🧪 Test Coverage Recommendations
📋 Checklist
💭 Final RecommendationAPPROVE with minor suggestions This is a solid fix that addresses a real protocol compliance issue. The implementation correctly follows the MS-TDS specification, and the bug fixes are important for correctness. Suggested improvements before merge:
The PR is ready to merge if the team is comfortable with current test coverage, though adding the SSPI + TDS 7.4 test would significantly increase confidence in the offset calculation fix. Great work on identifying and fixing these issues! 🎉 |
Add two new tests to verify the LOGIN7 packet structure: 1. Verifies ibFeatureExtLong offset pointer points to valid FeatureExt data 2. Verifies FeatureExt is correctly positioned after SSPI data These tests ensure the FeatureExt data is placed at the END of the packet as required by the MS-TDS specification section 2.2.6.4.
Pull Request Review - PR #1718: fix: rework FeatureExt generationI've completed a comprehensive review of this PR. Overall, this is excellent work that properly fixes a critical issue with Microsoft Fabric connections. The implementation is well-thought-out and addresses a fundamental protocol-level problem. ✅ Strengths1. Correct Implementation of MS-TDS Specification
2. Critical Bug Fix: SSPI Offset Tracking
3. Excellent Test Coverage
4. Clean Code Quality
🔍 Code Quality ObservationsMinor: Test RobustnessThe test at line 357-362 calculates const variableDataEnd = Math.max(
ibHostName + cchHostName * 2,
ibDatabase + cchDatabase * 2,
ibAttachDBFile + cchAttachDBFile * 2,
ibChangePassword + cchChangePassword * 2
);Observation: This doesn't include all variable-length fields that appear before FeatureExt in the data section:
Impact: Low - the test still passes because the fields that ARE checked happen to come after the omitted ones in this specific test payload. However, for complete correctness, all variable fields should be included. Suggestion: Consider adding all variable fields to ensure the test validates the true end of variable data: const variableDataEnd = Math.max(
ibHostName + cchHostName * 2,
data.readUInt16LE(40) + data.readUInt16LE(42) * 2, // ibUserName + cchUserName * 2
data.readUInt16LE(44) + data.readUInt16LE(46) * 2, // ibPassword + cchPassword * 2
data.readUInt16LE(48) + data.readUInt16LE(50) * 2, // ibAppName + cchAppName * 2
data.readUInt16LE(52) + data.readUInt16LE(54) * 2, // ibServerName + cchServerName * 2
data.readUInt16LE(60) + data.readUInt16LE(62) * 2, // ibCltIntName + cchCltIntName * 2
data.readUInt16LE(64) + data.readUInt16LE(66) * 2, // ibLanguage + cchLanguage * 2
ibDatabase + cchDatabase * 2,
data.readUInt16LE(78) + data.readUInt16LE(80), // ibSSPI + cbSSPI
ibAttachDBFile + cchAttachDBFile * 2,
ibChangePassword + cchChangePassword * 2
);🔒 Security✅ No security concerns identified
⚡ Performance✅ Minimal performance impact
🧪 Test Coverage✅ Excellent test coverage
Minor suggestion: Consider adding a test for the 🐛 Potential IssuesNone identifiedThe implementation correctly:
📋 Best Practices✅ Follows repository conventions
✅ Documentation
📝 SummaryThis PR represents high-quality work that:
Recommendation: ✅ APPROVE WITH MINOR SUGGESTIONThe code is ready to merge. The only suggestion is to enhance the test robustness by including all variable fields in the Great work on this fix! This will enable Node.js applications to connect to Microsoft Fabric, which has been a pain point for the community for over a year. Review conducted by Claude Code - analyzing PR #1718 in tediousjs/tedious |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1718 +/- ##
==========================================
+ Coverage 79.92% 79.93% +0.01%
==========================================
Files 90 90
Lines 4887 4890 +3
Branches 920 921 +1
==========================================
+ Hits 3906 3909 +3
Misses 676 676
Partials 305 305 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Clarify cbExtension comment to explicitly state it's the size of the ibFeatureExtLong pointer (4 bytes), not the FeatureExt data - Extend test to validate all variable-length fields when checking FeatureExt positioning, ensuring complete coverage per MS-TDS spec
Code Review - PR #1718: Fix FeatureExt GenerationSummaryThis PR correctly addresses a technical debt issue from PR #1668 by removing the non-existent isFabric parameter and properly implementing the MS-TDS specification for FeatureExt data placement in Login7 packets. Strengths1. Correct Implementation of MS-TDS Specification
2. Bug Fix - SSPI dataOffset Tracking
3. Excellent Test Coverage
4. Code Quality
Observations and Suggestions1. Comment Clarity (Minor) 2. Edge Case Documentation (Enhancement) 3. Test Assertion Messages (Minor) Security AnalysisNo security concerns identified:
Performance AnalysisMinimal performance impact:
Test CoverageExcellent coverage:
RecommendationAPPROVE - This is a well-implemented bug fix with excellent test coverage. The code correctly implements the MS-TDS specification and fixes a legitimate bug in the SSPI offset tracking. Optional Follow-upAfter merging, consider:
Great work on cleaning up the technical debt and improving spec compliance! |
Pull Request Review: Fix FeatureExt Generation for Microsoft FabricSummaryThis PR fixes Microsoft Fabric connection issues by correcting the LOGIN7 packet structure to comply with the MS-TDS specification (section 2.2.6.4). The key change is ensuring FeatureExt data is placed at the end of the packet, with Code Quality ✅Strengths:
Minor Suggestion:
Bug Analysis 🔍Fixed Issue: Critical Bug Found - SSPI dataOffset tracking: Code Correctness:
Test Coverage ✅Excellent test coverage:
Suggestions:
Performance ⚡No concerns:
Security 🔒No security issues identified:
Specification Compliance 📋MS-TDS Section 2.2.6.4 Compliance:
RecommendationsBefore Merge:
Future Enhancements:
Verdict: ✅ Approve with Minor SuggestionsThis is a high-quality fix that:
The minor suggestions are optional improvements. This PR is ready to merge. Review generated with attention to MS-TDS specification compliance and TDS 7.4 protocol requirements. |
Fixes Microsoft Fabric connection issues by correcting the LOGIN7 packet structure to comply with the MS-TDS specification (section 2.2.6.4).