【问题标题】:Php Ldap Sanitizing and ldap bindPhp Ldap 消毒和 ldap 绑定
【发布时间】:2019-10-06 22:14:31
【问题描述】:

我正在尝试使用 ldap 对用户进行身份验证。我有上面的代码来清理用户输入。

function ldapSanitize($val) {
    $sanitized=array('\\' => '\5c',
                     '*' => '\2a',
                     '(' => '\28',
                     ')' => '\29',
                     "\x00" => '\00');

    return str_replace(array_keys($sanitized),array_values($sanitized),$val);

我像这样调用 ldapSanitize 的用户名和密码

$uname = ldapSanitize($username);
$pass = ldapSanitize($password);

我使用 bind 来验证用户身份

 $ad = @ldap_connect(Config::ldaphost);
    if ($ad) {
        $bind = @ldap_bind($ad, $uname, $pass);
        if ($bind) {
            return true;
        }
    }
    return false;

我的问题是,如果密码有 * 字符,它会将其转换为 \2a 并且身份验证失败。例如,如果密码是“somepassword*”,它会将其更改为“somepassword\2a”并且绑定失败。

所以我想知道如何清理密码,同时还能使用 bind 进行身份验证。

【问题讨论】:

    标签: php ldap


    【解决方案1】:

    这是 RFC 4511 (https://tools.ietf.org/search/rfc4511#section-4.2) 中的相关段落:

     Textual passwords (consisting of a character sequence with a known
     character set and encoding) transferred to the server using the
     simple AuthenticationChoice SHALL be transferred as UTF-8 [RFC3629]
     encoded [Unicode].  Prior to transfer, clients SHOULD prepare text
     passwords as "query" strings by applying the SASLprep [RFC4013]
     profile of the stringprep [RFC3454] algorithm.  Passwords
     consisting of other data (such as random octets) MUST NOT be
     altered.  The determination of whether a password is textual is a
     local client matter.
    

    请注意,它声明“客户端应将文本密码准备为“查询”字符串”并参考其他标准。

    【讨论】:

      【解决方案2】:

      您不应清理密码。 RFC 4511 规定文本密码应以 UTF-8 格式传输。非文本密码不得更改。

      LDAP 服务器将密码视为八位字节字符串。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-15
        • 1970-01-01
        • 2014-09-24
        • 1970-01-01
        • 2013-06-27
        • 1970-01-01
        相关资源
        最近更新 更多