Unverified Commit 1f48583b authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(acl) Add a hard limit of 100 targets matched for an ACL target filter

This avoids performanance problems and RAM exhaustion.

issue #5531
Showing with 13 additions and 0 deletions
+13 -0
...@@ -137,6 +137,7 @@ class userinfo ...@@ -137,6 +137,7 @@ class userinfo
$this->reset_acl_cache(); $this->reset_acl_cache();
$ldap = $config->get_ldap_link(); $ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']); $ldap->cd($config->current['BASE']);
$targetFilterLimit = 100;
/* Get member groups... */ /* Get member groups... */
$ldap->search('(&(objectClass=groupOfNames)(member='.ldap_escape_f($this->dn).'))', ['dn']); $ldap->search('(&(objectClass=groupOfNames)(member='.ldap_escape_f($this->dn).'))', ['dn']);
...@@ -229,12 +230,24 @@ class userinfo ...@@ -229,12 +230,24 @@ class userinfo
if (!empty($ACLRule['targetfilter'])) { if (!empty($ACLRule['targetfilter'])) {
$ldap->cd($dn); $ldap->cd($dn);
$ldap->set_size_limit($targetFilterLimit);
$targetFilter = templateHandling::parseString($ACLRule['targetfilter'], $this->cachedAttrs, 'ldap_escape_f'); $targetFilter = templateHandling::parseString($ACLRule['targetfilter'], $this->cachedAttrs, 'ldap_escape_f');
$ldap->search($targetFilter, ['dn']); $ldap->search($targetFilter, ['dn']);
if ($ldap->hitSizeLimit()) {
msg_dialog::display(
_('Error'),
sprintf(
_('An ACL assignment for the connected user matched more than than the %d objects limit. This user will not have the ACL rights he should.'),
$targetFilterLimit
),
ERROR_DIALOG
);
}
$targetDns = []; $targetDns = [];
while ($targetAttrs = $ldap->fetch()) { while ($targetAttrs = $ldap->fetch()) {
$targetDns[] = $targetAttrs['dn']; $targetDns[] = $targetAttrs['dn'];
} }
$ldap->set_size_limit(0);
} else { } else {
$targetDns = [$dn]; $targetDns = [$dn];
} }
......
  • SonarQube analysis reported 1 issue

    • :warning: 1 major

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. :warning: This function "loadACL" has 158 lines, which is greater than the 150 lines authorized. Split it into smaller functions. :blue_book:

    By Ghost User on 2019-10-08T08:24:56 (imported from GitLab)

Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment