@zintrust/workers 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ import { Logger } from '@zintrust/core/logger';
4
4
  import { WorkerFactory } from '../WorkerFactory.js';
5
5
  import { WorkerMetrics as WorkerMetricsManager } from '../WorkerMetrics.js';
6
6
  import { WorkerRegistry } from '../WorkerRegistry.js';
7
+ import { maskInfrastructurePasswords } from '../helper/index.js';
7
8
  const DEFAULT_PAGE_SIZE = 100;
8
9
  const MAX_PAGE_SIZE = 200;
9
10
  // Helper for timeout handling
@@ -466,8 +467,8 @@ async function getRedisQueueData() {
466
467
  try {
467
468
  // Use existing queue monitor infrastructure
468
469
  const { QueueMonitor } = await import('@zintrust/queue-monitor');
469
- const { queueConfig } = await import('@zintrust/core/config');
470
- const redisConfig = queueConfig.drivers.redis;
470
+ const { queueConfig: FreshQeueConfig } = await import('@zintrust/core/config');
471
+ const redisConfig = FreshQeueConfig.drivers.redis;
471
472
  if (redisConfig?.driver !== 'redis') {
472
473
  throw ErrorFactory.createConfigError('Redis driver not configured');
473
474
  }
@@ -707,7 +708,7 @@ function buildWorkerConfiguration(worker, persisted) {
707
708
  activeStatus: persisted.activeStatus ?? true,
708
709
  version: persisted.version ?? worker.version,
709
710
  features: persisted.features ?? null,
710
- infrastructure: persisted.infrastructure ?? null,
711
+ infrastructure: maskInfrastructurePasswords(persisted.infrastructure),
711
712
  datacenter: persisted.datacenter ?? null,
712
713
  };
713
714
  }
@@ -3,3 +3,8 @@ import type { IRequest } from '@zintrust/core/http';
3
3
  * Helper to get path parameter
4
4
  */
5
5
  export declare const getParam: (req: IRequest, key: string) => string;
6
+ /**
7
+ * Mask sensitive password fields in infrastructure data
8
+ * This masks both Redis and database passwords to prevent them from being exposed in API responses
9
+ */
10
+ export declare const maskInfrastructurePasswords: (infrastructure: Record<string, unknown> | null | undefined) => Record<string, unknown> | null;
@@ -8,3 +8,54 @@ export const getParam = (req, key) => {
8
8
  const params = req.params ?? {};
9
9
  return params[key] ?? '';
10
10
  };
11
+ /**
12
+ * Mask password in a record if present
13
+ */
14
+ const maskPassword = (obj) => {
15
+ if (typeof obj['password'] === 'string' && obj['password'].length > 0) {
16
+ obj['password'] = '******';
17
+ }
18
+ };
19
+ /**
20
+ * Mask passwords in a nested connection object
21
+ */
22
+ const maskConnectionPassword = (persistence) => {
23
+ if (typeof persistence['connection'] === 'object' && persistence['connection'] !== null) {
24
+ const connection = { ...persistence['connection'] };
25
+ maskPassword(connection);
26
+ persistence['connection'] = connection;
27
+ }
28
+ };
29
+ /**
30
+ * Mask Redis password in infrastructure data
31
+ */
32
+ const maskRedisPassword = (masked) => {
33
+ if (typeof masked['redis'] === 'object' && masked['redis'] !== null) {
34
+ const redis = { ...masked['redis'] };
35
+ maskPassword(redis);
36
+ masked['redis'] = redis;
37
+ }
38
+ };
39
+ /**
40
+ * Mask persistence password in infrastructure data
41
+ */
42
+ const maskPersistencePassword = (masked) => {
43
+ if (typeof masked['persistence'] === 'object' && masked['persistence'] !== null) {
44
+ const persistence = { ...masked['persistence'] };
45
+ maskPassword(persistence);
46
+ maskConnectionPassword(persistence);
47
+ masked['persistence'] = persistence;
48
+ }
49
+ };
50
+ /**
51
+ * Mask sensitive password fields in infrastructure data
52
+ * This masks both Redis and database passwords to prevent them from being exposed in API responses
53
+ */
54
+ export const maskInfrastructurePasswords = (infrastructure) => {
55
+ if (!infrastructure)
56
+ return null;
57
+ const masked = { ...infrastructure };
58
+ maskRedisPassword(masked);
59
+ maskPersistencePassword(masked);
60
+ return masked;
61
+ };
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { Logger } from '@zintrust/core/logger';
6
6
  import { getWorkerDetails, getWorkers } from '../dashboard/workers-api.js';
7
- import { getParam } from '../helper/index.js';
7
+ import { getParam, maskInfrastructurePasswords } from '../helper/index.js';
8
8
  import { WorkerFactory } from '../WorkerFactory.js';
9
9
  /**
10
10
  * Helper to safely get a single string value from query params
@@ -76,7 +76,24 @@ export const listWorkers = async (req, res) => {
76
76
  includeInactive: getBooleanParam(query, 'includeInactive', false),
77
77
  };
78
78
  const result = await getWorkers(queryParams);
79
- res.json(result);
79
+ // Mask passwords in infrastructure data for all workers
80
+ const maskedWorkers = result.workers.map((worker) => {
81
+ const maskedWorker = { ...worker };
82
+ if (maskedWorker.details?.configuration) {
83
+ maskedWorker.details = {
84
+ ...maskedWorker.details,
85
+ configuration: {
86
+ ...maskedWorker.details.configuration,
87
+ infrastructure: maskInfrastructurePasswords(maskedWorker.details.configuration['infrastructure']),
88
+ },
89
+ };
90
+ }
91
+ return maskedWorker;
92
+ });
93
+ res.json({
94
+ ...result,
95
+ workers: maskedWorkers,
96
+ });
80
97
  }
81
98
  catch (error) {
82
99
  Logger.error('Error fetching workers:', error);
@@ -98,6 +115,7 @@ export const getWorkerDetailsHandler = async (req, res) => {
98
115
  }
99
116
  const driver = getQueryParam(req.getQuery?.() || {}, 'driver');
100
117
  const details = await getWorkerDetails(name, driver);
118
+ // Password masking is already applied in buildWorkerConfiguration
101
119
  res.json(details);
102
120
  }
103
121
  catch (error) {
@@ -195,6 +213,7 @@ const getWorkerJsonHandler = async (req, res) => {
195
213
  code: 'WORKER_NOT_FOUND',
196
214
  });
197
215
  }
216
+ // Mask passwords in infrastructure data (already applied in buildWorkerConfiguration)
198
217
  return res.json({
199
218
  success: true,
200
219
  data: worker,
@@ -231,9 +250,14 @@ const getWorkerDriverDataHandler = async (req, res) => {
231
250
  code: 'WORKER_NOT_FOUND',
232
251
  });
233
252
  }
253
+ // Mask passwords in infrastructure data
254
+ const maskedData = {
255
+ ...persistedData,
256
+ infrastructure: maskInfrastructurePasswords(persistedData['infrastructure']),
257
+ };
234
258
  return res.json({
235
259
  success: true,
236
- data: persistedData,
260
+ data: maskedData,
237
261
  });
238
262
  }
239
263
  catch (error) {
@@ -281,6 +305,7 @@ const updateWorkerJsonHandler = async (req, res) => {
281
305
  // For now, return the updated data as if it was updated
282
306
  // In a real implementation, this would update the worker in the database
283
307
  const updatedWorker = { ...existingWorker, ...workerData };
308
+ // Password masking is already applied in buildWorkerConfiguration via getWorkerDetails
284
309
  return res.json({
285
310
  success: true,
286
311
  data: updatedWorker,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/workers",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Worker orchestration and background job management for ZinTrust.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -4,6 +4,7 @@ import { Logger } from '@zintrust/core/logger';
4
4
  import { WorkerFactory } from '../WorkerFactory';
5
5
  import { WorkerMetrics as WorkerMetricsManager } from '../WorkerMetrics';
6
6
  import { WorkerRegistry } from '../WorkerRegistry';
7
+ import { maskInfrastructurePasswords } from '../helper';
7
8
  import type { WorkerRecord } from '../storage/WorkerStore';
8
9
  import type {
9
10
  GetWorkersQuery,
@@ -615,9 +616,9 @@ async function getRedisQueueData(): Promise<QueueData> {
615
616
  try {
616
617
  // Use existing queue monitor infrastructure
617
618
  const { QueueMonitor } = await import('@zintrust/queue-monitor');
618
- const { queueConfig } = await import('@zintrust/core/config');
619
+ const { queueConfig: FreshQeueConfig } = await import('@zintrust/core/config');
619
620
 
620
- const redisConfig = queueConfig.drivers.redis;
621
+ const redisConfig = FreshQeueConfig.drivers.redis;
621
622
  if (redisConfig?.driver !== 'redis') {
622
623
  throw ErrorFactory.createConfigError('Redis driver not configured');
623
624
  }
@@ -912,7 +913,7 @@ function buildWorkerConfiguration(
912
913
  activeStatus: persisted.activeStatus ?? true,
913
914
  version: persisted.version ?? worker.version,
914
915
  features: persisted.features ?? null,
915
- infrastructure: persisted.infrastructure ?? null,
916
+ infrastructure: maskInfrastructurePasswords(persisted.infrastructure),
916
917
  datacenter: persisted.datacenter ?? null,
917
918
  };
918
919
  }
@@ -9,3 +9,63 @@ export const getParam = (req: IRequest, key: string): string => {
9
9
  const params = (req.params as Record<string, string> | undefined) ?? {};
10
10
  return params[key] ?? '';
11
11
  };
12
+
13
+ /**
14
+ * Mask password in a record if present
15
+ */
16
+ const maskPassword = (obj: Record<string, unknown>): void => {
17
+ if (typeof obj['password'] === 'string' && obj['password'].length > 0) {
18
+ obj['password'] = '******';
19
+ }
20
+ };
21
+
22
+ /**
23
+ * Mask passwords in a nested connection object
24
+ */
25
+ const maskConnectionPassword = (persistence: Record<string, unknown>): void => {
26
+ if (typeof persistence['connection'] === 'object' && persistence['connection'] !== null) {
27
+ const connection = { ...(persistence['connection'] as Record<string, unknown>) };
28
+ maskPassword(connection);
29
+ persistence['connection'] = connection;
30
+ }
31
+ };
32
+
33
+ /**
34
+ * Mask Redis password in infrastructure data
35
+ */
36
+ const maskRedisPassword = (masked: Record<string, unknown>): void => {
37
+ if (typeof masked['redis'] === 'object' && masked['redis'] !== null) {
38
+ const redis = { ...(masked['redis'] as Record<string, unknown>) };
39
+ maskPassword(redis);
40
+ masked['redis'] = redis;
41
+ }
42
+ };
43
+
44
+ /**
45
+ * Mask persistence password in infrastructure data
46
+ */
47
+ const maskPersistencePassword = (masked: Record<string, unknown>): void => {
48
+ if (typeof masked['persistence'] === 'object' && masked['persistence'] !== null) {
49
+ const persistence = { ...(masked['persistence'] as Record<string, unknown>) };
50
+ maskPassword(persistence);
51
+ maskConnectionPassword(persistence);
52
+ masked['persistence'] = persistence;
53
+ }
54
+ };
55
+
56
+ /**
57
+ * Mask sensitive password fields in infrastructure data
58
+ * This masks both Redis and database passwords to prevent them from being exposed in API responses
59
+ */
60
+ export const maskInfrastructurePasswords = (
61
+ infrastructure: Record<string, unknown> | null | undefined
62
+ ): Record<string, unknown> | null => {
63
+ if (!infrastructure) return null;
64
+
65
+ const masked = { ...infrastructure };
66
+
67
+ maskRedisPassword(masked);
68
+ maskPersistencePassword(masked);
69
+
70
+ return masked;
71
+ };
@@ -13,7 +13,7 @@ import type {
13
13
  WorkerStatus,
14
14
  } from '../dashboard/types';
15
15
  import { getWorkerDetails, getWorkers } from '../dashboard/workers-api';
16
- import { getParam } from '../helper';
16
+ import { getParam, maskInfrastructurePasswords } from '../helper';
17
17
  import { WorkerFactory } from '../WorkerFactory';
18
18
 
19
19
  /**
@@ -116,7 +116,28 @@ export const listWorkers = async (req: IRequest, res: IResponse): Promise<void>
116
116
  };
117
117
 
118
118
  const result = await getWorkers(queryParams);
119
- res.json(result);
119
+
120
+ // Mask passwords in infrastructure data for all workers
121
+ const maskedWorkers = result.workers.map((worker) => {
122
+ const maskedWorker = { ...worker };
123
+ if (maskedWorker.details?.configuration) {
124
+ maskedWorker.details = {
125
+ ...maskedWorker.details,
126
+ configuration: {
127
+ ...maskedWorker.details.configuration,
128
+ infrastructure: maskInfrastructurePasswords(
129
+ maskedWorker.details.configuration['infrastructure'] as Record<string, unknown> | null
130
+ ),
131
+ },
132
+ };
133
+ }
134
+ return maskedWorker;
135
+ });
136
+
137
+ res.json({
138
+ ...result,
139
+ workers: maskedWorkers,
140
+ });
120
141
  } catch (error) {
121
142
  Logger.error('Error fetching workers:', error);
122
143
  res.status(500).json({
@@ -138,6 +159,8 @@ export const getWorkerDetailsHandler = async (req: IRequest, res: IResponse): Pr
138
159
  }
139
160
  const driver = getQueryParam(req.getQuery?.() || {}, 'driver');
140
161
  const details = await getWorkerDetails(name, driver);
162
+
163
+ // Password masking is already applied in buildWorkerConfiguration
141
164
  res.json(details);
142
165
  } catch (error) {
143
166
  if (error instanceof Error && error.message.includes('not found')) {
@@ -239,6 +262,7 @@ const getWorkerJsonHandler = async (req: IRequest, res: IResponse): Promise<void
239
262
  });
240
263
  }
241
264
 
265
+ // Mask passwords in infrastructure data (already applied in buildWorkerConfiguration)
242
266
  return res.json({
243
267
  success: true,
244
268
  data: worker,
@@ -279,9 +303,17 @@ const getWorkerDriverDataHandler = async (req: IRequest, res: IResponse): Promis
279
303
  });
280
304
  }
281
305
 
306
+ // Mask passwords in infrastructure data
307
+ const maskedData = {
308
+ ...persistedData,
309
+ infrastructure: maskInfrastructurePasswords(
310
+ persistedData['infrastructure'] as Record<string, unknown> | null
311
+ ),
312
+ };
313
+
282
314
  return res.json({
283
315
  success: true,
284
- data: persistedData,
316
+ data: maskedData,
285
317
  });
286
318
  } catch (error) {
287
319
  Logger.error('Failed to get worker driver data', error);
@@ -337,6 +369,7 @@ const updateWorkerJsonHandler = async (req: IRequest, res: IResponse): Promise<v
337
369
  // In a real implementation, this would update the worker in the database
338
370
  const updatedWorker = { ...existingWorker, ...workerData };
339
371
 
372
+ // Password masking is already applied in buildWorkerConfiguration via getWorkerDetails
340
373
  return res.json({
341
374
  success: true,
342
375
  data: updatedWorker,