-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
LDAP variables can be integers #35701
Conversation
Signed-off-by: Alexie Papanicolaou <alpapan@gmail.com>
@@ -192,7 +192,8 @@ | |||
*/ | |||
protected function getDNHash(string $fdn): string { | |||
$hash = hash('sha256', $fdn, false); | |||
if (is_string($hash)) { | |||
// very rare but a hash could just be numbers? is_string(int) would return false | |||
if (is_string($hash) || is_numeric($hash)) { |
Check failure
Code scanning / Psalm
TypeDoesNotContainType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory a sha256 can return just numbers. PHP will parse that as numeric and not a string AFAIK.
apps/user_ldap/lib/Configuration.php
Outdated
@@ -332,7 +332,7 @@ | |||
} else { | |||
$finalValue = []; | |||
foreach ($value as $key => $val) { | |||
if (is_string($val)) { | |||
if (is_string($val) || is_numeric($int)) { |
Check failure
Code scanning / Psalm
UndefinedVariable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, that's my mistake!
@@ -703,7 +703,8 @@ | |||
if ($userMatch !== false) { | |||
// match found so this user is in this group | |||
$groupName = $this->access->dn2groupname($dynamicGroup['dn'][0]); | |||
if (is_string($groupName)) { | |||
// in case it is just an integer (is_string(int) returns false | |||
if (is_string($groupName) || is_numeric($groupName)) { |
Check notice
Code scanning / Psalm
DocblockTypeContradiction
@@ -1191,7 +1194,8 @@ | |||
if ($dn = $this->groupPluginManager->createGroup($gid)) { | |||
//updates group mapping | |||
$uuid = $this->access->getUUID($dn, false); | |||
if (is_string($uuid)) { | |||
// in case it is just an integer, not sure if this UUID could ever be an int though | |||
if (is_string($uuid) || is_numeric($uuid)) { |
Check notice
Code scanning / Psalm
DocblockTypeContradiction
@@ -304,7 +304,8 @@ | |||
* @throws \OC\ServerNotAvailableException | |||
*/ | |||
public function userExistsOnLDAP($user, bool $ignoreCache = false): bool { | |||
if (is_string($user)) { | |||
// in case it is just an integer (is_string(int) returns false | |||
if (is_string($user) || is_numeric($user)) { |
Check notice
Code scanning / Psalm
DocblockTypeContradiction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't the username be just numbers?
@@ -645,7 +646,8 @@ | |||
if (is_string($dn)) { | |||
// the NC user creation work flow requires a know user id up front | |||
$uuid = $this->access->getUUID($dn, true); | |||
if (is_string($uuid)) { | |||
// not sure if UUID could ever be just a number | |||
if (is_string($uuid) || is_numeric($uuid)) { |
Check notice
Code scanning / Psalm
DocblockTypeContradiction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK what UUID is but if it can ever be a string of integers, PHP parses that as an integer not a string (no typecasting)
@@ -730,7 +731,8 @@ | |||
$groupDNs = $this->_getGroupDNsFromMemberOf($userDN); | |||
foreach ($groupDNs as $dn) { | |||
$groupName = $this->access->dn2groupname($dn); | |||
if (is_string($groupName)) { | |||
// in case it is just an integer (is_string(int) returns false | |||
if (is_string($groupName) || is_numeric($groupName)) { |
Check notice
Code scanning / Psalm
DocblockTypeContradiction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can't the name of a group be just numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with psalm that all these is_numeric checks are redundant. I will look into the bug and backtrace to try to understand what happens, ldap_* methods should always return values as strings to my knowledge, I need to look into where this int comes from.
Hello @alpapan, looks like the original issue was solved with a different approach! Wanted to still thank you for your contribution and hope to seeing more from you! 🚀 |
Signed-off-by: Alexie Papanicolaou alpapan@gmail.com
Some LDAP variables (such as cn / uids, group names) can be only integers. The is_string(int) returns false.
This commit adds an || is_numeric or !is_array() check for these use cases.
added // comments above most changes. I was not sure what UUID was and whether it could ever be just a number.
TODO
Please review.
Checklist