Skip to content

fix: remove unsafe exec() in App.java#3471

Open
orbisai0security wants to merge 5 commits into
iluwatar:masterfrom
orbisai0security:fix-v-002-os-command-injection-page-object-sample-app
Open

fix: remove unsafe exec() in App.java#3471
orbisai0security wants to merge 5 commits into
iluwatar:masterfrom
orbisai0security:fix-v-002-os-command-injection-page-object-sample-app

Conversation

@orbisai0security
Copy link
Copy Markdown
Contributor

Summary

Fix critical severity security issue in page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java.

Vulnerability

Field Value
ID V-002
Severity CRITICAL
Scanner multi_agent_ai
Rule V-002
File page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java:81
CWE CWE-78

Description: 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.java

Verification

  • Build passes
  • Scanner re-scan confirms fix
  • LLM code review passed

Automated security fix by OrbisAI Security

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

PR Summary

Fixed 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

File Summary
page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java Replaced insecure Runtime.exec with a cross-platform ProcessBuilder; added Locale import; detects OS and uses Windows cmd.exe, macOS open, or Linux xdg-open to open the application file.
page-object/src/main/java/com/iluwatar/pageobject/App.java Mirrored changes from sample app: replace Runtime.exec with ProcessBuilder, added Locale import, and OS-based commands (Windows cmd.exe, macOS open, Linux xdg-open) to securely open the app file.

autogenerated by presubmit.ai

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown

@prashantpiyush1111 prashantpiyush1111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

@orbisai0security
Copy link
Copy Markdown
Contributor Author

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.

This is addressed. So can you pls review.

@prashantpiyush1111
Copy link
Copy Markdown

Thanks for addressing the previous concerns!
Cross-platform support looks good

However, SonarQube Quality Gate has failed
3 Security Hotspots detected.

Please review and fix the SonarQube issues
before this can be approved.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@iluwatar iluwatar force-pushed the fix-v-002-os-command-injection-page-object-sample-app branch from 23814e1 to 65fc792 Compare June 7, 2026 06:30
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()"

Comment on lines +87 to +91
new ProcessBuilder(
"C:\\Windows\\System32\\cmd.exe",
"/c",
"start",
applicationFile.getAbsolutePath());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new ProcessBuilder(
"C:\\Windows\\System32\\cmd.exe",
"/c",
"start",
applicationFile.getAbsolutePath());
new ProcessBuilder(
"C:\\Windows\\System32\\cmd.exe",
"/c",
"start",
"");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

@orbisai0security
Copy link
Copy Markdown
Contributor Author

Code review comments are addressed. Pls review.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@c70b63d). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants