Skip to content

middleware/DefaultLoggerConfig looks like JSON, but doesn't escape #2846

@Drahflow

Description

@Drahflow

https://github.com/labstack/echo/blob/612967a9fec11b112a16c7b62efc2344eae308e8/middleware/logger.go#L205,L208 defines a JSON-like log format, suggesting logs will be formatted as JSON when it is used.

However, no escaping takes place.

Running the Example from README.md and then

% echo -ne 'GET /?","method":":D","remote_ip":"123.456.789.101112","_":" HTTP/1.0\r\n\r\n' | netcat 127.0.0.1 8080

results in this log:

{"time":"2025-12-09T17:55:44.83979515+01:00","id":"","remote_ip":"127.0.0.1","host":"","method":"GET","uri":"/?","method":":D","remote_ip":"123.456.789.101112","_":"","user_agent":"","status":200,"error":"","latency":8089,"latency_human":"8.089µs","bytes_in":0,"bytes_out":13}

Parsing that as JSON (e.g. with jq) gives

{
  "time": "2025-12-09T17:55:44.83979515+01:00",
  "id": "",
  "remote_ip": "123.456.789.101112",
  "host": "",
  "method": ":D",
  "uri": "/?",
  "_": "",
  "user_agent": "",
  "status": 200,
  "error": "",
  "latency": 8089,
  "latency_human": "8.089µs",
  "bytes_in": 0,
  "bytes_out": 13
}

I.e. the attacker is free to overwrite fields or (at their discretion) break JSON parsing completely.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions