|
| 1 | +package clap.server.adapter.inbound.web.xss; |
| 2 | + |
| 3 | +import clap.server.common.annotation.architecture.WebAdapter; |
| 4 | +import clap.server.common.annotation.swagger.DevelopOnlyApi; |
| 5 | +import io.swagger.v3.oas.annotations.Operation; |
| 6 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 7 | +import lombok.extern.slf4j.Slf4j; |
| 8 | +import org.springframework.http.ResponseEntity; |
| 9 | +import org.springframework.web.bind.annotation.*; |
| 10 | + |
| 11 | +@Slf4j |
| 12 | +@WebAdapter |
| 13 | +@RequestMapping("/api/xss-test") |
| 14 | +@Tag(name = "xss 공격 테스트 API", description = "아래와 같은 페이로드들에 대해 테스트합니다.\n" + |
| 15 | + "1. 기본적인 스크립트 삽입: `<script>alert('xss')</script>`\n" + |
| 16 | + "2. 이미지 태그를 이용한 XSS: `<img src=x onerror=alert('xss')>`\n" + |
| 17 | + "3. JavaScript 프로토콜: `javascript:alert('xss')`\n" + |
| 18 | + "4. HTML 이벤트 핸들러:` <div onmouseover=\"alert('xss')\">hover me</div>`\n" + |
| 19 | + "5. SVG를 이용한 XSS: `<svg><script>alert('xss')</script></svg>`\n" + |
| 20 | + "6. HTML5 태그를 이용한 XSS: `<video><source onerror=\"alert('xss')\">`") |
| 21 | +public class XssTestController { |
| 22 | + |
| 23 | + @GetMapping |
| 24 | + @DevelopOnlyApi |
| 25 | + @Operation(summary = "단일 파라미터 test") |
| 26 | + public ResponseEntity<String> testGetXss(@RequestParam String input) { |
| 27 | + log.info("Received GET input: {}", input); |
| 28 | + return ResponseEntity.ok("Processed GET input: " + input); |
| 29 | + } |
| 30 | + |
| 31 | + @PostMapping |
| 32 | + @DevelopOnlyApi |
| 33 | + @Operation(summary = "dto test") |
| 34 | + public ResponseEntity<XssTestResponse> testPostXss(@RequestBody XssTestRequest request) { |
| 35 | + log.info("Received POST input: {}", request); |
| 36 | + return ResponseEntity.ok(new XssTestResponse(request.content())); |
| 37 | + } |
| 38 | + |
| 39 | + @GetMapping("/multi-params") |
| 40 | + @Operation(summary = "다중 파라미터 테스트") |
| 41 | + public ResponseEntity<String> testMultiParamXss(@RequestParam(value = "inputs", required = false) String[] inputs) { |
| 42 | + if (inputs == null || inputs.length == 0) { |
| 43 | + return ResponseEntity.badRequest().body("No inputs provided"); |
| 44 | + } |
| 45 | + |
| 46 | + StringBuilder response = new StringBuilder("Processed inputs:\n"); |
| 47 | + for (int i = 0; i < inputs.length; i++) { |
| 48 | + log.info("Received input {}: {}", i, inputs[i]); |
| 49 | + response.append("Input ").append(i).append(": ").append(inputs[i]).append("\n"); |
| 50 | + } |
| 51 | + |
| 52 | + return ResponseEntity.ok(response.toString()); |
| 53 | + } |
| 54 | +} |
0 commit comments