@aikidosec/broker-client 1.0.4 → 1.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.
- package/app/client.js +23 -8
- package/package.json +1 -1
package/app/client.js
CHANGED
|
@@ -37,9 +37,12 @@ const DNS_SERVERS = process.env.DNS_SERVERS
|
|
|
37
37
|
: null;
|
|
38
38
|
|
|
39
39
|
// Configure axios defaults
|
|
40
|
+
const MAX_RESPONSE_SIZE = 100 * 1024 * 1024; // 100 MB
|
|
40
41
|
const axiosConfig = {
|
|
41
42
|
timeout: 30000,
|
|
42
|
-
maxRedirects: 5
|
|
43
|
+
maxRedirects: 5,
|
|
44
|
+
maxContentLength: MAX_RESPONSE_SIZE,
|
|
45
|
+
maxBodyLength: MAX_RESPONSE_SIZE
|
|
43
46
|
};
|
|
44
47
|
|
|
45
48
|
// Create axios instance for internal requests
|
|
@@ -232,7 +235,8 @@ const socket = io(SERVER_URL, {
|
|
|
232
235
|
reconnectionDelayMax: 30000,
|
|
233
236
|
randomizationFactor: 0.5,
|
|
234
237
|
tryAllTransports: true, // if we don't, it won't try to fallback from websocket to polling
|
|
235
|
-
autoConnect: false // Don't connect until after registration
|
|
238
|
+
autoConnect: false, // Don't connect until after registration
|
|
239
|
+
withCredentials: true // make sure cookies work for sticky sessions
|
|
236
240
|
});
|
|
237
241
|
|
|
238
242
|
// Socket.IO event handlers
|
|
@@ -300,7 +304,7 @@ socket.on('forward_request', async (data, callback) => {
|
|
|
300
304
|
request_id: requestId,
|
|
301
305
|
status_code: 403,
|
|
302
306
|
headers: {},
|
|
303
|
-
body: 'Target URL is not an allowed internal resource'
|
|
307
|
+
body: formatMessageBody('Target URL is not an allowed internal resource')
|
|
304
308
|
});
|
|
305
309
|
return;
|
|
306
310
|
}
|
|
@@ -310,7 +314,7 @@ socket.on('forward_request', async (data, callback) => {
|
|
|
310
314
|
request_id: requestId,
|
|
311
315
|
status_code: 403,
|
|
312
316
|
headers: {},
|
|
313
|
-
body: 'Target URL is not in the allowed resources list'
|
|
317
|
+
body: formatMessageBody('Target URL is not in the allowed resources list')
|
|
314
318
|
});
|
|
315
319
|
return;
|
|
316
320
|
}
|
|
@@ -337,30 +341,41 @@ socket.on('forward_request', async (data, callback) => {
|
|
|
337
341
|
url: resolvedUrl,
|
|
338
342
|
headers,
|
|
339
343
|
data: body,
|
|
340
|
-
validateStatus: () => true // Accept any status code
|
|
344
|
+
validateStatus: () => true, // Accept any status code
|
|
345
|
+
responseType: 'arraybuffer', // Get raw bytes, don't parse JSON
|
|
341
346
|
});
|
|
342
347
|
|
|
343
348
|
log.info(`Successfully forwarded request ${requestId} to ${targetUrl}, status: ${response.status}`);
|
|
344
349
|
|
|
345
350
|
// Return response via acknowledgement
|
|
351
|
+
// Send body as base64 to preserve binary data byte-for-byte (critical for Docker registry digests)
|
|
352
|
+
const responseBody = response.data ? Buffer.from(response.data).toString('base64') : null;
|
|
353
|
+
|
|
346
354
|
callback({
|
|
347
355
|
request_id: requestId,
|
|
348
356
|
status_code: response.status,
|
|
349
357
|
headers: response.headers,
|
|
350
|
-
body:
|
|
358
|
+
body: responseBody,
|
|
359
|
+
version: 2
|
|
351
360
|
});
|
|
352
361
|
|
|
353
362
|
} catch (error) {
|
|
354
|
-
log.error(`Error forwarding request ${requestId} to ${targetUrl}: ${error.message}`);
|
|
363
|
+
log.error(`Error forwarding request ${requestId} to ${targetUrl}: ${error?.response?.status || error.message}`);
|
|
364
|
+
const errorMessage = `Error reaching internal resource: ${error?.response?.status || error.message}`;
|
|
355
365
|
callback({
|
|
356
366
|
request_id: requestId,
|
|
357
367
|
status_code: 502,
|
|
358
368
|
headers: {},
|
|
359
|
-
body:
|
|
369
|
+
body: formatMessageBody(errorMessage),
|
|
370
|
+
version: 2
|
|
360
371
|
});
|
|
361
372
|
}
|
|
362
373
|
});
|
|
363
374
|
|
|
375
|
+
function formatMessageBody(message) {
|
|
376
|
+
return Buffer.from(message, 'utf-8').toString('base64');
|
|
377
|
+
}
|
|
378
|
+
|
|
364
379
|
/**
|
|
365
380
|
* Register this client with the broker server
|
|
366
381
|
*/
|
package/package.json
CHANGED