alwaysgoodtime / java-sec-code

Java web common vulnerabilities and security code which is base on springboot and spring security
0 stars 0 forks source link

Sweep: 请帮我修复SpEL.java文件中的表达式语言注入漏洞 #14

Open alwaysgoodtime opened 7 months ago

alwaysgoodtime commented 7 months ago
Checklist - [X] Modify `src/main/java/org/joychou/controller/SpEL.java` ✓ https://github.com/alwaysgoodtime/java-sec-code/commit/726fcf5f32563de296c5b252815aee250145ac0f [Edit](https://github.com/alwaysgoodtime/java-sec-code/edit/sweep/speljava/src/main/java/org/joychou/controller/SpEL.java) - [X] Running GitHub Actions for `src/main/java/org/joychou/controller/SpEL.java` ✓ [Edit](https://github.com/alwaysgoodtime/java-sec-code/edit/sweep/speljava/src/main/java/org/joychou/controller/SpEL.java)
sweep-ai[bot] commented 7 months ago

🚀 Here's the PR! #17

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: 6f01709a28)

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/alwaysgoodtime/java-sec-code/blob/058a20e17d540288d081fc581f8e4f29536317d8/src/main/java/org/joychou/controller/SpEL.java#L1-L62

Step 2: ⌨️ Coding

--- 
+++ 
@@ -23,8 +23,11 @@
      */
     @RequestMapping("/spel/vuln1")
     public String spel_vuln1(String value) {
-        ExpressionParser parser = new SpelExpressionParser();
-        return parser.parseExpression(value).getValue().toString();
+        SpelExpressionParser parser = new SpelExpressionParser();
+        SimpleEvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
+        Expression expression = parser.parseExpression(value);
+        Object x = expression.getValue(context);
+        return x.toString();
     }

     /**
@@ -34,11 +37,11 @@
      */
     @RequestMapping("spel/vuln2")
     public String spel_vuln2(String value) {
-        StandardEvaluationContext context = new StandardEvaluationContext();
+        SimpleEvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build();
         SpelExpressionParser parser = new SpelExpressionParser();
         Expression expression = parser.parseExpression(value, new TemplateParserContext());
-        Object x = expression.getValue(context);    // trigger vulnerability point
-        return x.toString();   // response
+        Object x = expression.getValue(context);
+        return x.toString();
     }

     /**

Ran GitHub Actions for 726fcf5f32563de296c5b252815aee250145ac0f:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/speljava.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.

This is an automated message generated by Sweep AI.