Skip to content

feat(tests): add intentional command injection vulnerability for Code… #4

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

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main/java/com/weather/app/WeatherApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
public class WeatherApp {

private static final Logger LOGGER = Logger.getLogger(WeatherApp.class.getName());


private static final String SECRET_PAT =
"ATATT3xFfGF0wp8k76Z0Q2Wc2sP0NhHIlTALaCZR_CZxw8vuwsyt5Jijh-Zoem712l0jIAUjzn7hbdQ2" +
"vOz3dUloyFR2oFtU26VjImYu0a5opr5AoCsuiIDKfiWgxwyu_oe-IMYURIQmea5x8CPBXMhkeD9rJbPZGOy-BbrnH74s9Dap_U=4900D7F8";

// Initialize logging configuration
static {
try (InputStream is = WeatherApp.class.getClassLoader().getResourceAsStream("logging.properties")) {
Expand Down Expand Up @@ -69,6 +73,18 @@ public static void main(String[] args) {
String city = args[0];
LOGGER.log(Level.INFO, "Weather request for city: {0}", city);

// --- Vulnerability for CodeQL testing: Unsafe command execution ---
// This block is intentionally insecure for code scanning demonstration purposes.
if ("test-injection".equals(city)) {
try {
Runtime.getRuntime().exec("ls"); // Potential command injection vulnerability
LOGGER.log(Level.WARNING, "Executed unsafe command for testing purposes.");
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to execute command: " + e.getMessage(), e);
}
}
// --- End of vulnerability block ---

try {
// Get API key from environment or config file
String apiKey = ConfigUtil.getApiKey();
Expand Down