Repository with Java code to test
This is a medium-sized Java REST API application intentionally designed with common security vulnerabilities for testing code scanning tools.
src/main/java/com/testapp/api/
├── VulnerableApiApplication.java # Main Spring Boot application
├── config/
│ └── SecurityConfig.java # Configuration with hardcoded credentials
├── controller/
│ └── UserController.java # REST API endpoints
├── model/
│ └── User.java # User entity
├── repository/
│ └── UserRepository.java # Data access layer
├── service/
│ ├── AuthenticationService.java # Authentication logic
│ ├── DataProcessingService.java # Command execution service
│ ├── FileService.java # File operations service
│ └── XmlProcessingService.java # XML parsing service
└── util/
└── LoggingUtil.java # Logging utilities
This application contains the following security vulnerabilities for testing purposes:
- Location:
UserRepository.java - User input directly concatenated into SQL queries
- Vulnerable endpoints:
/api/users/search
- Location:
AuthenticationService.java,SecurityConfig.java - Hardcoded passwords, API keys, and AWS credentials
- Database credentials in plain text
- Location:
FileService.java - No validation of file paths allowing directory traversal
- Vulnerable endpoint:
/api/users/profile/picture
- Location:
DataProcessingService.java - Direct execution of user-supplied commands
- Vulnerable endpoints:
/api/users/ping,/api/users/execute
- Location:
LoggingUtil.java - Logging passwords, credit card numbers, SSNs, API keys
- Location:
AuthenticationService.java - Use of deprecated DES encryption
- MD5 hashing for passwords
- Insecure random number generation
- Location:
XmlProcessingService.java - XML parser without protection against XXE attacks
- Location:
SecurityConfig.java - Disabled certificate validation
- Disabled hostname verification
- Location:
UserController.java - Direct binding of user input to model objects without validation
- Location:
UserController.java - No authentication checks on sensitive endpoints
- No authorization for delete operations
- Location:
UserController.java - Cookies without HttpOnly and Secure flags
- Location:
DataProcessingService.java - Deserializing untrusted data
mvn clean compilemvn spring-boot:runThe application will start on http://localhost:8080
GET /api/users- List all usersGET /api/users/{id}- Get user by IDGET /api/users/search?query=...- Search users (SQL Injection vulnerable)POST /api/users/login- User loginPOST /api/users- Create new userPUT /api/users/{id}- Update userDELETE /api/users/{id}- Delete userGET /api/users/profile/picture?filename=...- Get profile picture (Path Traversal vulnerable)GET /api/users/ping?host=...- Ping a host (Command Injection vulnerable)POST /api/users/execute?command=...- Execute command (Command Injection vulnerable)
This application is designed to be scanned by security analysis tools such as:
- CodeQL
- SonarQube
- Snyk
- OWASP Dependency Check
- Checkmarx
- Fortify
Each vulnerability should be detected by proper security scanning tools.
Apache License 2.0