Skip to content

Commit 0fcde87

Browse files
committed
Merge branch 'main' of github.com:kyma-project/busola into bump-backend
2 parents cc4cedc + 779eb6d commit 0fcde87

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

backend/common.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const express = require('express');
77
const path = require('path');
88
const fs = require('fs');
99
const uuid = require('uuid').v4;
10+
const escape = require('lodash.escape');
1011

1112
// https://github.tools.sap/sgs/SAP-Global-Trust-List/blob/master/approved.pem
1213
const certs = fs.readFileSync('certs.pem', 'utf8');
@@ -47,7 +48,7 @@ export const makeHandleRequest = () => {
4748
id: req.id,
4849
method: req.method,
4950
url: req.url,
50-
apiServerAddress: req.headers['x-cluster-url'],
51+
apiServerAddress: escape(req.headers['x-cluster-url']),
5152
code: req.code,
5253
stack: req.stack,
5354
type: req.type,
@@ -63,6 +64,7 @@ export const makeHandleRequest = () => {
6364
headersData = extractHeadersData(req);
6465
} catch (e) {
6566
req.log.error('Headers error:' + e.message);
67+
res.contentType('text/plain');
6668
res.status(400).send('Headers are missing or in a wrong format.');
6769
return;
6870
}
@@ -71,7 +73,8 @@ export const makeHandleRequest = () => {
7173
filters.forEach(filter => filter(req, headersData));
7274
} catch (e) {
7375
req.log.error('Filters rejected the request: ' + e.message);
74-
res.status(400).send('Request ID: ' + req.id);
76+
res.contentType('text/plain');
77+
res.status(400).send('Request ID: ' + escape(req.id));
7578
return;
7679
}
7780

@@ -120,7 +123,10 @@ export const makeHandleRequest = () => {
120123

121124
function throwInternalServerError(originalError) {
122125
req.log.warn(originalError);
123-
res.status(502).send('Request ID: ' + req.id);
126+
res.contentType('text/plain');
127+
res
128+
.status(502)
129+
.send('Internal server error. Request ID: ' + escape(req.id));
124130
}
125131
};
126132
};
@@ -143,11 +149,19 @@ function extractHeadersData(req) {
143149
const clientKeyDataHeader = 'x-client-key-data';
144150
const authorizationHeader = 'x-k8s-authorization';
145151
let targetApiServer;
152+
146153
if (req.headers[urlHeader]) {
147-
targetApiServer = handleDockerDesktopSubsitution(
148-
new URL(req.headers[urlHeader]),
149-
);
154+
try {
155+
targetApiServer = handleDockerDesktopSubsitution(
156+
new URL(req.headers[urlHeader]),
157+
);
158+
} catch (e) {
159+
throw new Error('Invalid cluster URL provided.');
160+
}
161+
} else {
162+
throw new Error('Missing required cluster URL.');
150163
}
164+
151165
const ca = decodeHeaderToBuffer(req.headers[caHeader]) || certs;
152166
const cert = decodeHeaderToBuffer(req.headers[clientCAHeader]);
153167
const key = decodeHeaderToBuffer(req.headers[clientKeyDataHeader]);

backend/package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"https": "^1.0.0",
2121
"jose": "^5.2.4",
2222
"js-yaml": "^4.1.0",
23+
"lodash.escape": "^4.0.1",
2324
"lodash.merge": "^4.6.2",
2425
"pino-http": "^5.7.0",
2526
"uuid": "^8.3.2"

0 commit comments

Comments
 (0)