Fix ModelManager Uncontrolled command line dependencyPath #3426
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
serve/frontend/server/src/main/java/org/pytorch/serve/wlm/ModelManager.java
Line 332 in 62c4d6a
serve/frontend/server/src/main/java/org/pytorch/serve/wlm/ModelManager.java
Lines 383 to 389 in 62c4d6a
Code that passes user input directly to
Runtime.exec
, or some other library routine that executes a command, allows the user to execute malicious code. The following shows code that takes a shell script that can be changed maliciously by a user, and passes it straight toRuntime.exec
without examining it first.fix the issue must ensure that user-controlled input is properly sanitized and validated before it is used in a command execution context. Specifically:
Restrict the
dependencyPath
to known-safe directories:isValidDependencyPath()
to ensure that the path resolves to a pre-approved, hard-coded directory (e.g., within a specific application-controlled directory tree).Reject symbolic links and enforce canonical paths:
dependencyPath
does not point to a symbolic link or any unintended location. UseFile.getCanonicalPath()
for validation.Construct the command using only sanitized paths:
ProcessBuilder
command.Log and handle invalid paths appropriately:
dependencyPath
validation fails, throw an exception and log the issue.References
IDS07-J. Sanitize untrusted data passed to the Runtime.exec() method
Command Injection
Type of change
Please delete options that are not relevant.
Feature/Issue validation/testing
Please describe the Unit or Integration tests that you ran to verify your changes and relevant result summary. Provide instructions so it can be reproduced.
Please also list any relevant details for your test configuration.
Test A
Logs for Test A
Test B
Logs for Test B
Checklist: