fix: remove unsafe exec() in App.java#3471
Conversation
PR SummaryFixed a critical security vulnerability (V-002) by replacing the unsafe single-string Runtime.exec usage with a cross-platform ProcessBuilder approach in both App.java variants. The update adds Locale handling, detects the OS at runtime, and delegates to appropriate commands: Windows uses cmd.exe /c start with an empty title, macOS uses open, and Linux uses xdg-open. This improves security and portability while preserving behavior for opening the target application file. Changes
autogenerated by presubmit.ai |
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (1)
- b09012a: fix: V-002 security vulnerability
Automated security fix generated by Orbis Security AI
Files Processed (1)
- page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java (1 hunk)
Actionable Comments (0)
Skipped Comments (3)
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [81-81]
security: "Security: path handling risks with Windows start command"
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [81-81]
possible bug: "Possible bug: Null check for applicationFile"
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [81-81]
enhancement: "Cross-platform considerations"
prashantpiyush1111
left a comment
There was a problem hiding this comment.
Array-based exec() is an improvement, but:
- cmd.exe is still hardcoded (Windows only)
- Build is failing on JDK 21 ❌
- This is sample/demo code, real risk is minimal
- Fix is from automated AI bot, needs manual verification
Please fix the build failure first before merge.
| } else { | ||
| // java Desktop not supported - above unlikely to work for Windows so try instead... | ||
| Runtime.getRuntime().exec("cmd.exe start " + applicationFile); | ||
| Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "start", applicationFile.getAbsolutePath()}); |
There was a problem hiding this comment.
Array-based exec() is an improvement, but:
- cmd.exe is still hardcoded (Windows only)
- Build is failing on JDK 21
- This is sample/demo code, real risk is minimal
- Fix is from automated AI bot, needs manual verification
Please fix the build failure first before merge.
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (1)
- d68c18b: adding cross-platform support
Files Processed (1)
- page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java (2 hunks)
Actionable Comments (0)
Skipped Comments (3)
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [81-92]
best_practice: "Windows path handling with Start may fail for spaces"
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [81-92]
maintainability: "Use explicit type instead of 'var' for compatibility"
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [29-29]
readability: "Locale usage rationale"
This is addressed. So can you pls review. |
|
Thanks for addressing the previous concerns! However, SonarQube Quality Gate has failed Please review and fix the SonarQube issues |
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (1)
- db3f0c6: fixing sonarqube hotspots
Files Processed (1)
- page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java (2 hunks)
Actionable Comments (0)
Skipped Comments (3)
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [81-87]
possible_bug: "Windows command invocation requires a window title to handle spaces correctly"
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [82-82]
best_practice: "Use explicit type for OS detection"
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [94-94]
enhancement: "Consider inheriting I/O for the launched process"
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (1)
- 23814e1: fixing the formating for java windows
Files Processed (1)
- page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java (2 hunks)
Actionable Comments (0)
Skipped Comments (2)
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [85-91]
possible bug: "Windows path quoting for start command"
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [99-99]
enhancement: "Log or capture the Process from ProcessBuilder"
|
Automated security fix generated by Orbis Security AI
23814e1 to
65fc792
Compare
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (4)
- 65fc792: fixing the formating for java windows
- 57e65b2: fixing sonarqube hotspots
- 296c731: adding cross-platform support
- 9ac6885: fix: V-002 security vulnerability
Automated security fix generated by Orbis Security AI
Files Processed (1)
- page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java (2 hunks)
Actionable Comments (0)
Skipped Comments (3)
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [30-30]
best_practice: "Use Locale.ROOT for locale-insensitive operations"
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [86-91]
best_practice: "Windows: potential 'start' command parsing edge-case"
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [99-99]
possible bug: "Handle SecurityException from ProcessBuilder.start()"
| new ProcessBuilder( | ||
| "C:\\Windows\\System32\\cmd.exe", | ||
| "/c", | ||
| "start", | ||
| applicationFile.getAbsolutePath()); |
There was a problem hiding this comment.
| new ProcessBuilder( | |
| "C:\\Windows\\System32\\cmd.exe", | |
| "/c", | |
| "start", | |
| applicationFile.getAbsolutePath()); | |
| new ProcessBuilder( | |
| "C:\\Windows\\System32\\cmd.exe", | |
| "/c", | |
| "start", | |
| ""); |
There was a problem hiding this comment.
The Windows start command treats the first quoted argument as the window title.
If the user's workspace path or checkout path contains spaces (which is very common), ProcessBuilder automatically adds quotes. This makes the start command fail to open the file and instead launch an empty cmd shell window with the path as its title.
| applicationFile.getAbsolutePath()); | ||
| } else if (os.contains("mac")) { | ||
| // Standard macOS location for 'open' command | ||
| pb = new ProcessBuilder("/usr/bin/open", applicationFile.getAbsolutePath()); |
There was a problem hiding this comment.
On some Linux distributions or installations, xdg-open may reside in /bin/xdg-open or /usr/local/bin/xdg-open. Hardcoding the path will throw an IOException (command not found) on those systems.
Use relative command names (e.g., "open" and "xdg-open") and allow the OS to locate them in the system PATH.
| Runtime.getRuntime().exec("cmd.exe start " + applicationFile); | ||
| // Use absolute paths to avoid PATH injection vulnerabilities (SonarQube S5304) | ||
| var os = System.getProperty("os.name").toLowerCase(Locale.ROOT); | ||
| ProcessBuilder pb; |
There was a problem hiding this comment.
Inconsistency with the main page-object App.java implementation.
The main module's App.java has a much simpler fallback block without operating system checks or hardcoded path names. Maintaining two different styles of fallbacks for the same logical behavior is unnecessary.
Align the fix implementation with the one used in main page-object App.java.
…consistency - Add empty string title arg to cmd /c start to fix paths-with-spaces bug - Revert Unix commands to bare names (open, xdg-open) with NOSONAR since xdg-open location varies by distro; absolute paths broke portability - Apply same ProcessBuilder fix to page-object/src App.java for consistency Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (1)
-
897ed32: fix: address PR review comments - Windows title bug, Unix paths, and consistency
-
Add empty string title arg to cmd /c start to fix paths-with-spaces bug
-
Revert Unix commands to bare names (open, xdg-open) with NOSONAR since
xdg-open location varies by distro; absolute paths broke portability -
Apply same ProcessBuilder fix to page-object/src App.java for consistency
Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com
Files Processed (2)
- page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java (2 hunks)
- page-object/src/main/java/com/iluwatar/pageobject/App.java (2 hunks)
Actionable Comments (0)
Skipped Comments (2)
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [81-99]
potential issue: "Cross-platform OS fallback: compatibility concerns"
-
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java [79-99]
maintainability: "Code duplication: cross-platform open logic"
|
Code review comments are addressed. Pls review. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3471 +/- ##
=========================================
Coverage ? 83.29%
Complexity ? 4024
=========================================
Files ? 1060
Lines ? 14246
Branches ? 686
=========================================
Hits ? 11866
Misses ? 2094
Partials ? 286 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|


Summary
Fix critical severity security issue in
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java.Vulnerability
V-002page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java:81Description: The sample-application variant of App.java independently reproduces the same OS command injection pattern as V-001. This is a separate file in a different subdirectory (page-object/sample-application/) and is independently exploitable. The single-string form of Runtime.exec() passes the full concatenated command to cmd.exe for shell interpretation, enabling an attacker who controls applicationFile to chain arbitrary OS commands. The presence of this vulnerability in two separate files indicates a copy-paste propagation of the insecure pattern and increases the overall attack surface.
Changes
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.javaVerification
Automated security fix by OrbisAI Security