##// END OF EJS Templates
api: security, fix problem when absolute paths are specified with API call, that would allow...
marcink -
r2663:0777b16f default
parent child Browse files
Show More
@@ -99,7 +99,9 b' class TestApiUpdateRepo(object):'
99 99
100 100 id_, params = build_data(
101 101 self.apikey, 'update_repo', repoid=repo_name, **updates)
102 response = api_call(self.app, params)
102
103 with mock.patch('rhodecode.model.validation_schema.validators.url_validator'):
104 response = api_call(self.app, params)
103 105
104 106 if updates.get('repo_name'):
105 107 repo_name = updates['repo_name']
@@ -659,6 +659,7 b' def create_repo('
659 659
660 660 schema = repo_schema.RepoSchema().bind(
661 661 repo_type_options=rhodecode.BACKENDS.keys(),
662 repo_type=repo_type,
662 663 # user caller
663 664 user=apiuser)
664 665
@@ -902,16 +903,18 b' def update_repo('
902 903 request.translate, repo=repo)
903 904
904 905 old_values = repo.get_api_data()
906 repo_type = repo.repo_type
905 907 schema = repo_schema.RepoSchema().bind(
906 908 repo_type_options=rhodecode.BACKENDS.keys(),
907 909 repo_ref_options=ref_choices,
910 repo_type=repo_type,
908 911 # user caller
909 912 user=apiuser,
910 913 old_values=old_values)
911 914 try:
912 915 schema_data = schema.deserialize(dict(
913 916 # we save old value, users cannot change type
914 repo_type=repo.repo_type,
917 repo_type=repo_type,
915 918
916 919 repo_name=updates['repo_name'],
917 920 repo_owner=updates['user'],
@@ -1062,6 +1065,7 b' def fork_repo(request, apiuser, repoid, '
1062 1065
1063 1066 schema = repo_schema.RepoSchema().bind(
1064 1067 repo_type_options=rhodecode.BACKENDS.keys(),
1068 repo_type=repo.repo_type,
1065 1069 # user caller
1066 1070 user=apiuser)
1067 1071
@@ -319,13 +319,13 b' class RepoSchema(colander.MappingSchema)'
319 319
320 320 repo_clone_uri = colander.SchemaNode(
321 321 colander.String(),
322 validator=colander.All(colander.Length(min=1)),
322 validator=deferred_sync_uri_validator,
323 323 preparers=[preparers.strip_preparer],
324 324 missing='')
325 325
326 326 repo_push_uri = colander.SchemaNode(
327 327 colander.String(),
328 validator=colander.All(colander.Length(min=1)),
328 validator=deferred_sync_uri_validator,
329 329 preparers=[preparers.strip_preparer],
330 330 missing='')
331 331
@@ -117,6 +117,11 b' def url_validator(url, repo_type, config'
117 117 % (url, ','.join(allowed_prefixes)))
118 118 exc.allowed_prefixes = allowed_prefixes
119 119 raise exc
120 elif repo_type == 'svn':
121 # no validation for SVN yet
122 return
123
124 raise InvalidCloneUrl('No repo type specified')
120 125
121 126
122 127 class CloneUriValidator(object):
@@ -124,16 +129,14 b' class CloneUriValidator(object):'
124 129 self.repo_type = repo_type
125 130
126 131 def __call__(self, node, value):
132
127 133 from rhodecode.lib.utils import make_db_config
128 134 try:
129 135 config = make_db_config(clear_session=False)
130 136 url_validator(value, self.repo_type, config)
131 137 except InvalidCloneUrl as e:
132 138 log.warning(e)
133 msg = _(u'Invalid clone url, provide a valid clone '
134 u'url starting with one of {allowed_prefixes}').format(
135 allowed_prefixes=e.allowed_prefixes)
136 raise colander.Invalid(node, msg)
139 raise colander.Invalid(node, e.message)
137 140 except Exception:
138 141 log.exception('Url validation failed')
139 142 msg = _(u'invalid clone url for {repo_type} repository').format(
@@ -53,6 +53,7 b' class TestRepoSchema(object):'
53 53 def test_deserialize(self, app, user_admin):
54 54 schema = repo_schema.RepoSchema().bind(
55 55 repo_type_options=['hg'],
56 repo_type='hg',
56 57 user=user_admin
57 58 )
58 59
@@ -78,6 +79,7 b' class TestRepoSchema(object):'
78 79
79 80 schema = repo_schema.RepoSchema().bind(
80 81 repo_type_options=['hg'],
82 repo_type='hg',
81 83 user=user_admin
82 84 )
83 85
@@ -93,6 +95,7 b' class TestRepoSchema(object):'
93 95 def test_deserialize_with_group_name(self, app, user_admin, test_repo_group):
94 96 schema = repo_schema.RepoSchema().bind(
95 97 repo_type_options=['hg'],
98 repo_type='hg',
96 99 user=user_admin
97 100 )
98 101
@@ -114,6 +117,7 b' class TestRepoSchema(object):'
114 117 self, app, user_regular, test_repo_group):
115 118 schema = repo_schema.RepoSchema().bind(
116 119 repo_type_options=['hg'],
120 repo_type='hg',
117 121 user=user_regular
118 122 )
119 123
General Comments 0
You need to be logged in to leave comments. Login now