-
Notifications
You must be signed in to change notification settings - Fork 0
Vulnerable sample for Action test #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,2 +1,9 @@ | ||||||||||||||||||||||||
| // safe baseline | ||||||||||||||||||||||||
| public class DemoController {} | ||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.*; | ||||||||||||||||||||||||
| @RestController | ||||||||||||||||||||||||
| public class DemoController { | ||||||||||||||||||||||||
| @GetMapping("/items") | ||||||||||||||||||||||||
| public String items(@RequestParam String sort) throws Exception { | ||||||||||||||||||||||||
| Class<?> clazz = Class.forName(sort); | ||||||||||||||||||||||||
|
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uncontrolled reflection: Class.forName on user input is a critical vulnerability (classloader injection). A user can cause arbitrary classes to load and run static initializers (DoS/side effects). Remove reflection and validate input via an allowlist, returning proper HTTP status. - public String items(@RequestParam String sort) throws Exception {
- Class<?> clazz = Class.forName(sort);
- return "ok";
- }
+ public ResponseEntity<String> items(
+ @RequestParam(name = "sort", required = false, defaultValue = "name") String sort) {
+ // Allow-list acceptable sort keys only; do NOT reflectively load anything from user input.
+ Set<String> allowed = Set.of("name", "price", "createdAt");
+ if (!allowed.contains(sort)) {
+ return ResponseEntity.badRequest().body("invalid sort");
+ }
+ return ResponseEntity.ok("ok");
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| return "ok"; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing package declaration; class won’t compile under src/main/java/com/acme. Also replace wildcard import and add required imports.
Add the package and explicit imports (needed for the fix below).
📝 Committable suggestion
🤖 Prompt for AI Agents