Skip to content

Commit 9a3cb9c

Browse files
authored
Merge pull request #1082 from amvanbaren/GHSA-wc7c-xq2f-qp4h
Fix GHSA-wc7c-xq2f-qp4h
2 parents 38d69c7 + 4150175 commit 9a3cb9c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

server/src/main/java/org/eclipse/openvsx/UserAPI.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,15 @@ public List<NamespaceJson> getOwnNamespaces() {
241241
produces = MediaType.APPLICATION_JSON_VALUE
242242
)
243243
public ResponseEntity<ResultJson> updateNamespaceDetails(@RequestBody NamespaceDetailsJson details) {
244+
var user = users.findLoggedInUser();
245+
if (user == null) {
246+
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
247+
}
248+
244249
try {
245250
return ResponseEntity.ok()
246251
.cacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES).cachePublic())
247-
.body(users.updateNamespaceDetails(details));
252+
.body(users.updateNamespaceDetails(details, user));
248253
} catch (NotFoundException exc) {
249254
var json = NamespaceDetailsJson.error("Namespace not found: " + details.getName());
250255
return new ResponseEntity<>(json, HttpStatus.NOT_FOUND);
@@ -262,9 +267,14 @@ public ResponseEntity<ResultJson> updateNamespaceDetailsLogo(
262267
@PathVariable String namespace,
263268
@RequestParam MultipartFile file
264269
) {
270+
var user = users.findLoggedInUser();
271+
if (user == null) {
272+
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
273+
}
274+
265275
try {
266276
return ResponseEntity.ok()
267-
.body(users.updateNamespaceDetailsLogo(namespace, file));
277+
.body(users.updateNamespaceDetailsLogo(namespace, file, user));
268278
} catch (ErrorResultException exc) {
269279
return exc.toResponseEntity(ResultJson.class);
270280
}

server/src/main/java/org/eclipse/openvsx/UserService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,14 @@ public ResultJson addNamespaceMember(Namespace namespace, UserData user, String
208208

209209
@Transactional(rollbackOn = { ErrorResultException.class, NotFoundException.class })
210210
@CacheEvict(value = { CACHE_NAMESPACE_DETAILS_JSON }, key="#details.name")
211-
public ResultJson updateNamespaceDetails(NamespaceDetailsJson details) {
211+
public ResultJson updateNamespaceDetails(NamespaceDetailsJson details, UserData user) {
212212
var namespace = repositories.findNamespace(details.getName());
213213
if (namespace == null) {
214214
throw new NotFoundException();
215215
}
216+
if (!repositories.isNamespaceOwner(user, namespace)) {
217+
throw new ErrorResultException("You must be an owner of this namespace.");
218+
}
216219

217220
var issues = validator.validateNamespaceDetails(details);
218221
if (!issues.isEmpty()) {
@@ -250,11 +253,14 @@ public ResultJson updateNamespaceDetails(NamespaceDetailsJson details) {
250253

251254
@Transactional
252255
@CacheEvict(value = { CACHE_NAMESPACE_DETAILS_JSON }, key="#namespaceName")
253-
public ResultJson updateNamespaceDetailsLogo(String namespaceName, MultipartFile file) {
256+
public ResultJson updateNamespaceDetailsLogo(String namespaceName, MultipartFile file, UserData user) {
254257
var namespace = repositories.findNamespace(namespaceName);
255258
if (namespace == null) {
256259
throw new NotFoundException();
257260
}
261+
if (!repositories.isNamespaceOwner(user, namespace)) {
262+
throw new ErrorResultException("You must be an owner of this namespace.");
263+
}
258264

259265
var oldNamespace = SerializationUtils.clone(namespace);
260266
try (

0 commit comments

Comments
 (0)