Skip to content
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

Fix code injection vulnerability of getGroupsForUserCommand #17256

Closed
wants to merge 3 commits into from

Conversation

LetianYuan
Copy link

What changes are proposed in this pull request?

We split the ShellUtils.getGroupsForUserCommand into two seperate methods ShellUtils.getEffectiveGroupsForUserCommand and ShellUtils.getAllGroupsForUserCommand. Then change the corresponding test cases.

Why are the changes needed?

Executing commands like "bash -c some_command" will introduce code injection vulnerability.

For example, if CommonUtils.getUnixGroups("| echo 123 ") is invoked, the whole command is truncated by |and "echo 123" will be executed.

Therefore, the most simple way to fix it is to not to use "bash -c".

Does this PR introduce any user facing changes?

@Deprecated is marked on the ShellUtils.getGroupsForUserCommand in case some users' codes stongly rely on this method. But in the repository Alluxio/alluxio, ShellUtils.getGroupsForUserCommand is never used anymore. It is replaced by ShellUtils.getEffectiveGroupsForUserCommand and ShellUtils.getAllGroupsForUserCommand.

@alluxio-bot
Copy link
Contributor

Thank you for your pull request.
In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement (CLA).
It's all electronic and will take just a few minutes. Please download CLA form here, sign, and e-mail back to [email protected]

@alluxio-bot
Copy link
Contributor

Automated checks report:

  • Commits associated with Github account: FAIL
    • It looks like your commits can't be linked to a valid Github account.
      Your commits are made with the email [email protected], which does not allow your contribution to be tracked by Github.
      See this link for possible reasons this might be happening.
      To change the author email address that your most recent commit was made under, you can run:
      git -c user.name="Name" -c user.email="Email" commit --amend --reset-author
      See this answer for more details about how to change commit email addresses.
      Once the author email address has been updated, update the pull request by running:
      git push --force https://github.com/LetianYuan/alluxio.git fix_code_injection
  • PR title follows the conventions: FAIL
    • The title of the PR does not pass all the checks. Please fix the following issues:
      • Title is too long (81 characters). Must be at most 72 characters.
      • First word must be capitalized

Some checks failed. Please fix the reported issues and reply 'alluxio-bot, check this please' to re-run checks.

@LetianYuan LetianYuan changed the title fix code injection vulnerability introduced by ShellUtils.getGroupsForUserCommand Fix code injection vulnerability introduced by ShellUtils.getGroupsForUserCommand Apr 16, 2023
@LetianYuan LetianYuan changed the title Fix code injection vulnerability introduced by ShellUtils.getGroupsForUserCommand Fix code injection vulnerability of getGroupsForUserCommand Apr 16, 2023
@alluxio-bot
Copy link
Contributor

Automated checks report:

  • Commits associated with Github account: PASS
  • PR title follows the conventions: PASS

All checks passed!

@LetianYuan
Copy link
Author

alluxio-bot, check this please

@alluxio-bot
Copy link
Contributor

Automated checks report:

  • Commits associated with Github account: PASS
  • PR title follows the conventions: PASS

All checks passed!

@ChunxuTang
Copy link
Member

FYI: @yyongycy

@MacChen01
Copy link

Hi, guys, when will this bug fix be merged?

List<String> userAllGroups = new ArrayList<>();
userEffectiveGroups.add(userEffectiveGroup1);
userEffectiveGroups.add(userEffectiveGroup2);
userAllGroups.add(userAllGroup1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add negative case like
ShellUtils.execCommand(ShellUtils.getEffectiveGroupsForUserCommand("| echo 123 ") to see if that works.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry. I'm not quite familiar with PowerMockito. These codes are written after my one-hour's quick learning. So, I don't know how to add a negative case.

If possible, I'll do more researches on PowerMockito. But I'm much busy now.

And it's welcome that you or someone else to give me a hand to add a negative case.

*/
@Deprecated
public static String[] getGroupsForUserCommand(final String user) {
return new String[] {"bash", "-c", "id -gn " + user + "; id -Gn " + user};
}
Copy link
Contributor

@lucyge2022 lucyge2022 Feb 28, 2024

Choose a reason for hiding this comment

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

i think you can get rid of this function as it exposes vulnerability

Copy link
Contributor

@yyongycy yyongycy left a comment

Choose a reason for hiding this comment

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

lgtm

add negative shellutil for "get effective group name from use"
* @param user the user name
* @return the Unix command to get a given user's effective groups list
*/
public static String[] getEffectiveGroupsForUserCommand(final String user){
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public static String[] getEffectiveGroupsForUserCommand(final String user){
public static String[] getEffectiveGroupsForUserCommand(final String user) {

This was referenced Feb 29, 2024
alluxio-bot pushed a commit that referenced this pull request Mar 4, 2024
### What changes are proposed in this pull request?

Port changes from  [@LetianYuan](https://github.com/LetianYuan) in PR : #17256
in urgency for resolving injection vulnerability.

### Why are the changes needed?

Resolve issue:  https://nvd.nist.gov/vuln/detail/CVE-2023-38889

### Does this PR introduce any user facing changes?

No.

			pr-link: #18532
			change-id: cid-de6273697887692ceda876d556e910bdd529d2ee
alluxio-bot pushed a commit that referenced this pull request Mar 4, 2024
### What changes are proposed in this pull request?

Port changes from  [@LetianYuan](https://github.com/LetianYuan) in PR : #17256
in urgency for resolving injection vulnerability.

### Why are the changes needed?

Resolve issue:  https://nvd.nist.gov/vuln/detail/CVE-2023-38889

### Does this PR introduce any user facing changes?

No.

			pr-link: #18536
			change-id: cid-a8122e3ff3324f1a9d881f55cc425ab30a020c35
@lucyge2022
Copy link
Contributor

Merged as part of #18536
Thanks for the contribution!

@lucyge2022 lucyge2022 closed this Mar 5, 2024
alluxio-bot pushed a commit that referenced this pull request Mar 12, 2024
### What changes are proposed in this pull request?

Port changes from  [@LetianYuan](https://github.com/LetianYuan) in PR : #17256
in urgency for resolving injection vulnerability.

### Why are the changes needed?

Resolve issue:  https://nvd.nist.gov/vuln/detail/CVE-2023-38889

### Does this PR introduce any user facing changes?

No.

			pr-link: #18532
			change-id: cid-de6273697887692ceda876d556e910bdd529d2ee
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.

7 participants