Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion debug_api_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const app = express()
const port = 3999

app.use('/api',(req, res, next) => {
console.log(req.headers)
process.stdout.write(JSON.stringify(req.headers) + '\n')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

The application logs the entire "req.headers" object, which can expose sensitive information like session tokens ("Cookie"), authentication credentials ("Authorization"), and API keys ("X-Api-Key") in system logs. It is recommended to redact or filter sensitive headers before logging. Additionally, while "process.stdout.write" can be faster, its direct use here is unsafe for a server handling requests as it does not handle backpressure. This can lead to event loop blocking, high memory usage, and server crashes under load. For high-performance and safe logging, consider a dedicated logging library like "pino" or "winston" that also supports redaction.

    const redactedHeaders = { ...req.headers };
    ['authorization', 'cookie', 'set-cookie', 'x-api-key'].forEach(h => {
      if (redactedHeaders[h]) redactedHeaders[h] = '[REDACTED]';
    });
    process.stdout.write(JSON.stringify(redactedHeaders) + '\n')

res.setHeader('content-type','application/json')
res.send(req.headers)
next()
Expand Down