clone ldapjs input objects

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-01-17 20:48:18 +01:00
parent 4c176a81d6
commit 3368dc6b62
2 changed files with 12 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend-module-ldap': patch
---
Make sure to clone objects sent to `ldapjs` since the library modifies them
@@ -16,6 +16,7 @@
import { ForwardedError } from '@backstage/errors';
import ldap, { Client, SearchEntry, SearchOptions } from 'ldapjs';
import { cloneDeep } from 'lodash';
import { Logger } from 'winston';
import { BindConfig } from './config';
import { errorString } from './util';
@@ -85,7 +86,9 @@ export class LdapClient {
}, 5000);
const search = new Promise<SearchEntry[]>((resolve, reject) => {
this.client.search(dn, options, (err, res) => {
// Note that we clone the (frozen) options, since ldapjs rudely tries to
// overwrite parts of them
this.client.search(dn, cloneDeep(options), (err, res) => {
if (err) {
reject(new Error(errorString(err)));
return;
@@ -137,7 +140,9 @@ export class LdapClient {
): Promise<void> {
try {
return await new Promise<void>((resolve, reject) => {
this.client.search(dn, options, (err, res) => {
// Note that we clone the (frozen) options, since ldapjs rudely tries to
// overwrite parts of them
this.client.search(dn, cloneDeep(options), (err, res) => {
if (err) {
reject(new Error(errorString(err)));
}