fix: Secure OpenWrt change_password against OS command injection#1376
fix: Secure OpenWrt change_password against OS command injection#1376kartikbhartiya wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR hardens the remote password-change functionality in the OpenWrt SSH connector. The Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error)
✅ Passed checks (4 passed)
✨ 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 |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge This PR correctly addresses a critical OS command injection vulnerability in the What was fixed:
Review notes:
Files Reviewed (2 files)
Reviewed by kimi-k2.5-0127 · 88,845 tokens |
There was a problem hiding this comment.
Pull request overview
Addresses an OS command injection vulnerability in OpenWrt.change_password by sanitizing all string inputs via shlex.quote and replacing echo -e with printf '%s\n%s\n' to avoid backslash interpretation.
Changes:
- Sanitize
password,confirm_password, anduserarguments withshlex.quotebefore string interpolation. - Switch from
echo -etoprintf '%s\n%s\n'for safer/POSIX-compliant piping intopasswd. - Update
test_execute_change_passwordassertion to the new command format.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| openwisp_controller/connection/connectors/openwrt/ssh.py | Quote shell inputs and use printf instead of echo -e in change_password. |
| openwisp_controller/connection/tests/test_models.py | Update the expected exec_command argument in the change-password test. |
Notes:
- The updated test's expected string (
'Newpasswd@123','root') does not match whatshlex.quoteactually returns for those safe-character inputs, so the test will fail as written. There is also no new test asserting the quoting actually protects against shell metacharacters (e.g. a password containing spaces,;,$,"), which is the core hardening claim of this PR.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| mocked_exec_command.assert_called_once() | ||
| mocked_exec_command.assert_called_with( | ||
| 'echo -e "Newpasswd@123\nNewpasswd@123" | passwd root', | ||
| "printf '%s\\n%s\\n' 'Newpasswd@123' 'Newpasswd@123' | passwd 'root'", |
Test Failures in
|
Security Fix for OS Command Injection
We have identified and resolved a critical OS Command Injection vulnerability in the OpenWrt connection connector (change_password method).
Changes Made
1. Hardened command building in ssh.py
2. Updated corresponding test case