-
-
Notifications
You must be signed in to change notification settings - Fork 52
feat: automated security hardening as per CIS benchmarks #105 #520
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,12 @@ | ||||||||||||||||||||||
| import os | ||||||||||||||||||||||
| import shlex | ||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def harden_package_manager(package_name): | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add required type hints and docstring. This public function lacks type hints and a docstring, which violates the coding guidelines requiring both for all public APIs in Python. 🔎 Proposed fix-def harden_package_manager(package_name):
+def harden_package_manager(package_name: str) -> None:
+ """
+ Upgrade a specific package to its latest version.
+
+ Args:
+ package_name: The name of the package to upgrade.
+
+ Raises:
+ subprocess.CalledProcessError: If the apt-get command fails.
+ """As per coding guidelines, type hints and docstrings are required for all public APIs. 🤖 Prompt for AI Agents |
||||||||||||||||||||||
| # Security: Use shlex.quote to prevent shell injection | ||||||||||||||||||||||
| safe_name = shlex.quote(package_name) | ||||||||||||||||||||||
| print(f"Hardening package: {safe_name}") | ||||||||||||||||||||||
| try: | ||||||||||||||||||||||
| subprocess.run(["apt-get", "install", "--only-upgrade", safe_name], check=True) | ||||||||||||||||||||||
|
Comment on lines
+6
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CRITICAL: Incorrect use of When using Either:
🔎 Proposed fix- # Security: Use shlex.quote to prevent shell injection
- safe_name = shlex.quote(package_name)
- print(f"Hardening package: {safe_name}")
+ print(f"Hardening package: {package_name}")
try:
- subprocess.run(["apt-get", "install", "--only-upgrade", safe_name], check=True)
+ subprocess.run(["apt-get", "install", "--only-upgrade", package_name], check=True)
except subprocess.CalledProcessError as e:
print(f"Failed to harden: {e}")Based on learnings, when using subprocess with a list of arguments, shell injection is already prevented without needing 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add privilege verification before executing system commands. The 🔎 Proposed fix+ if os.geteuid() != 0:
+ print("Error: This script must be run as root (use sudo)")
+ return
+
print(f"Hardening package: {package_name}")
try:
subprocess.run(["apt-get", "install", "--only-upgrade", package_name], check=True)Note: If you add this check, keep the
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| except subprocess.CalledProcessError as e: | ||||||||||||||||||||||
| print(f"Failed to harden: {e}") | ||||||||||||||||||||||
|
Comment on lines
+5
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CRITICAL: Missing CIS benchmark implementation contradicts PR objectives. The PR objectives state this implements "automated security hardening as per CIS benchmarks" from issue #105, but this function only upgrades a single package—it doesn't implement any CIS benchmark controls. Additionally, the past review comments reference a CIS benchmark hardening typically includes:
Before merging, either:
Do you want me to help generate an implementation that performs actual CIS benchmark hardening? 🤖 Prompt for AI Agents |
||||||||||||||||||||||
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.
Remove unused import.
The
osmodule is imported but never used in this file.🔎 Proposed fix
-import os import shlex import subprocess🤖 Prompt for AI Agents