Skip to content

Commit 063f6ca

Browse files
Potential fix for code scanning alert no. 82: Log injection
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 1ddff43 commit 063f6ca

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

fixtures/flight/server/global.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ function request(options, body) {
8686
});
8787
}
8888

89+
function sanitizeForLog(value) {
90+
return String(value).replace(/[\r\n]+/g, ' ');
91+
}
92+
8993
async function renderApp(req, res, next) {
9094
// Proxy the request to the regional server.
9195
const proxiedHeaders = {
@@ -202,7 +206,8 @@ async function renderApp(req, res, next) {
202206
},
203207
});
204208
} catch (e) {
205-
console.error(`Failed to SSR: ${e.stack}`);
209+
const safeStack = sanitizeForLog(e && e.stack ? e.stack : e);
210+
console.error(`Failed to SSR: ${safeStack}`);
206211
res.statusCode = 500;
207212
res.end();
208213
}
@@ -219,7 +224,8 @@ async function renderApp(req, res, next) {
219224
res.end();
220225
});
221226
} catch (e) {
222-
console.error(`Failed to proxy request: ${e.stack}`);
227+
const safeStack = sanitizeForLog(e && e.stack ? e.stack : e);
228+
console.error(`Failed to proxy request: ${safeStack}`);
223229
res.statusCode = 500;
224230
res.end();
225231
}

0 commit comments

Comments
 (0)