##// 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 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2011-2018 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22
23 23 from pyramid.view import view_config
24 24 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
25 25
26 26 from rhodecode.apps._base import BaseAppView
27 27 from rhodecode.lib import helpers as h
28 28 from rhodecode.lib.auth import (NotAnonymous, HasRepoPermissionAny)
29 29 from rhodecode.model.db import Repository
30 from rhodecode.model.validation_schema.types import RepoNameType
30 31
31 32 log = logging.getLogger(__name__)
32 33
33 34
34 35 class RepoChecksView(BaseAppView):
35 36 def load_default_context(self):
36 37 c = self._get_local_tmpl_context()
37 38
38 39 return c
39 40
40 41 @NotAnonymous()
41 42 @view_config(
42 43 route_name='repo_creating', request_method='GET',
43 44 renderer='rhodecode:templates/admin/repos/repo_creating.mako')
44 45 def repo_creating(self):
45 46 c = self.load_default_context()
46
47 47 repo_name = self.request.matchdict['repo_name']
48 repo_name = RepoNameType().deserialize(None, repo_name)
48 49 db_repo = Repository.get_by_repo_name(repo_name)
49 50
50 51 # check if maybe repo is already created
51 52 if db_repo and db_repo.repo_state in [Repository.STATE_CREATED]:
52 53 # re-check permissions before redirecting to prevent resource
53 54 # discovery by checking the 302 code
54 55 perm_set = ['repository.read', 'repository.write', 'repository.admin']
55 56 has_perm = HasRepoPermissionAny(*perm_set)(
56 57 db_repo.repo_name, 'Repo Creating check')
57 58 if not has_perm:
58 59 raise HTTPNotFound()
59 60
60 61 raise HTTPFound(h.route_path(
61 62 'repo_summary', repo_name=db_repo.repo_name))
62 63
63 64 c.task_id = self.request.GET.get('task_id')
64 65 c.repo_name = repo_name
65 66
66 67 return self._get_template_context(c)
67 68
68 69 @NotAnonymous()
69 70 @view_config(
70 71 route_name='repo_creating_check', request_method='GET',
71 72 renderer='json_ext')
72 73 def repo_creating_check(self):
73 74 _ = self.request.translate
74 75 task_id = self.request.GET.get('task_id')
75 76 self.load_default_context()
76 77
77 78 repo_name = self.request.matchdict['repo_name']
78 79
79 80 if task_id and task_id not in ['None']:
80 81 import rhodecode
81 82 from rhodecode.lib.celerylib.loader import celery_app, exceptions
82 83 if rhodecode.CELERY_ENABLED:
83 84 log.debug('celery: checking result for task:%s', task_id)
84 85 task = celery_app.AsyncResult(task_id)
85 86 try:
86 87 task.get(timeout=10)
87 88 except exceptions.TimeoutError:
88 89 task = None
89 90 if task and task.failed():
90 91 msg = self._log_creation_exception(task.result, repo_name)
91 92 h.flash(msg, category='error')
92 93 raise HTTPFound(h.route_path('home'), code=501)
93 94
94 95 db_repo = Repository.get_by_repo_name(repo_name)
95 96 if db_repo and db_repo.repo_state == Repository.STATE_CREATED:
96 97 if db_repo.clone_uri:
97 98 clone_uri = db_repo.clone_uri_hidden
98 99 h.flash(_('Created repository %s from %s')
99 100 % (db_repo.repo_name, clone_uri), category='success')
100 101 else:
101 102 repo_url = h.link_to(
102 103 db_repo.repo_name,
103 104 h.route_path('repo_summary', repo_name=db_repo.repo_name))
104 105 fork = db_repo.fork
105 106 if fork:
106 107 fork_name = fork.repo_name
107 108 h.flash(h.literal(_('Forked repository %s as %s')
108 109 % (fork_name, repo_url)), category='success')
109 110 else:
110 111 h.flash(h.literal(_('Created repository %s') % repo_url),
111 112 category='success')
112 113 return {'result': True}
113 114 return {'result': False}
General Comments 0
You need to be logged in to leave comments. Login now