Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any reason to not always generate a random request_id in middleware? #9

Closed
gtmax opened this issue May 19, 2019 · 1 comment
Closed

Comments

@gtmax
Copy link

gtmax commented May 19, 2019

In https://github.com/ElMassimo/request_store_rails/blob/master/lib/request_store_rails/middleware.rb#L27 env['action_dispatch.request_id'] || env['HTTP_X_REQUEST_ID'] are used as the base for request_id - why not always generate a random one? Using the forwarded request_id seems to allow room for accidentally sharing the RequestLocals, e.g. in a scenario of a multi-threaded web server that makes another request with forwarded request_id which ends up being processed on the same server instance.

@ElMassimo
Copy link
Owner

Some applications benefit from sharing the cache across requests with the same id that are being handled concurrently, but I agree it would be safer not to rely on the request id provided by the ActionDispatch::RequestId middleware, which might be useful for tracing purposes but leaves room for accidents in this use case.

Will cut a new release that uses SecureRandom.uuid instead.

Thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants