##// END OF EJS Templates
security: fixed issues with exposing repository names using global PR redirection link...
marcink -
r4044:573a1043 default
parent child Browse files
Show More
@@ -1,72 +1,79 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2019 RhodeCode GmbH
3 # Copyright (C) 2016-2019 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import logging
21 import logging
22
22
23 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
23 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
24 from pyramid.view import view_config
24 from pyramid.view import view_config
25
25
26 from rhodecode.apps._base import BaseAppView
26 from rhodecode.apps._base import BaseAppView
27 from rhodecode.lib import helpers as h
27 from rhodecode.lib import helpers as h
28 from rhodecode.lib.auth import (LoginRequired, NotAnonymous)
28 from rhodecode.lib.auth import (LoginRequired, NotAnonymous, HasRepoPermissionAny)
29 from rhodecode.model.db import PullRequest
29 from rhodecode.model.db import PullRequest
30
30
31
31
32 log = logging.getLogger(__name__)
32 log = logging.getLogger(__name__)
33
33
34
34
35 class AdminMainView(BaseAppView):
35 class AdminMainView(BaseAppView):
36 def load_default_context(self):
36 def load_default_context(self):
37 c = self._get_local_tmpl_context()
37 c = self._get_local_tmpl_context()
38 return c
38 return c
39
39
40 @LoginRequired()
40 @LoginRequired()
41 @NotAnonymous()
41 @NotAnonymous()
42 @view_config(
42 @view_config(
43 route_name='admin_home', request_method='GET',
43 route_name='admin_home', request_method='GET',
44 renderer='rhodecode:templates/admin/main.mako')
44 renderer='rhodecode:templates/admin/main.mako')
45 def admin_main(self):
45 def admin_main(self):
46 c = self.load_default_context()
46 c = self.load_default_context()
47 c.active = 'admin'
47 c.active = 'admin'
48
48
49 if not (c.is_super_admin or c.is_delegated_admin):
49 if not (c.is_super_admin or c.is_delegated_admin):
50 raise HTTPNotFound()
50 raise HTTPNotFound()
51
51
52 return self._get_template_context(c)
52 return self._get_template_context(c)
53
53
54 @LoginRequired()
54 @LoginRequired()
55 @view_config(route_name='pull_requests_global_0', request_method='GET')
55 @view_config(route_name='pull_requests_global_0', request_method='GET')
56 @view_config(route_name='pull_requests_global_1', request_method='GET')
56 @view_config(route_name='pull_requests_global_1', request_method='GET')
57 @view_config(route_name='pull_requests_global', request_method='GET')
57 @view_config(route_name='pull_requests_global', request_method='GET')
58 def pull_requests(self):
58 def pull_requests(self):
59 """
59 """
60 Global redirect for Pull Requests
60 Global redirect for Pull Requests
61 pull_request_id: id of pull requests in the system
61 pull_request_id: id of pull requests in the system
62 """
62 """
63
63
64 pull_request = PullRequest.get_or_404(
64 pull_request = PullRequest.get_or_404(
65 self.request.matchdict['pull_request_id'])
65 self.request.matchdict['pull_request_id'])
66 pull_request_id = pull_request.pull_request_id
66 pull_request_id = pull_request.pull_request_id
67
67
68 repo_name = pull_request.target_repo.repo_name
68 repo_name = pull_request.target_repo.repo_name
69 # NOTE(marcink):
70 # check permissions so we don't redirect to repo that we don't have access to
71 # exposing it's name
72 target_repo_perm = HasRepoPermissionAny(
73 'repository.read', 'repository.write', 'repository.admin')(repo_name)
74 if not target_repo_perm:
75 raise HTTPNotFound()
69
76
70 raise HTTPFound(
77 raise HTTPFound(
71 h.route_path('pullrequest_show', repo_name=repo_name,
78 h.route_path('pullrequest_show', repo_name=repo_name,
72 pull_request_id=pull_request_id))
79 pull_request_id=pull_request_id))
General Comments 0
You need to be logged in to leave comments. Login now