Skip to content

[#3570] fix(integration-test): Fix possible command inject vulnerability in ProcessBuilder#4337

Closed
yuqi1129 wants to merge 1 commit intoapache:mainfrom
yuqi1129:issue_3570
Closed

[#3570] fix(integration-test): Fix possible command inject vulnerability in ProcessBuilder#4337
yuqi1129 wants to merge 1 commit intoapache:mainfrom
yuqi1129:issue_3570

Conversation

@yuqi1129
Copy link
Contributor

@yuqi1129 yuqi1129 commented Aug 1, 2024

What changes were proposed in this pull request?

Fix potential command inject bugs in ProcessBuilder. Passing a single string as the parameter of ProcessBuilder will lead to the command inject vulnerability, for example, if the value of the command is ls -al ;rm -rf, then it will launch a process that will execute ls -al first and then rm -rf.

However, If we split the command to a list like ['ls', '-al', ';rm', "-rf"], the list will view as a single command and values start from -al will be viewed the parameter as the command ls , so command rm -rf will not take effect.

Why are the changes needed?

To fix the bug.

Fix: #3570

Does this PR introduce any user-facing change?

N/A.

How was this patch tested?

Existing IT.

LOG.info("Sending command \"{}\" to localhost", mergedCommand);

ProcessBuilder processBuilder = new ProcessBuilder(command);
ProcessBuilder processBuilder = new ProcessBuilder(subCommandsAsList);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please explain why changing this could avoid command injection?

Copy link
Contributor Author

@yuqi1129 yuqi1129 Aug 2, 2024

Choose a reason for hiding this comment

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

If the command is a string value, ProcessBuilder will take it as a whole command like ls -al; rm -rf, however, if we split it into a list, -al;, rm, -rf will be reviewed as the parameter of the first command ls, thus dangerous operations like rm -rf will not take effect.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please put it on the PR description.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let a example. If we the command is a string value, ProcessBuilder will take it as a whole command like ls -al; rm -rf, however, if we split it into a list, -al;, rm, -rf will be reviewed as the parameter of the first value, thus dangerous operation like rm -rf will not take effect.

It's really hard to understand the meanings of what you say, can you please rephrase the words.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why changing from array to list will solve the problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

List<String> subCommandsAsList = new ArrayList<>(Arrays.asList(command));

Why do we need to wrap a list again with ArrayList.

@yuqi1129
Copy link
Contributor Author

yuqi1129 commented Aug 2, 2024

I will temporarily close this PR as it could not solve the problem thoroughly as we lack more details about the issue. Once more information is provided, I will continue working on this issue.

@yuqi1129 yuqi1129 closed this Aug 2, 2024
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.

[Bug report] there is a RCE security problem

2 participants