##// END OF EJS Templates
security: fix XSS in repo strip view.
ergo -
r2155:a81b6ebb default
parent child Browse files
Show More
@@ -1,113 +1,113 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2017-2017 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 from pyramid.view import view_config
23 23
24 24 from rhodecode.apps._base import RepoAppView
25 25 from rhodecode.lib import audit_logger
26 26 from rhodecode.lib import helpers as h
27 27 from rhodecode.lib.auth import (
28 28 LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired)
29 29 from rhodecode.lib.ext_json import json
30 30
31 31 log = logging.getLogger(__name__)
32 32
33 33
34 34 class StripView(RepoAppView):
35 35 def load_default_context(self):
36 36 c = self._get_local_tmpl_context()
37 37
38 38 self._register_global_c(c)
39 39 return c
40 40
41 41 @LoginRequired()
42 42 @HasRepoPermissionAnyDecorator('repository.admin')
43 43 @view_config(
44 44 route_name='edit_repo_strip', request_method='GET',
45 45 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
46 46 def strip(self):
47 47 c = self.load_default_context()
48 48 c.active = 'strip'
49 49 c.strip_limit = 10
50 50
51 51 return self._get_template_context(c)
52 52
53 53 @LoginRequired()
54 54 @HasRepoPermissionAnyDecorator('repository.admin')
55 55 @CSRFRequired()
56 56 @view_config(
57 57 route_name='strip_check', request_method='POST',
58 58 renderer='json', xhr=True)
59 59 def strip_check(self):
60 60 from rhodecode.lib.vcs.backends.base import EmptyCommit
61 61 data = {}
62 62 rp = self.request.POST
63 63 for i in range(1, 11):
64 64 chset = 'changeset_id-%d' % (i,)
65 65 check = rp.get(chset)
66 66
67 67 if check:
68 68 data[i] = self.db_repo.get_changeset(rp[chset])
69 69 if isinstance(data[i], EmptyCommit):
70 70 data[i] = {'rev': None, 'commit': h.escape(rp[chset])}
71 71 else:
72 72 data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch,
73 'author': data[i].author,
74 'comment': data[i].message}
73 'author': h.escape(data[i].author),
74 'comment': h.escape(data[i].message)}
75 75 else:
76 76 break
77 77 return data
78 78
79 79 @LoginRequired()
80 80 @HasRepoPermissionAnyDecorator('repository.admin')
81 81 @CSRFRequired()
82 82 @view_config(
83 83 route_name='strip_execute', request_method='POST',
84 84 renderer='json', xhr=True)
85 85 def strip_execute(self):
86 86 from rhodecode.model.scm import ScmModel
87 87
88 88 c = self.load_default_context()
89 89 user = self._rhodecode_user
90 90 rp = self.request.POST
91 91 data = {}
92 92 for idx in rp:
93 93 commit = json.loads(rp[idx])
94 94 # If someone put two times the same branch
95 95 if commit['branch'] in data.keys():
96 96 continue
97 97 try:
98 98 ScmModel().strip(
99 99 repo=self.db_repo,
100 100 commit_id=commit['rev'], branch=commit['branch'])
101 101 log.info('Stripped commit %s from repo `%s` by %s' % (
102 102 commit['rev'], self.db_repo_name, user))
103 103 data[commit['rev']] = True
104 104
105 105 audit_logger.store_web(
106 106 'repo.commit.strip', action_data={'commit_id': commit['rev']},
107 107 repo=self.db_repo, user=self._rhodecode_user, commit=True)
108 108
109 109 except Exception as e:
110 110 data[commit['rev']] = False
111 111 log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s' % (
112 112 commit['rev'], self.db_repo_name, user, e.message))
113 113 return data
General Comments 0
You need to be logged in to leave comments. Login now