| name | security-review |
| description | Conduct security code reviews. Use when reviewing code for vulnerabilities, assessing security posture, or auditing applications. Covers security review checklist. |
| allowed-tools | Read, Glob, Grep |
Security Review
Review Checklist
Authentication
Authorization
Input Validation
Output Encoding
Cryptography
Error Handling
Logging
Code Patterns to Flag (Java)
SQL Injection
String query = "SELECT * FROM users WHERE id = " + userId;
jdbcTemplate.queryForObject(query, User.class);
@Query("SELECT u FROM User u WHERE u.id = :id")
Optional<User> findById(@Param("id") Long id);
XSS (Cross-Site Scripting)
@GetMapping("/profile")
public String profile(Model model, @RequestParam String name) {
model.addAttribute("name", name);
return "profile";
}
<!-- Thymeleaf auto-escapes by default -->
<p th:text="${name}">Name here</p>
import org.springframework.web.util.HtmlUtils;
String safe = HtmlUtils.htmlEscape(userInput);
Hardcoded Secrets
public class ApiClient {
private static final String API_KEY = "sk-abc123...";
private static final String DB_PASSWORD = "password123";
}
@Value("${api.key}")
private String apiKey;
@Value("${spring.datasource.password}")
private String dbPassword;
Insecure Random
Random random = new Random();
String token = String.valueOf(random.nextInt());
SecureRandom secureRandom = new SecureRandom();
byte[] token = new byte[32];
secureRandom.nextBytes(token);
String tokenStr = Base64.getUrlEncoder().encodeToString(token);
Path Traversal
@GetMapping("/files/{filename}")
public ResponseEntity<Resource> getFile(@PathVariable String filename) {
File file = new File("/uploads/" + filename);
return ResponseEntity.ok(new FileSystemResource(file));
}
@GetMapping("/files/{filename}")
public ResponseEntity<Resource> getFile(@PathVariable String filename) {
if (filename.contains("..") || filename.contains("/")) {
throw new IllegalArgumentException("Invalid filename");
}
Path basePath = Paths.get("/uploads").toAbsolutePath().normalize();
Path filePath = basePath.resolve(filename).normalize();
if (!filePath.startsWith(basePath)) {
throw new SecurityException("Path traversal detected");
}
return ResponseEntity.ok(new FileSystemResource(filePath));
}
Security Review Report
## Security Review: [Component]
### Summary
- Critical: [X]
- High: [X]
- Medium: [X]
- Low: [X]
### Findings
#### [CRITICAL] SQL Injection in UserService
**Location**: api/src/main/java/com/example/service/UserService.java:47
**Description**: User input concatenated into SQL query
**Remediation**: Use JPA with named parameters
**Code**:
```java
// Current (vulnerable)
String query = "SELECT * FROM users WHERE email = '" + email + "'";
// ✅ Recommended fix
@Query("SELECT u FROM User u WHERE u.email = :email")
Optional<User> findByEmail(@Param("email") String email);