Is escaping advisable when setting a value for an attribute? #686
-
Hello, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @andsal, It's not possible to escape LDAP attributes in LdapRecord. LdapRecord uses PHP's standard $changes = [
[
"attrib" => "telephoneNumber",
"modtype" => LDAP_MODIFY_BATCH_ADD,
"values" => ["+1 555 555 1717"], // Value cannot be escaped, its passed as its true PHP value.
],
];
ldap_modify_batch($connection, $dn, $modifs); This is different for LDAP search filters. Input supplied in LDAP search filters must always be escaped, as search filters are constructed similarly to SQL queries, in the sense that the string contains logic for filtering LDAP results. Ex: Without Escaping: // User-supplied input:
// $username = $_GET['username'];
// Ex:
$username = "*";
// "(uid=*)"
$query = "(uid=$username)";
// Search returns all users due to wildcard:
$result = ldap_search($ldap_connection, $base_dn, $query); With Escaping: // "\2a"
$username = ldap_escape("*");
// "(uid=\2a)"
$query = "(uid=$username)";
// Search returns user with UID literal "*":
$result = ldap_search($ldap_connection, $base_dn, $query); Hope this clears things up for you. Let me know if you have any further questions 👍 |
Beta Was this translation helpful? Give feedback.
Hey @andsal,
It's not possible to escape LDAP attributes in LdapRecord. LdapRecord uses PHP's standard
ldap_*
methods when performing creates and updates. Attributes will always be sent in a structured format as strings to your LDAP server. Ex:This is different for LDAP search filters. Input supplied in LDAP search filters must always be escaped, as search filters are constructed similarly to SQL queries, in the sense that the s…