开发者

Sanitize LDAP_bind query

开发者 https://www.devze.com 2023-01-31 07:17 出处:网络
I know that when I query a MySQL database in PHP from user entered data, the data should be sanitized.For a project that I am starting up, I will be a开发者_运维问答uthenticating against Active Direct

I know that when I query a MySQL database in PHP from user entered data, the data should be sanitized. For a project that I am starting up, I will be a开发者_运维问答uthenticating against Active Directory for use login using the ldap_bind() function.

I've taken steps to check for a password to prevent an anonymous bind attempt, but I'm wondering if I need to take any other precautions like I would normally take when using user entered data. Or is this something that Active Directory will take care of itself?


I'm an OpenLDAP kind of guy, but if I'm not mistaken there's no way to exploit this with special characters.

However, that doesn't mean it's not good practice to strip out things you know won't be there, particularly in user names or generated bind paths. For instance:

$myname = preg_replace( "/[^a-zA-Z0-9_\ -]/", "", $myname );

That would strip everything out except lowercase, uppercase, numbers, underscore, spaces and dash. It's always more secure to use an "allow only this" logic rather than "reject something". You can never think of ALL things to reject.


Be careful to validate that the password is not null. Sounds silly, but according to the LDAP standard a bind with a username and no password is counted as an anonymous bind and will succeed.

If you are using the success/failure of the bind attempt to validate the users credentials then a null password would be a nice way to fake it out.

0

精彩评论

暂无评论...
验证码 换一张
取 消