-
Notifications
You must be signed in to change notification settings - Fork 1
fix: security and code quality improvements #44
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
Conversation
Security fixes: - Fix LDAP injection vulnerabilities in organization.ts, groups.ts, and ldapFlat.ts by using escapeLdapFilter() for user-supplied query parameters - Mask unauthorized tokens in logs to prevent credential exposure (token.ts) Code quality improvements: - Extract duplicated regex caching utilities (getCompiledRegex, escapeRegex) from groups.ts and ldapFlat.ts into shared utils.ts - Add .catch() handlers to fire-and-forget hook calls in ldapActions.ts to prevent silent failures - Replace unbounded Map with LRUCache for attrSignatureCache to prevent memory leaks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…s.ts The previous commit inadvertently broke the custom filter functionality. This commit restores the ability to use custom filters (with =) while: - Keeping strict character validation for custom filters - Escaping simple values to prevent LDAP injection 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements security fixes for LDAP injection vulnerabilities and several code quality improvements. The changes add LDAP filter escaping, mask unauthorized tokens in logs, extract duplicated regex utilities, add error handling to hooks, and replace an unbounded Map with an LRU cache.
Changes:
- Add
escapeLdapFilter()function and apply it to user-supplied query parameters in LDAP searches - Mask unauthorized tokens in authentication logs to prevent credential exposure
- Extract regex caching utilities (
getCompiledRegex,escapeRegex) from class instances to shared utils - Add
.catch()handlers to fire-and-forget hook calls for better error visibility - Replace unbounded
attrSignatureCacheMap with bounded LRUCache to prevent memory leaks
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/plugins/ldap/organization.ts | Adds LDAP filter escaping for search queries to prevent injection attacks |
| src/plugins/ldap/groups.ts | Applies LDAP filter escaping and removes duplicate regex utilities |
| src/plugins/auth/token.ts | Masks unauthorized tokens in logs to prevent credential exposure |
| src/lib/utils.ts | Adds shared regex caching utilities and LDAP escaping functions |
| src/lib/ldapActions.ts | Replaces unbounded Map with LRU cache and adds hook error handlers |
| src/abstract/ldapFlat.ts | Applies LDAP filter escaping and removes duplicate regex utilities |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export function getCompiledRegex(pattern: string, flags?: string): RegExp { | ||
| const key = flags ? `${pattern}:${flags}` : pattern; | ||
| let regex = regexCache.get(key); | ||
| if (!regex) { | ||
| regex = new RegExp(pattern, flags); | ||
| regexCache.set(key, regex); | ||
| } | ||
| return regex; | ||
| } | ||
|
|
||
| /** | ||
| * Escape special regex characters in a string | ||
| * Useful when building dynamic regex patterns from user input | ||
| * | ||
| * @param str - The string to escape | ||
| * @returns The escaped string safe for use in RegExp | ||
| */ | ||
| export function escapeRegex(str: string): string { | ||
| return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| } |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new regex caching utility functions (getCompiledRegex and escapeRegex) lack test coverage. While these are lower risk than security functions, they are shared across multiple plugins and should have unit tests to verify:
- Proper caching behavior (returns same RegExp instance for same pattern)
- Correct handling of flags parameter
- Proper escaping of all special regex characters in
escapeRegex
Consider adding tests for these utility functions in a test file like test/lib/utils.test.ts.
- Escape DN parameter in organization.ts search filter (LDAP injection fix) - Replace escapeLdapFilter() with whitelist validation for LDAP attribute names in ldapFlat.ts (proper security pattern for attribute names) - Add documentation clarifying regexCache is for static patterns only - Fix prettier formatting in ldapFlat.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary
escapeLdapFilter()for user-supplied query parametersgetCompiledRegex,escapeRegex) from groups.ts and ldapFlat.ts into shared utils.ts.catch()handlers to fire-and-forget hook calls in ldapActions.ts to prevent silent failuresattrSignatureCacheto prevent memory leaksSecurity fixes
LDAP Injection Prevention (Critical)
User-supplied query parameters were being directly interpolated into LDAP filters, allowing potential injection attacks:
Before:
filter: `(&(objectClass=organizationalUnit)(|(ou=*${query}*)(description=*${query}*)))`After:
Token Masking in Logs
Unauthorized tokens were logged in full, potentially exposing valid tokens:
Before:
After:
Code quality improvements
utils.tsreduce code duplicationTest plan
npm run build:dev)🤖 Generated with Claude Code