You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While updating some components, I ran into a rather interesting problem related to using this library for logging express requests. My express instance runs @tus/server, which uses srvx for API unification, and it internally uses flat array, not object, to write response headers - and those headers were broken. At first I've modified srvx internals to find out that change from Array to Object fixed my issue, but Node docs list array as supported value for headers - so it should work with arrays.
TL;DR
I know it's a bit convoluted, but to put it simply – the issue is that with morgan enabled, instead of response headers like these:
morgan is internally calling (eventually) setHeadersFromArray in on-headers, passing in: ['content-type', 'text/plain', 'x-testing', 'true'], so it ends up setting headers:
content-type -> c: o
text/plain -> t: e
x-testing -> x: -
and then t gets written over:
true -> t: r
aside from that bug in on-headers, I still don't like the fact that what is ostensibly a logging middleware is inadvertently manipulating response headers (or anything for that matter)
Activity
ctcpip commentedon Jun 17, 2025
the root cause is this issue: jshttp/on-headers#15
morgan is internally calling (eventually) setHeadersFromArray in on-headers, passing in:
['content-type', 'text/plain', 'x-testing', 'true'], so it ends up setting headers:content-type -> c: o
text/plain -> t: e
x-testing -> x: -
and then t gets written over:
true -> t: r
aside from that bug in
on-headers, I still don't like the fact that what is ostensibly a logging middleware is inadvertently manipulating response headers (or anything for that matter)caasi commentedon Jun 24, 2025
A quick workaround is enabling the immediate log mode to prevent calling
onHeaders.ctcpip commentedon Jul 17, 2025
resolved via GHSA-76c9-3jph-rj3q
ctcpip commentedon Jul 17, 2025
morgan 1.1.0 is published now with the patched version of on-headers