-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
Thank you for your pull request. |
Automated checks report:
Some checks failed. Please fix the reported issues and reply 'alluxio-bot, check this please' to re-run checks. |
ad5bf26
to
4b5ec25
Compare
Automated checks report:
All checks passed! |
alluxio-bot, check this please |
Automated checks report:
All checks passed! |
FYI: @yyongycy |
Hi, guys, when will this bug fix be merged? |
List<String> userAllGroups = new ArrayList<>(); | ||
userEffectiveGroups.add(userEffectiveGroup1); | ||
userEffectiveGroups.add(userEffectiveGroup2); | ||
userAllGroups.add(userAllGroup1); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}; | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this 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){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static String[] getEffectiveGroupsForUserCommand(final String user){ | |
public static String[] getEffectiveGroupsForUserCommand(final String user) { |
### 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
### 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
Merged as part of #18536 |
### 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
What changes are proposed in this pull request?
We split the
ShellUtils.getGroupsForUserCommand
into two seperate methodsShellUtils.getEffectiveGroupsForUserCommand
andShellUtils.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 theShellUtils.getGroupsForUserCommand
in case some users' codes stongly rely on this method. But in the repositoryAlluxio/alluxio
,ShellUtils.getGroupsForUserCommand
is never used anymore. It is replaced byShellUtils.getEffectiveGroupsForUserCommand
andShellUtils.getAllGroupsForUserCommand
.