Skip to content

Commit

Permalink
Fixed sanitizeUrl function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Tsoganov authored and Sergei Tsoganov committed Jan 25, 2024
1 parent 83d7336 commit a648e67
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions server/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const logger = {
ignoreRoute,
meta: false,
msg: (req, res) => {
return `${req.method} ${req.protocol}://${req.get('host')}${sanitizeUrl(req.originalUrl)} (${
res.statusCode
}) ${Math.floor(res.responseTime / 1000)}, User-Agent: ${req.get(
return `${req.method} ${req.protocol}://${req.get('host')}${sanitizeUrl(
req.originalUrl
)} (${res.statusCode}) ${Math.floor(res.responseTime / 1000)}, User-Agent: ${req.get(
'User-Agent'
)}, Referrer: ${sanitizeUrl(req.get('Referrer'))}, IP: ${
req.ip.indexOf(':') >= 0 ? req.ip.substring(req.ip.lastIndexOf(':') + 1) : req.i
Expand All @@ -30,7 +30,11 @@ const logger = {
function sanitizeUrl(url) {
// Implement URL sanitization logic here
// For example, removing or encoding certain characters
return url.replace(/[{}]/g, encodeURIComponent);
if (typeof url === 'string') {
return url.replace(/[{}]/g, match => encodeURIComponent(match));
} else {
return '';
}
}

export const accessLog = {
Expand Down

0 comments on commit a648e67

Please sign in to comment.