🛡️ Sentinel: Fix shell injection and parsing vulnerabilities in entrypoint.sh#38
🛡️ Sentinel: Fix shell injection and parsing vulnerabilities in entrypoint.sh#38
Conversation
Fixes multiple security issues in the Docker entrypoint script: - Improper quoting of variables leading to word splitting and globbing. - Unsafe `read` usage stripping backslashes from passwords. - Format string vulnerability in `printf`. - Logic bug preventing execution of multiple commands in `VPNCMD_*` variables. Verification: - Verified with `verify_fix.sh` that passwords with spaces, globs (`*`), and backslashes are handled correctly. - Verified that multiple semicolon-separated commands are executed. - Verified syntax with `bash -n`. Co-authored-by: bluPhy <11618798+bluPhy@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello @bluPhy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the security posture and reliability of the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
WalkthroughIntroduces security guidance documentation for Shell Script Injection Patterns at Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request significantly hardens the entrypoint.sh script by addressing several shell injection and parsing vulnerabilities. The changes, including consistent variable quoting, use of read -r, format string protection in printf, and safe execution of dynamic commands with set -f, are excellent security improvements. The logic for processing multiple users and commands from environment variables has also been corrected and clarified. I've added a few suggestions to further improve the script's robustness by adding checks for empty values when parsing user and command lists, making it more resilient to malformed input.
| for pair in "${USER_PAIRS[@]}"; do | ||
| # Split by colon into username and password | ||
| IFS=':' read -r username password <<<"$pair" | ||
| # echo "Creating user: ${username}" | ||
| adduser $username $password | ||
| done | ||
| done <<<"$USERS" | ||
| adduser "$username" "$password" | ||
| done |
There was a problem hiding this comment.
The loop processing $USERS is much improved, but it could be made more robust. If $USERS contains empty segments (e.g., user1:pass1;;user2:pass2) or a pair without a username (e.g., :password), the script will attempt to create a user with an empty username. It's good practice to validate that the username is not empty before proceeding to avoid potential errors.
| for pair in "${USER_PAIRS[@]}"; do | |
| # Split by colon into username and password | |
| IFS=':' read -r username password <<<"$pair" | |
| # echo "Creating user: ${username}" | |
| adduser $username $password | |
| done | |
| done <<<"$USERS" | |
| adduser "$username" "$password" | |
| done | |
| for pair in "${USER_PAIRS[@]}"; do | |
| # Split by colon into username and password | |
| IFS=':' read -r username password <<<"$pair" | |
| if [ -n "$username" ]; then | |
| adduser "$username" "$password" | |
| fi | |
| done |
| for cmd in "${CMDS[@]}"; do | ||
| set -f | ||
| vpncmd_server $cmd | ||
| set +f | ||
| done |
There was a problem hiding this comment.
This loop for processing $VPNCMD_SERVER commands could be more robust. If $VPNCMD_SERVER contains empty commands (e.g., cmd1;;cmd2), the loop will execute vpncmd_server with no arguments, which may lead to unexpected behavior. It's safer to skip empty commands.
Additionally, running the command in a subshell (...) is a cleaner way to temporarily disable globbing (set -f) without affecting the parent shell's state.
| for cmd in "${CMDS[@]}"; do | |
| set -f | |
| vpncmd_server $cmd | |
| set +f | |
| done | |
| for cmd in "${CMDS[@]}"; do | |
| if [ -n "$cmd" ]; then | |
| (set -f; vpncmd_server $cmd) | |
| fi | |
| done |
| for cmd in "${CMDS[@]}"; do | ||
| set -f | ||
| vpncmd_hub $cmd | ||
| set +f | ||
| done |
There was a problem hiding this comment.
This loop for processing $VPNCMD_HUB commands has the same potential issue as the $VPNCMD_SERVER loop. If $VPNCMD_HUB contains empty commands, vpncmd_hub will be called without arguments. It's best to add a check to skip empty commands for robustness.
Using a subshell is also recommended here to temporarily disable globbing.
| for cmd in "${CMDS[@]}"; do | |
| set -f | |
| vpncmd_hub $cmd | |
| set +f | |
| done | |
| for cmd in "${CMDS[@]}"; do | |
| if [ -n "$cmd" ]; then | |
| (set -f; vpncmd_hub $cmd) | |
| fi | |
| done |
This PR hardens the
copyables/entrypoint.shscript by fixing several shell scripting vulnerabilities.Security Fixes:
"$PSK","$USERNAME") to prevent accidental word splitting and file globbing.read -rto prevent backslashes in passwords/usernames from being interpreted as escape characters.set -f(noglob) when processing dynamic commands fromVPNCMD_SERVERandVPNCMD_HUBto safely split arguments without expanding wildcards.printf " $1"toprintf " %s" "$1"in theadduserfunction.Bug Fixes:
VPNCMD_SERVERandVPNCMD_HUBto correctly iterate over all semicolon-separated commands (previously only the first command was executed).Verification:
A verification script was created and run to confirm:
*in passwords does not expand to filenames.PR created automatically by Jules for task 12604410747989356806 started by @bluPhy
Summary by CodeRabbit
Documentation
Bug Fixes