Merge pull request #8974 from backstage/freben/ldapjs-clone

clone ldapjs input objects
This commit is contained in:
Fredrik Adelöw
2022-01-18 08:26:23 +01:00
committed by GitHub
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)));
}