プロジェクト

全般

プロフィール

Vote #75165

完了

Introduce the request_store gem to hold User.current and prevent data leakage in error messages

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Accounts / authentication_7
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

100%

予定工数:
category_id:
7
version_id:
81
issue_org_id:
16685
author_id:
2784
assigned_to_id:
0
comments:
16
status_id:
5
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

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 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":https://plan.io proposes the introduction of the "request_store gem":https://github.com/steveklabnik/request_store. 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":https://github.com/redmine/redmine.


journals

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Test fails on drone.io.

https://drone.io/github.com/marutosi/redmine/211
https://drone.io/github.com/marutosi/redmine/212

<pre>
1) Failure:
test_api_should_trigger_basic_http_auth_with_basic_authorization_header(Redmine::ApiTest::AuthenticationTest)
[/xxxxxxxx/redmine/test/integration/api_test/authentication_test.rb:34]:
Expected response to be a <401>, but was <500>
</pre>

Tests on CI Server pass and I cannot reproduce on my CentOS 6.5.
http://www.redmine.org/builds/index.html
--------------------------------------------------------------------------------
On Ubuntu 12.04.4 LTS,
ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-linux]

<pre>
1) Failure:
test_api_should_trigger_basic_http_auth_with_basic_authorization_header(Redmine::ApiTest::AuthenticationTest)
[test/integration/api_test/authentication_test.rb:34]:
Expected response to be a <401>, but was <500>
</pre>

<pre>
Mocha::ExpectationError (unexpected invocation: #<AnyInstance:UsersController>.authenticate_with_http_basic()
unsatisfied expectations:
- expected exactly once, not yet invoked: #<AnyInstance:ApplicationController>.authenticate_with_http_basic(any_parameters)
):
app/controllers/application_controller.rb:125:in `find_current_user'
app/controllers/application_controller.rb:100:in `user_setup'
test/integration/api_test/authentication_test.rb:33:in `test_api_should_trigger_basic_http_auth_with_basic_authorization_header'
</pre>
--------------------------------------------------------------------------------
Is it really useful to add a new runtime dependency? Wouldn't a complete test be enough instead? And if jot, could that change be targeted to next major release?
--------------------------------------------------------------------------------
Etienne Massip wrote:
> Is it really useful to add a new runtime dependency?
mocha is in "test" group.

> Wouldn't a complete test be enough instead?

It depends web servers, so we cannot add new tests.
https://github.com/steveklabnik/request_store#the-problem

> And if not, could that change be targeted to next major release?
This issue is security fix depends on #16511 with r13041,
so I think it should be targeted to minor release.
--------------------------------------------------------------------------------
I meant request store, not mocha. This should be handled by RoR, not by a specific dependency.
--------------------------------------------------------------------------------
We usually upgrade Rails version for security fix in minor release.
And r13110 does not change application behaviors.
--------------------------------------------------------------------------------
Sure but this is not a security fix, only a potential fix (which from my very personal pov may be a bit of overkill since it seems that all possibilities of having a wrong user in thread are now prevented).
--------------------------------------------------------------------------------
OK. I have reverted 2.4-stable and 2.5-stable revisions.
--------------------------------------------------------------------------------
Thanks, it was just my personal opinion; it may be safer than adding a new gem which might itself contain some security issue we're not aware of!
--------------------------------------------------------------------------------
Etienne: It's way too easy to introduce data leaks when dealing with before filters, either in the core or in Plugins, so this adds an additional safety net.

Also, the gem is actually about 10 lines of code, so not that much of a dependency burden. You could add it into the core if you would be willing to support this code (which I think is pointless here). If you read the "code on github":https://github.com/steveklabnik/request_store/, you'll notice that there isn't much room for bugs. Also, the library is well tested.

In my opinion, it adds a rather easy-to-use safty net under some easy to break code paths.
--------------------------------------------------------------------------------
request_store 1.0.6 breaks many tests.
http://www.redmine.org/builds/logs/build_trunk_postgresql_ruby-2.0.0-p0_1969.html

<pre>
1) Failure: test_api_should_accept_switch_user_header_for_admin_user(Redmine::ApiTest::AuthenticationTest)
...
</pre>
--------------------------------------------------------------------------------
This is probably caused by "this commit":https://github.com/steveklabnik/request_store/commit/cf01d128ceb0425d4d652b95c4333afc9934290f. In 1.0.6, the thread store is cleared after a request has finished (and not before a request started as before). That means, that after the middleware was passed on the way up again, @User.current@ is not valid anymore.

The solution for this would be to fix the integration tests to not rely on an "old" @User.current@. In fact, not having this old value still set after a request is a good thing and solves many potential leakage issues.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

relates,Closed,31911,Update request_store gem to 1.4

Admin Redmine さんが約4年前に更新

  • カテゴリAccounts / authentication_7 にセット
  • 対象バージョン2.6.0_81 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0