|
| 1 | +package com.drunkbaby.ssti.controller; |
| 2 | + |
| 3 | +import org.slf4j.Logger; |
| 4 | +import org.slf4j.LoggerFactory; |
| 5 | +import org.springframework.stereotype.Controller; |
| 6 | +import org.springframework.ui.Model; |
| 7 | +import org.springframework.web.bind.annotation.*; |
| 8 | + |
| 9 | +import javax.servlet.http.HttpServletResponse; |
| 10 | + |
| 11 | +@Controller |
| 12 | +public class ThymeleafController { |
| 13 | + |
| 14 | + Logger log = LoggerFactory.getLogger(ThymeleafController.class); |
| 15 | + |
| 16 | + @GetMapping("/") |
| 17 | + public String index(Model model) { |
| 18 | + model.addAttribute("message", "happy birthday"); |
| 19 | + return "welcome"; |
| 20 | + } |
| 21 | + |
| 22 | + //GET /path?lang=en HTTP/1.1 |
| 23 | + //GET /path?lang=__$%7bnew%20java.util.Scanner(T(java.lang.Runtime).getRuntime().exec(%22id%22).getInputStream()).next()%7d__::.x |
| 24 | + @GetMapping("/path") |
| 25 | + public String path(@RequestParam String lang) { |
| 26 | + return "user/" + lang + "/welcome"; //template path is tainted |
| 27 | + } |
| 28 | + |
| 29 | + //GET /fragment?section=main |
| 30 | + //GET /fragment?section=__$%7bnew%20java.util.Scanner(T(java.lang.Runtime).getRuntime().exec(%22touch%20executed%22).getInputStream()).next()%7d__::.x |
| 31 | + @GetMapping("/fragment") |
| 32 | + public String fragment(@RequestParam String section) { |
| 33 | + return "welcome :: " + section; //fragment is tainted |
| 34 | + } |
| 35 | + |
| 36 | + @GetMapping("/doc/{document}") |
| 37 | + public void getDocument(@PathVariable String document) { |
| 38 | + log.info("Retrieving " + document); |
| 39 | + //returns void, so view name is taken from URI |
| 40 | + } |
| 41 | + |
| 42 | + @GetMapping("/safe/fragment") |
| 43 | + @ResponseBody |
| 44 | + public String safeFragment(@RequestParam String section) { |
| 45 | + return "welcome :: " + section; //FP, as @ResponseBody annotation tells Spring to process the return values as body, instead of view name |
| 46 | + } |
| 47 | + |
| 48 | + @GetMapping("/safe/redirect") |
| 49 | + public String redirect(@RequestParam String url) { |
| 50 | + return "redirect:" + url; //FP as redirects are not resolved as expressions |
| 51 | + } |
| 52 | + |
| 53 | + @GetMapping("/safe/doc/{document}") |
| 54 | + public void getDocument(@PathVariable String document, HttpServletResponse response) { |
| 55 | + log.info("Retrieving " + document); //FP |
| 56 | + } |
| 57 | +} |