Skip to content

Commit 71c9234

Browse files
authored
Fix LDAP Sanitization (mitmproxy#8178)
This fixes GHSA-527g-3w9m-29hv.
1 parent cc58fc9 commit 71c9234

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
## Unreleased: mitmproxy next
99

10+
- [GHSA-527g-3w9m-29hv](https://github.com/mitmproxy/mitmproxy/security/advisories/GHSA-527g-3w9m-29hv):
11+
Fix LDAP injection vulnerability reported by @yueyueL.
12+
([#8178](https://github.com/mitmproxy/mitmproxy/pull/8178), @mhils)
1013
- Fix addon options not being included in `--options` output.
1114
([#4423](https://github.com/mitmproxy/mitmproxy/issues/4423))
1215
- Fix `view.settings.setval.toggle` command to correctly use the provided key parameter instead of hardcoded "key" string.

mitmproxy/addons/proxyauth.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,14 @@ def parse_spec(spec: str) -> tuple[bool, str, int | None, str, str, str, str]:
281281
except ValueError:
282282
raise exceptions.OptionsError(f"Invalid LDAP specification: {spec}")
283283

284+
def make_search_filter(self, username: str) -> str:
285+
username = ldap3.utils.conv.escape_filter_chars(username)
286+
return f"({self.filter_key}={username})"
287+
284288
def __call__(self, username: str, password: str) -> bool:
285289
if not username or not password:
286290
return False
287-
self.conn.search(self.dn_subtree, f"({self.filter_key}={username})")
291+
self.conn.search(self.dn_subtree, self.make_search_filter(username))
288292
if self.conn.response:
289293
c = ldap3.Connection(
290294
self.server, self.conn.response[0]["dn"], password, auto_bind=True

test/mitmproxy/addons/test_proxyauth.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,12 @@ def test_ldap(monkeypatch, spec):
269269
assert validator("foo", "bar")
270270
validator.conn.response = False
271271
assert not validator("foo", "bar")
272+
273+
274+
def test_ldap_username_sanitization(monkeypatch):
275+
monkeypatch.setattr(ldap3, "Server", mock.MagicMock())
276+
monkeypatch.setattr(ldap3, "Connection", mock.MagicMock())
277+
validator = proxyauth.Ldap(
278+
"ldaps:localhost:cn=default,dc=cdhdt,dc=com:password:ou=application,dc=cdhdt,dc=com"
279+
)
280+
assert validator.make_search_filter("*") == "(cn=\\2a)"

0 commit comments

Comments
 (0)