Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GHSA-wc7c-xq2f-qp4h #1082

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions server/src/main/java/org/eclipse/openvsx/UserAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,15 @@ public List<NamespaceJson> getOwnNamespaces() {
produces = MediaType.APPLICATION_JSON_VALUE
)
public ResponseEntity<ResultJson> updateNamespaceDetails(@RequestBody NamespaceDetailsJson details) {
var user = users.findLoggedInUser();
if (user == null) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
}

try {
return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES).cachePublic())
.body(users.updateNamespaceDetails(details));
.body(users.updateNamespaceDetails(details, user));
} catch (NotFoundException exc) {
var json = NamespaceDetailsJson.error("Namespace not found: " + details.getName());
return new ResponseEntity<>(json, HttpStatus.NOT_FOUND);
Expand All @@ -262,9 +267,14 @@ public ResponseEntity<ResultJson> updateNamespaceDetailsLogo(
@PathVariable String namespace,
@RequestParam MultipartFile file
) {
var user = users.findLoggedInUser();
if (user == null) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
}

try {
return ResponseEntity.ok()
.body(users.updateNamespaceDetailsLogo(namespace, file));
.body(users.updateNamespaceDetailsLogo(namespace, file, user));
} catch (ErrorResultException exc) {
return exc.toResponseEntity(ResultJson.class);
}
Expand Down
10 changes: 8 additions & 2 deletions server/src/main/java/org/eclipse/openvsx/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,14 @@ public ResultJson addNamespaceMember(Namespace namespace, UserData user, String

@Transactional(rollbackOn = { ErrorResultException.class, NotFoundException.class })
@CacheEvict(value = { CACHE_NAMESPACE_DETAILS_JSON }, key="#details.name")
public ResultJson updateNamespaceDetails(NamespaceDetailsJson details) {
public ResultJson updateNamespaceDetails(NamespaceDetailsJson details, UserData user) {
var namespace = repositories.findNamespace(details.getName());
if (namespace == null) {
throw new NotFoundException();
}
if (!repositories.isNamespaceOwner(user, namespace)) {
throw new ErrorResultException("You must be an owner of this namespace.");
}

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

@Transactional
@CacheEvict(value = { CACHE_NAMESPACE_DETAILS_JSON }, key="#namespaceName")
public ResultJson updateNamespaceDetailsLogo(String namespaceName, MultipartFile file) {
public ResultJson updateNamespaceDetailsLogo(String namespaceName, MultipartFile file, UserData user) {
var namespace = repositories.findNamespace(namespaceName);
if (namespace == null) {
throw new NotFoundException();
}
if (!repositories.isNamespaceOwner(user, namespace)) {
throw new ErrorResultException("You must be an owner of this namespace.");
}

var oldNamespace = SerializationUtils.clone(namespace);
try (
Expand Down
Loading