From b5a2be3f9fd861359a142e4a753091e264de9b62 Mon Sep 17 00:00:00 2001 From: WebUp Cloud Date: Sun, 8 Nov 2026 23:36:16 +0800 Subject: [PATCH] Authorize service ownership before checking restart eligibility --- .../run/webup/platform/RuntimeController.java | 3 +- .../platform/IdentityIntegrationTest.java | 37 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/run/webup/platform/RuntimeController.java b/backend/src/main/java/run/webup/platform/RuntimeController.java index 7d2fed6..3c0043c 100644 --- a/backend/src/main/java/run/webup/platform/RuntimeController.java +++ b/backend/src/main/java/run/webup/platform/RuntimeController.java @@ -57,7 +57,8 @@ public class RuntimeController { @AuthenticationPrincipal SecurityConfig.Identity who, @PathVariable UUID project, @PathVariable UUID service) { + String servicePath = path(who, project, service); operations.checkAllowed(project); - return gateway.request(path(who, project, service) + "/restart", Map.of()); + return gateway.request(servicePath + "/restart", Map.of()); } } diff --git a/backend/src/test/java/run/webup/platform/IdentityIntegrationTest.java b/backend/src/test/java/run/webup/platform/IdentityIntegrationTest.java index b43e411..30b9ec1 100644 --- a/backend/src/test/java/run/webup/platform/IdentityIntegrationTest.java +++ b/backend/src/test/java/run/webup/platform/IdentityIntegrationTest.java @@ -19,7 +19,7 @@ import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.*; -@SpringBootTest +@SpringBootTest(properties = "app.encryption-key=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") @AutoConfigureMockMvc @ActiveProfiles("test") class IdentityIntegrationTest { @@ -35,6 +35,7 @@ class IdentityIntegrationTest { @Autowired MockMvc mvc; @Autowired IdentityService users; + @Autowired HostingService hosting; @Autowired ObjectMapper json; @MockitoBean EphemeralStore store; final Map ephemeral = new ConcurrentHashMap<>(); @@ -92,6 +93,40 @@ class IdentityIntegrationTest { return json.readTree(result).get("token").asText(); } + @Test + void restartDoesNotRevealAnotherProjectsModerationState() throws Exception { + UUID owner = user("owner@restart.test"); + user("other@restart.test"); + UUID project = UUID.randomUUID(); + users + .db() + .update( + "INSERT INTO projects(id,owner_id,name,description,stack,requirements) VALUES" + + " (?,?,?,'','HTML','')", + project, + owner, + "Private project"); + users + .db() + .update("INSERT INTO project_moderation(project_id,status) VALUES (?,'BANNED')", project); + Object service = + hosting + .service( + owner, + project, + null, + new HostingController.ServiceSpec( + "web", "nginx:example", List.of(), null, 3000, 250, 256, 1, "/", true)) + .get("id"); + String url = "/api/projects/" + project + "/runtime/services/" + service + "/restart"; + mvc.perform(post(url).header("Authorization", "Bearer " + token("other@restart.test"))) + .andExpect(status().isNotFound()) + .andExpect(jsonPath("$.message").value("项目不存在")); + mvc.perform(post(url).header("Authorization", "Bearer " + token("owner@restart.test"))) + .andExpect(status().isForbidden()) + .andExpect(jsonPath("$.message").value("网站已被封禁,请联系管理员")); + } + @Test void captchaIsServerGeneratedAndOneUse() throws Exception { String result =