-
Notifications
You must be signed in to change notification settings - Fork 908
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
chore: Handle all level 1 TiCS security violations #5103
Conversation
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.
nit: could we please add some context about these suppressions to inline comments? A comment on the preceding line describing which Bandit code this suppresses and (optionally) why would go a long ways.
also, just a minor nitpick but I think that intermixing the URIs with the codes in the message makes the message a bit dense to parse - a list of links at the end with [N] refs would be easier to read
chore: Handle all level 1 TiCS security violations
Ignore these bandit violations as we're not dealing with untrusted
input. Violations ignored in this commit are:
* B314: xml_bad_ElementTree
B318: xml_bad_mindom
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b313-b320-xml
* B405: import_xml_etree
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b405-import-xml-etree
* B406: import_xml_sax
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b406-import-xml-sax
* B408: import_xml_minidom
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b408-import-xml-minidom
* B603: subprocess_without_shell_equals_true
https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html#b603-subprocess-without-shell-equals-tru
cloudinit/cmd/devel/logs.py
Outdated
@@ -167,7 +167,7 @@ def _stream_command_output_to_file(cmd, filename, msg, verbosity): | |||
ensure_dir(os.path.dirname(filename)) | |||
try: | |||
with open(filename, "w") as f: | |||
subprocess.call(cmd, stdout=f, stderr=f) | |||
subprocess.call(cmd, stdout=f, stderr=f) # nosec |
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.
+1, B603 is a pretty silly check - see PyCQA/bandit#333
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.
Yep...there's also a separate check for shell=True
. So no shell gives you one error while having shell gives you another.
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.
So no shell gives you one error while having shell gives you another.
/facepalm
@@ -205,7 +205,7 @@ def doexit(sysexit): | |||
def execmd(exe_args, output=None, data_in=None): | |||
ret = 1 | |||
try: | |||
proc = subprocess.Popen( | |||
proc = subprocess.Popen( # nosec |
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.
This one is also to suppress B603, right?
Also I'm a little surprised that subp isn't used here.
Ignore these bandit violations as we're not dealing with untrusted input. Violations ignored in this commit are: B314: xml_bad_ElementTree B318: xml_bad_mindom B405: import_xml_etree B406: import_xml_sax B408: import_xml_minidom B603: subprocess_without_shell_equals_true
1fe329d
to
41683e4
Compare
@holmanb , I updated all of the Also, I removed the URLs entirely from the commit message. They can be easily googleable. Let me know if these changes make sense to you. |
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.
One nit, but feel free to merge once fixed!
cloudinit/sources/azure/errors.py
Outdated
@@ -9,7 +9,7 @@ | |||
from datetime import datetime | |||
from io import StringIO | |||
from typing import Any, Dict, List, Optional, Tuple | |||
from xml.etree import ElementTree | |||
from xml.etree import ElementTree # B405 |
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.
is this supposed to have a nosec
in the comment?
Ignore these bandit violations as we're not dealing with untrusted input. Violations ignored in this commit are: B314: xml_bad_ElementTree B318: xml_bad_mindom B405: import_xml_etree B406: import_xml_sax B408: import_xml_minidom B603: subprocess_without_shell_equals_true
Ignore these bandit violations as we're not dealing with untrusted input. Violations ignored in this commit are: B314: xml_bad_ElementTree B318: xml_bad_mindom B405: import_xml_etree B406: import_xml_sax B408: import_xml_minidom B603: subprocess_without_shell_equals_true
Ignore these bandit violations as we're not dealing with untrusted input. Violations ignored in this commit are: B314: xml_bad_ElementTree B318: xml_bad_mindom B405: import_xml_etree B406: import_xml_sax B408: import_xml_minidom B603: subprocess_without_shell_equals_true
Proposed Commit Message
Additional Context
This PR addresses all of the level 1 warnings at: https://canonical.tiobe.com/tiobeweb/TICS/ViolationsDashboard.html#axes=Project(cloud-init)&sort=T(4,worst)&x=Ap(type),Ap(rule),Ap(level),Ap(impactAtProject),Ap(impactAtScope),Ap(message)
(Link is Canonical only)
I attempted to add a bandit config to ignore certain warnings, but TiCS won't pick it up. We have to go line by line.
As of right now, we're only concerned with Level 1 warnings. Running locally, I got this result:
Since this is all purely ignores, I see no reason to add the ruff-equivalent checks to CI yet. When we get to addressing real issues, those checks can be added then.
Merge type