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
I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal
Add a option to disable requestIdHeader overwriting genReqId
Motivation
As far as I understand, fastify will by default use the value of the requestIdHeader,if such a header is present in the request, over the genReqId value.
Now, one does not necessarily know that a server is a fastify server, and one can change (obfuscate) the header key, but essentially a malicious actor could pass the same request-id for all requests and therefore reduce the quality of the logs. If one is trying to investigate an incident multiple requests now share the same id.
This is of low impact I'd assume, still I think it would be nice to disable this behaviour in a proper way instead of relying on obfuscation.
@Eomm Thank you for the quick reply.
What I meant was to disable requestIdHeader overwriting genReqId(), so untrusted requests can not overwrite my reqId.
This is the internal code: const id = req.headers[requestIdHeader] || genReqId(req)
The only way is to (like you did) change the requestIdHeader to a bogus value. Which is honestly secure enough. Just not very clean in my opinion.
@mcollina Sorry, I don't think I understand how/what you mean.
Simply req.headers[requestIdHeader] || genReqId(req) inside genReqId(factory) would obviously get overwritten by any custom genRegId(setup), therefore removing the requestIdHeader functionality. So, I don't think you mean it this way.
Okey, I have a PR, it's my first one ever. It does not use the reqIdGenFactory because I could not get it to work using the factory just yet. Sorry. Have a look at it maybe, it's to hackish...
Activity
Eomm commentedon Aug 10, 2022
It is already doable (not straight forward tbh)
What I understood is that you don't want to log the
reqIdfieldphilippviereck commentedon Aug 10, 2022
@Eomm Thank you for the quick reply.
What I meant was to disable
requestIdHeaderoverwritinggenReqId(), so untrusted requests can not overwrite myreqId.This is the internal code:
const id = req.headers[requestIdHeader] || genReqId(req)The only way is to (like you did) change the
requestIdHeaderto a bogus value. Which is honestly secure enough. Just not very clean in my opinion.Eomm commentedon Aug 10, 2022
Oh, I got it! The issue here is to choose the priority of the genId option over the header 👍🏼
Yeah, I agree!
Would you like to submit a pr?
mcollina commentedon Aug 10, 2022
I think a better implementation is to move that
||switch insidegenReqIditself: https://github.com/fastify/fastify/blob/main/lib/reqIdGenFactory.js.Would you like to send a PR?
philippviereck commentedon Aug 10, 2022
@mcollina Sorry, I don't think I understand how/what you mean.
Simply
req.headers[requestIdHeader] || genReqId(req)insidegenReqId(factory) would obviously get overwritten by any customgenRegId(setup), therefore removing therequestIdHeaderfunctionality. So, I don't think you mean it this way.mcollina commentedon Aug 10, 2022
Just move the check inside
genReqId(req).add option to disable/ignore request-id header
philippviereck commentedon Aug 10, 2022
Okey, I have a PR, it's my first one ever. It does not use the
reqIdGenFactorybecause I could not get it to work using the factory just yet. Sorry. Have a look at it maybe, it's to hackish...Maybe in 2 weeks I have time to dig deeper...
feat: disable/ignore request-id header (#4193)
Change request id header default value to false (#4194)