Skip to content
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

Fix escaping in LDAP search strings [CVE-2020-14013] #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

onovy
Copy link

@onovy onovy commented Jun 10, 2020

When username contains any special character (parentheses, asterisk, ...)
user search will fail.

When returned DN of user contains any escaped character (for example ",")
group filter will fail.

Example:

(&(CN=group)(member=CN=dummy\, dummy2,OU=ou,DC=dc))"

Which is wrong and doesn't work with Active directory.

Correct is:

(&(CN=group)(member=CN=dummy\5C, dummy2,OU=ou,DC=dc))"

This patch fixies both of these bugs by using ldap_bv2escaped_filter_value
from LDAP client to escape all of filter values.

See: https://tools.ietf.org/search/rfc2254#page-5
Fixes #224 fixes #180

CVE-2020-14013

When username contains any special character (parentheses, asterisk, ...)
user search will fail.

When returned DN of user contains any escaped character (for example ",")
group filter will fail.

Example:
(&(CN=group)(member=CN=dummy\, dummy2,OU=ou,DC=dc))"

Which is wrong and doesn't work with Active directory.

Correct is:
(&(CN=group)(member=CN=dummy\5C, dummy2,OU=ou,DC=dc))"

This patch fixies both of these bugs by using ldap_bv2escaped_filter_value
from LDAP client to escape all of filter values.

See: https://tools.ietf.org/search/rfc2254#page-5
Fix: kvspb#224 kvspb#180
@onovy onovy changed the title Fix escaping in LDAP search strings. Fix escaping in LDAP search strings Jun 10, 2020
@onovy onovy changed the title Fix escaping in LDAP search strings Fix escaping in LDAP search strings [CVE-2020-14013] Jun 10, 2020
}

out.len = euserbv.bv_len;
out.data = ngx_pcalloc(r->pool, out.len);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can ngx_pcalloc not fail?

Suggested change
out.data = ngx_pcalloc(r->pool, out.len);
out.data = ngx_pcalloc(r->pool, out.len);
if (!out.data) {
return out;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning out is not correct, because out.len will be set to new length but out.data will be null.

return ngx_null_string is probably better

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but tbh: Whole upstream code is not checking return code of ngx_pcalloc, so meh.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I saw that I will probably not use this module at all and use https://github.com/sto/ngx_http_auth_pam_module which seems much simpler and cleaner code.

@sc29872001
Copy link

I encountered the error during make install with this module.

/root/nginx-auth-ldap/ngx_http_auth_ldap_module.c: In function ‘ngx_http_auth_ldap_escape_filter’:
/root/nginx-auth-ldap/ngx_http_auth_ldap_module.c:766:19: error: pointer targets in assignment differ in signedness [-Werror=pointer-sign]
     userbv.bv_val = in->data;
                   ^
cc1: all warnings being treated as errors
make[1]: *** [objs/addon/nginx-auth-ldap/ngx_http_auth_ldap_module.o] Error 1
make[1]: Leaving directory `/root/nginx-1.20.1'
make: *** [build] Error 2

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.

LDAP Bad search filter (-7) error when CN has a comma in it (fix included) PR 170 breaks filters to AD
3 participants