Patch #16685

Updated by Toshi MARUYAMA over 3 years ago

Recently, there were several issues where the User.current was not properly initialized and thus the setting from the request before it was used, e.g. #16511 #13041 with r13041 which can lead to data disclosure. This issue and all similar ones can be fully circumvented by ensuring that the current user is reset before the request even reaches our rails code.

This patch which was extracted from "Planio": proposes the introduction of the "request_store gem": It adds a middleware to provide a true request-local data store based on @Thread.current@. This ensures that the current user always needs to be set explicitly and can't be taken from previous requests, even if the logic to setup the user somehow fails or is circumvented due to early error handlers. The fail-safe default is always @User.anonymous@ which should be sufficient even in the face of an auth error.

This patch is against the current master branch on "Github":