Only set ldap allowlist if file exists and is not empty
This commit is contained in:
@@ -516,15 +516,20 @@ async function setExposedLdapConfig(exposedLdapConfig) {
|
||||
const config = {
|
||||
enabled: exposedLdapConfig.enabled,
|
||||
// if list is empty, we allow all IPs
|
||||
allowlist: exposedLdapConfig.allowlist || '0.0.0.0/0'
|
||||
allowlist: exposedLdapConfig.allowlist || ''
|
||||
};
|
||||
|
||||
if (config.enabled) {
|
||||
let gotOne = false;
|
||||
for (const line of exposedLdapConfig.allowlist.split('\n')) {
|
||||
if (!line || line.startsWith('#')) continue;
|
||||
const rangeOrIP = line.trim();
|
||||
if (!validator.isIP(rangeOrIP) && !validator.isIPRange(rangeOrIP)) throw new BoxError(BoxError.BAD_FIELD, `${rangeOrIP} is not a valid IP or range`);
|
||||
gotOne = true;
|
||||
}
|
||||
|
||||
// only allow if we at least have one allowed IP/range
|
||||
if (!gotOne) throw new BoxError(BoxError.BAD_FIELD, 'allowlist must at least contain one IP or range');
|
||||
}
|
||||
|
||||
await set(exports.EXPOSED_LDAP_KEY, JSON.stringify(config));
|
||||
|
||||
Reference in New Issue
Block a user