Skip to content

Fix LDAP bind panic when userPassword attribute is missing#171

Merged
rhafer merged 2 commits intolibregraph:masterfrom
longsleep-io:longsleep-fix-issue-114-bind-panic
Jul 1, 2025
Merged

Fix LDAP bind panic when userPassword attribute is missing#171
rhafer merged 2 commits intolibregraph:masterfrom
longsleep-io:longsleep-fix-issue-114-bind-panic

Conversation

@longsleep
Copy link
Collaborator

Summary

Fixes #114 - Resolves LDAP bind panic and silent error handling when user records lack userPassword attributes.

This PR addresses two critical issues:

  1. Silent panic recovery - panics are now properly logged with context
  2. Unsafe array access - prevents panic when accessing missing userPassword values

Changes Made

Core Fix

  • pkg/ldapserver/bind.go: Enhanced panic logging with error context and remote address
  • server/handler/ldif/entry.go: Added safe password validation with proper null checks
  • server/handler/ldif/entry_test.go: Comprehensive unit tests covering edge cases

Key Improvements

  • ✅ No panics when processing entries without userPassword
  • ✅ Clear, actionable error messages in logs ("user has no password attribute")
  • ✅ Proper LDAP error codes (InvalidCredentials vs OperationsError)
  • ✅ No timing attack vulnerabilities (maintains constant-time behavior)
  • ✅ Backward compatibility maintained

Testing

Unit Tests

  • Added comprehensive test suite for password validation edge cases
  • Tests for missing userPassword attribute
  • Tests for empty password values
  • Performance benchmarks to ensure no regression

End-to-End Testing

  • Verified no panics with malformed LDIF data containing users without passwords
  • Confirmed proper error codes (InvalidCredentials 49) returned to clients
  • Validated clear debug logging for troubleshooting
  • Ensured existing functionality unchanged

Before/After Behavior

Before (Issue #114):

  • Panic when user has no userPassword → silent recovery → OperationsError
  • No logging of panic reason → difficult debugging

After (This Fix):

  • Safe handling of missing userPassword → InvalidCredentials
  • Clear log: "ldap bind credentials error" error="user has no password attribute"
  • Proper error codes for client applications

Security Considerations

  • No timing attack vulnerabilities introduced
  • Maintains existing authentication security model
  • No sensitive information leaked in logs

Backward Compatibility

  • No changes to public APIs
  • Existing LDIF files continue to work
  • Error response codes consistent for valid scenarios

Test Plan

  • All existing tests pass
  • New unit tests cover edge cases
  • Manual testing with malformed LDIF data
  • Performance regression testing
  • Error code validation

Ready for review and merge.

Fixes libregraph#114

This commit addresses two critical issues in LDAP bind operations:

1. **Silent panic recovery**: Panics during bind operations are now properly
   logged with context including panic reason and remote address

2. **Unsafe array access**: Fixed panic when user records lack userPassword
   field by adding proper null checks before accessing Values[0]

Changes:
- pkg/ldapserver/bind.go: Enhanced panic logging with error context
- server/handler/ldif/entry.go: Added safe password validation with null checks
- server/handler/ldif/entry_test.go: Comprehensive unit tests for edge cases

The fix ensures:
- No panics when processing entries without userPassword
- Clear, actionable error messages in logs
- Proper LDAP error codes (InvalidCredentials vs OperationsError)
- No performance regression or timing attack vulnerabilities
- Backward compatibility maintained

Testing:
- All existing tests pass
- New unit tests cover missing password scenarios
- End-to-end testing confirms proper error handling
- No regressions in valid password scenarios
- Split long test functions to meet funlen requirements
- Fix gofmt formatting issues
- Remove var redeclaration in entry_test.go
- Improve else-if flow in test conditions

All tests pass and linter is now clean for the changed files.
@rhafer rhafer merged commit db3f305 into libregraph:master Jul 1, 2025
1 check passed
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.

Bind from LDIF data source panics when there is no userPassword and the panic is not logged

2 participants