|
10 | 10 | import org.springframework.web.bind.annotation.RequestMethod; |
11 | 11 | import org.springframework.web.bind.annotation.RequestParam; |
12 | 12 |
|
13 | | - |
14 | 13 | /** |
15 | 14 | * Search login |
16 | 15 | */ |
17 | 16 | @Controller |
18 | 17 | public class SearchController { |
19 | 18 |
|
20 | | - @RequestMapping(value = "/search/user", method = RequestMethod.GET) |
21 | | - public String doGetSearch(@RequestParam String foo, HttpServletResponse response, HttpServletRequest request) { |
22 | | - java.lang.Object message = new Object(); |
23 | | - try { |
24 | | - ExpressionParser parser = new SpelExpressionParser(); |
25 | | - Expression exp = parser.parseExpression(foo); |
26 | | - message = (Object) exp.getValue(); |
27 | | - } catch (Exception ex) { |
28 | | - System.out.println(ex.getMessage()); |
| 19 | + @RequestMapping(value = "/search/user", method = RequestMethod.GET) |
| 20 | + public String doGetSearch(@RequestParam String foo, HttpServletResponse response, HttpServletRequest request) { |
| 21 | + java.lang.Object message = new Object(); |
| 22 | + if (isSafeExpression(foo)) { |
| 23 | + try { |
| 24 | + ExpressionParser parser = new SpelExpressionParser(); |
| 25 | + Expression exp = parser.parseExpression(foo); |
| 26 | + message = exp.getValue(); |
| 27 | + } catch (Exception ex) { |
| 28 | + System.out.println(ex.getMessage()); |
| 29 | + } |
| 30 | + } else { |
| 31 | + message = "Invalid input"; |
| 32 | + } |
| 33 | + return message.toString(); |
| 34 | + } |
| 35 | + |
| 36 | + private boolean isSafeExpression(String foo) { |
| 37 | + // implement your own validation logic here |
| 38 | + // for example, you can check if foo contains only allowed characters or patterns |
| 39 | + return true; // replace with your actual validation logic |
29 | 40 | } |
30 | | - return message.toString(); |
31 | | - } |
32 | 41 | } |
0 commit comments