##// END OF EJS Templates
sec: serialize the repo name in repo checks to prevent potential html injections.
marcink -
r2547:0fd8208e stable
parent child Browse files
Show More
@@ -1,113 +1,114 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2011-2018 RhodeCode GmbH
3 # Copyright (C) 2011-2018 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.view import view_config
23 from pyramid.view import view_config
24 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
24 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
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 (NotAnonymous, HasRepoPermissionAny)
28 from rhodecode.lib.auth import (NotAnonymous, HasRepoPermissionAny)
29 from rhodecode.model.db import Repository
29 from rhodecode.model.db import Repository
30 from rhodecode.model.validation_schema.types import RepoNameType
30
31
31 log = logging.getLogger(__name__)
32 log = logging.getLogger(__name__)
32
33
33
34
34 class RepoChecksView(BaseAppView):
35 class RepoChecksView(BaseAppView):
35 def load_default_context(self):
36 def load_default_context(self):
36 c = self._get_local_tmpl_context()
37 c = self._get_local_tmpl_context()
37
38
38 return c
39 return c
39
40
40 @NotAnonymous()
41 @NotAnonymous()
41 @view_config(
42 @view_config(
42 route_name='repo_creating', request_method='GET',
43 route_name='repo_creating', request_method='GET',
43 renderer='rhodecode:templates/admin/repos/repo_creating.mako')
44 renderer='rhodecode:templates/admin/repos/repo_creating.mako')
44 def repo_creating(self):
45 def repo_creating(self):
45 c = self.load_default_context()
46 c = self.load_default_context()
46
47 repo_name = self.request.matchdict['repo_name']
47 repo_name = self.request.matchdict['repo_name']
48 repo_name = RepoNameType().deserialize(None, repo_name)
48 db_repo = Repository.get_by_repo_name(repo_name)
49 db_repo = Repository.get_by_repo_name(repo_name)
49
50
50 # check if maybe repo is already created
51 # check if maybe repo is already created
51 if db_repo and db_repo.repo_state in [Repository.STATE_CREATED]:
52 if db_repo and db_repo.repo_state in [Repository.STATE_CREATED]:
52 # re-check permissions before redirecting to prevent resource
53 # re-check permissions before redirecting to prevent resource
53 # discovery by checking the 302 code
54 # discovery by checking the 302 code
54 perm_set = ['repository.read', 'repository.write', 'repository.admin']
55 perm_set = ['repository.read', 'repository.write', 'repository.admin']
55 has_perm = HasRepoPermissionAny(*perm_set)(
56 has_perm = HasRepoPermissionAny(*perm_set)(
56 db_repo.repo_name, 'Repo Creating check')
57 db_repo.repo_name, 'Repo Creating check')
57 if not has_perm:
58 if not has_perm:
58 raise HTTPNotFound()
59 raise HTTPNotFound()
59
60
60 raise HTTPFound(h.route_path(
61 raise HTTPFound(h.route_path(
61 'repo_summary', repo_name=db_repo.repo_name))
62 'repo_summary', repo_name=db_repo.repo_name))
62
63
63 c.task_id = self.request.GET.get('task_id')
64 c.task_id = self.request.GET.get('task_id')
64 c.repo_name = repo_name
65 c.repo_name = repo_name
65
66
66 return self._get_template_context(c)
67 return self._get_template_context(c)
67
68
68 @NotAnonymous()
69 @NotAnonymous()
69 @view_config(
70 @view_config(
70 route_name='repo_creating_check', request_method='GET',
71 route_name='repo_creating_check', request_method='GET',
71 renderer='json_ext')
72 renderer='json_ext')
72 def repo_creating_check(self):
73 def repo_creating_check(self):
73 _ = self.request.translate
74 _ = self.request.translate
74 task_id = self.request.GET.get('task_id')
75 task_id = self.request.GET.get('task_id')
75 self.load_default_context()
76 self.load_default_context()
76
77
77 repo_name = self.request.matchdict['repo_name']
78 repo_name = self.request.matchdict['repo_name']
78
79
79 if task_id and task_id not in ['None']:
80 if task_id and task_id not in ['None']:
80 import rhodecode
81 import rhodecode
81 from rhodecode.lib.celerylib.loader import celery_app, exceptions
82 from rhodecode.lib.celerylib.loader import celery_app, exceptions
82 if rhodecode.CELERY_ENABLED:
83 if rhodecode.CELERY_ENABLED:
83 log.debug('celery: checking result for task:%s', task_id)
84 log.debug('celery: checking result for task:%s', task_id)
84 task = celery_app.AsyncResult(task_id)
85 task = celery_app.AsyncResult(task_id)
85 try:
86 try:
86 task.get(timeout=10)
87 task.get(timeout=10)
87 except exceptions.TimeoutError:
88 except exceptions.TimeoutError:
88 task = None
89 task = None
89 if task and task.failed():
90 if task and task.failed():
90 msg = self._log_creation_exception(task.result, repo_name)
91 msg = self._log_creation_exception(task.result, repo_name)
91 h.flash(msg, category='error')
92 h.flash(msg, category='error')
92 raise HTTPFound(h.route_path('home'), code=501)
93 raise HTTPFound(h.route_path('home'), code=501)
93
94
94 db_repo = Repository.get_by_repo_name(repo_name)
95 db_repo = Repository.get_by_repo_name(repo_name)
95 if db_repo and db_repo.repo_state == Repository.STATE_CREATED:
96 if db_repo and db_repo.repo_state == Repository.STATE_CREATED:
96 if db_repo.clone_uri:
97 if db_repo.clone_uri:
97 clone_uri = db_repo.clone_uri_hidden
98 clone_uri = db_repo.clone_uri_hidden
98 h.flash(_('Created repository %s from %s')
99 h.flash(_('Created repository %s from %s')
99 % (db_repo.repo_name, clone_uri), category='success')
100 % (db_repo.repo_name, clone_uri), category='success')
100 else:
101 else:
101 repo_url = h.link_to(
102 repo_url = h.link_to(
102 db_repo.repo_name,
103 db_repo.repo_name,
103 h.route_path('repo_summary', repo_name=db_repo.repo_name))
104 h.route_path('repo_summary', repo_name=db_repo.repo_name))
104 fork = db_repo.fork
105 fork = db_repo.fork
105 if fork:
106 if fork:
106 fork_name = fork.repo_name
107 fork_name = fork.repo_name
107 h.flash(h.literal(_('Forked repository %s as %s')
108 h.flash(h.literal(_('Forked repository %s as %s')
108 % (fork_name, repo_url)), category='success')
109 % (fork_name, repo_url)), category='success')
109 else:
110 else:
110 h.flash(h.literal(_('Created repository %s') % repo_url),
111 h.flash(h.literal(_('Created repository %s') % repo_url),
111 category='success')
112 category='success')
112 return {'result': True}
113 return {'result': True}
113 return {'result': False}
114 return {'result': False}
General Comments 0
You need to be logged in to leave comments. Login now