codeaudit 1.0.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. codeaudit-1.2.0/CHANGELOG.md +59 -0
  2. {codeaudit-1.0.0 → codeaudit-1.2.0}/PKG-INFO +14 -11
  3. {codeaudit-1.0.0 → codeaudit-1.2.0}/README.md +13 -10
  4. {codeaudit-1.0.0 → codeaudit-1.2.0}/SECURITY.md +0 -1
  5. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/CLIcommands.ipynb +23 -16
  6. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/CONTRIBUTE.md +11 -1
  7. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/_toc.yml +16 -7
  8. codeaudit-1.2.0/docs/apidocs/api_intro.md +19 -0
  9. codeaudit-1.2.0/docs/apidocs/codeaudit.rst +12 -0
  10. codeaudit-1.2.0/docs/apidocs/modules.rst +7 -0
  11. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/assert_check.md +37 -5
  12. codeaudit-1.2.0/docs/checks/builtinfunctions_check.md +138 -0
  13. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/input_check.md +11 -2
  14. codeaudit-1.2.0/docs/checks/systemcalls_check.md +76 -0
  15. codeaudit-1.2.0/docs/checks/tarfile_extract_check.md +76 -0
  16. codeaudit-1.2.0/docs/checksinformation.md +44 -0
  17. codeaudit-1.2.0/docs/codeauditchecks.md +22 -0
  18. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/codeauditcommands.md +14 -42
  19. codeaudit-1.2.0/docs/examples/ca_api_example_basic.ipynb +191 -0
  20. codeaudit-1.2.0/docs/examples/ca_api_example_json.ipynb +197 -0
  21. codeaudit-1.2.0/docs/examples/ca_api_example_overview.ipynb +160 -0
  22. codeaudit-1.2.0/docs/examples/checks.html +637 -0
  23. codeaudit-1.2.0/docs/examples/demoscan.json +205 -0
  24. codeaudit-1.2.0/docs/features.md +53 -0
  25. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/filescan.md +29 -11
  26. codeaudit-1.2.0/docs/howtoscan.md +113 -0
  27. codeaudit-1.2.0/docs/implementedvalidations.md +63 -0
  28. codeaudit-1.2.0/docs/intro.md +76 -0
  29. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/issues.md +22 -2
  30. codeaudit-1.2.0/docs/makeitbetter.md +109 -0
  31. codeaudit-1.2.0/docs/pca_overview.png +0 -0
  32. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/sponsors.md +2 -0
  33. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/userguide.md +10 -3
  34. codeaudit-1.2.0/docs/whatissast.md +34 -0
  35. codeaudit-1.2.0/docs/whysast.md +92 -0
  36. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/__about__.py +1 -1
  37. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/altairplots.py +53 -0
  38. codeaudit-1.2.0/src/codeaudit/api_interfaces.py +269 -0
  39. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/checkmodules.py +28 -10
  40. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/codeaudit.py +4 -5
  41. codeaudit-1.2.0/src/codeaudit/data/sastchecks.csv +71 -0
  42. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/filehelpfunctions.py +27 -5
  43. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/reporting.py +41 -23
  44. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/totals.py +1 -1
  45. codeaudit-1.2.0/tests/test_apicalls.py +60 -0
  46. codeaudit-1.2.0/tests/test_modulecheck.py +40 -0
  47. codeaudit-1.2.0/tests/validationfiles/allshit.py +480 -0
  48. codeaudit-1.2.0/tests/validationfiles/dunderexec_with_parsing_error.py +34 -0
  49. codeaudit-1.0.0/CHANGELOG.md +0 -22
  50. codeaudit-1.0.0/docs/checks/builtinfunctions_check.md +0 -57
  51. codeaudit-1.0.0/docs/checks/systemcalls_check.md +0 -38
  52. codeaudit-1.0.0/docs/checks/tarfile_extract_check.md +0 -31
  53. codeaudit-1.0.0/docs/checksinformation.md +0 -73
  54. codeaudit-1.0.0/docs/codeauditchecks.md +0 -21
  55. codeaudit-1.0.0/docs/directoryscan.md +0 -75
  56. codeaudit-1.0.0/docs/examples/checks_example.html +0 -585
  57. codeaudit-1.0.0/docs/features.md +0 -60
  58. codeaudit-1.0.0/docs/intro.md +0 -48
  59. codeaudit-1.0.0/docs/whysast.md +0 -39
  60. codeaudit-1.0.0/src/codeaudit/data/sastchecks.csv +0 -71
  61. codeaudit-1.0.0/tests/test_modulecheck.py +0 -21
  62. {codeaudit-1.0.0 → codeaudit-1.2.0}/.gitignore +0 -0
  63. {codeaudit-1.0.0 → codeaudit-1.2.0}/CONTRIBUTE.md +0 -0
  64. {codeaudit-1.0.0 → codeaudit-1.2.0}/LICENSE.txt +0 -0
  65. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/_config.yml +0 -0
  66. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/_static/nocxstyle.css +0 -0
  67. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/about.md +0 -0
  68. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/astlines.md +0 -0
  69. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/astlines2.md +0 -0
  70. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/changelog.md +0 -0
  71. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/base64_check.md +0 -0
  72. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/binding_check.md +0 -0
  73. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/chmod_check.md +0 -0
  74. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/directorycreation_check.md +0 -0
  75. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/dynamicimport_check.md +0 -0
  76. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/exception_check.md +0 -0
  77. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/hash_check.md +0 -0
  78. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/httpserver_check.md +0 -0
  79. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/loggingconf_check.md +0 -0
  80. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/marshal_check.md +0 -0
  81. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/mktemp_check.md +0 -0
  82. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/multiprocessing_check.md +0 -0
  83. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/pickle_check.md +0 -0
  84. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/random_check.md +0 -0
  85. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/shelve_check.md +0 -0
  86. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/shutil_check.md +0 -0
  87. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/subprocess_check.md +0 -0
  88. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/syscalls_check.md +0 -0
  89. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/xml_check.md +0 -0
  90. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/checks/zipfile_check.md +0 -0
  91. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/codeauditoverview.md +0 -0
  92. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/complexitycheck.md +0 -0
  93. /codeaudit-1.0.0/tests/validationfiles/allshit.py → /codeaudit-1.2.0/docs/examples/demofile.py +0 -0
  94. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/examples/directoryscan.html +0 -0
  95. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/examples/filescan.html +0 -0
  96. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/examples/modulescan.html +0 -0
  97. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/examples/overview.html +0 -0
  98. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/filescan.png +0 -0
  99. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/help.md +0 -0
  100. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/images/OO.png +0 -0
  101. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/images/ROI_logo.png +0 -0
  102. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/images/YourLogoHere.png +0 -0
  103. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/images/codeauditlogo.png +0 -0
  104. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/images/nocxbanner.png +0 -0
  105. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/images/overview_linkaudit.png +0 -0
  106. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/license.md +0 -0
  107. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/modulescan.md +0 -0
  108. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/overviewplot.png +0 -0
  109. {codeaudit-1.0.0 → codeaudit-1.2.0}/docs/warnings.md +0 -0
  110. {codeaudit-1.0.0 → codeaudit-1.2.0}/filescan.png +0 -0
  111. {codeaudit-1.0.0 → codeaudit-1.2.0}/pyproject.toml +0 -0
  112. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/__init__.py +0 -0
  113. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/complexitycheck.py +0 -0
  114. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/htmlhelpfunctions.py +0 -0
  115. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/issuevalidations.py +0 -0
  116. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/security_checks.py +0 -0
  117. {codeaudit-1.0.0 → codeaudit-1.2.0}/src/codeaudit/simple.css +0 -0
  118. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/__init__.py +0 -0
  119. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/count_lines_file1.py +0 -0
  120. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_basicpatterns.py +0 -0
  121. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_chmod.py +0 -0
  122. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_constructspart2.py +0 -0
  123. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_correctexceptionuse.py +0 -0
  124. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_count_commentlines.py +0 -0
  125. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_directorycreation.py +0 -0
  126. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_directorycreation2.py +0 -0
  127. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_hashstrenght.py +0 -0
  128. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_obfuscatingbuiltins.py +0 -0
  129. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_oschecks.py +0 -0
  130. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_random.py +0 -0
  131. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_standardlibconstructs.py +0 -0
  132. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/test_totalscheck.py +0 -0
  133. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/assert.py +0 -0
  134. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/base64.py +0 -0
  135. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/chmod_things.py +0 -0
  136. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/complexitycheck.py +0 -0
  137. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/correctcounts.py +0 -0
  138. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/directorycreation.py +0 -0
  139. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/directorycreation2.py +0 -0
  140. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/exception.py +0 -0
  141. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/file3.py +0 -0
  142. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/file_with_warnings.py +0 -0
  143. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/gzip.py +0 -0
  144. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/hashcheck.py +0 -0
  145. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/httpserver.py +0 -0
  146. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/inputstatement.py +0 -0
  147. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/marshal.py +0 -0
  148. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/modulecheck.py +0 -0
  149. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/multiprocessing.py +0 -0
  150. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/obfuscating.py +0 -0
  151. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/oschecks.py +0 -0
  152. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/pickle.py +0 -0
  153. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/python2_file_willnotwork.py +0 -0
  154. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/random.py +0 -0
  155. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/shelve.py +0 -0
  156. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/shutil.py +0 -0
  157. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/subprocess.py +0 -0
  158. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/syslibrary.py +0 -0
  159. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/tarfilevalidation.py +0 -0
  160. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/tempcheck.py +0 -0
  161. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/validation1.py +0 -0
  162. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/validation2.py +0 -0
  163. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/xml.py +0 -0
  164. {codeaudit-1.0.0 → codeaudit-1.2.0}/tests/validationfiles/zipfile.py +0 -0
@@ -0,0 +1,59 @@
1
+ # Change Log
2
+
3
+ # Version 1.2: Changes and Updates
4
+
5
+ * fix: Improved error handling — when performing a file scan on a single Python file that cannot be parsed, the CLI now correctly displays an error message.
6
+
7
+ * fix: Updated API logic to properly handle parsing errors for single Python files.
8
+
9
+ * fix: Corrected validation descriptions for `os.write` and `os.writev`. Writing to unvalidated or unintended file descriptors can lead to data corruption, privilege escalation, or denial of service.
10
+
11
+ * fix: Internal API functions now use a leading underscore (`_`) to clearly distinguish them from public APIs.
12
+
13
+ * **new**: Added a function for weakness visualization. Refer to the examples for usage details.
14
+
15
+ * **new**: Added API documentation and examples for usage details.
16
+
17
+
18
+ ## Version 1.1:What's New
19
+
20
+ We've released a new version with several key improvements focused on making your security workflow smoother and providing more detailed security information.
21
+
22
+ * Streamlined Scanning:
23
+
24
+ The separate `directoryscan` command has been removed. You can now use the versatile `filescan` command to scan both individual files and entire directories. This simplifies the command-line interface and makes the process more intuitive.
25
+
26
+ * Enhanced Reporting:
27
+
28
+ We've made minor corrections to the documentation and static HTML reports to improve clarity. Additionally, warning messages are now more descriptive, helping you quickly understand potential issues.
29
+
30
+ * Improved Vulnerability Data:
31
+
32
+ You'll now get more detailed information about module vulnerabilities. The tool now includes CVSS scores, a standard metric for rating vulnerability severity, giving you a clearer picture of the risks.
33
+
34
+ * Behind-the-Scenes Fixes:
35
+
36
+ We've made a more robust and reliable adjustment to how the tool retrieves file names. This ensures consistency and accuracy during scans. We've also added beta-level API functions, opening up new possibilities for integration.
37
+
38
+
39
+
40
+ ## Version 1.0
41
+
42
+ This release represents a stabilisation of Python Code Audit!
43
+ Main changes in relation to the pre-1.0 versions are:
44
+ * More validations added: Python Code Audit now counts 70 security validations!
45
+ * Documentation updates
46
+ * Improved validation for `builtins`, like `compile`, `exec`,, `eval` that can be obfuscated in code.
47
+ * Various UI/UX updates. CLI text improved and HTML report text made consistent.
48
+ * Added test to validate correct working for now and in the future. Also validated working with other SAST tools to make sure core functionality is rock solid or better! Spoiler Python Code Audit is better than most used OSS and commercial SAST tools available today!
49
+
50
+
51
+ ## Beta Versions (Before 1.0)
52
+
53
+ All published beta version are stable and verified!
54
+ During the public beta phase input of users and experts is retrieved.
55
+ This resulted is mainly:
56
+ * More validation
57
+ * Better documentation and
58
+ * UI/UX improvements to make sure Python Code Audit is dead simple to use for non-programmers to validate a Python package.
59
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codeaudit
3
- Version: 1.0.0
3
+ Version: 1.2.0
4
4
  Summary: Simplified static security checks for Python
5
5
  Project-URL: Documentation, https://github.com/nocomplexity/codeaudit#readme
6
6
  Project-URL: Issues, https://github.com/nocomplexity/codeaudit/issues
@@ -35,13 +35,17 @@ Description-Content-Type: text/markdown
35
35
 
36
36
  Python Code Audit - A modern Python source code analyzer based on distrust.
37
37
 
38
- Python Code Audit is a tool to find **security issues** in Python code. This static application security testing (SAST) tool has **great** features to simplify the necessary security tasks and make it fun and easy.
38
+ Python Code Audit is a tool to find **security weaknesses** in Python code. This static application security testing (SAST) tool has **great** features to simplify the necessary security tasks and make it fun and easy.
39
+
40
+
41
+ This tool is designed for anyone who uses or creates Python programs and wants to understand and mitigate potential security risks.
39
42
 
40
43
  This tool is created for:
41
- * Users of Python programs who want to known the security risks of the used Python code.
42
- * Anyone who loves to create Python programs and want to deliver Python code without vulnerabilities. So this tool is not only professional programs, but also occasional Python programmers. Creating secure software is very difficult. This program with the extensive documentation is your friendly security colleague!
43
- * Anyone who wants a simple way to get fast insight in possible security risks with Python packages or Python files.
44
+ * Python Users who want to assess the security risks in the Python code they use.
45
+ * Python Developers: Anyone, from professionals to hobbyists, who wants to deliver secure Python code.
46
+ * Security-Conscious Users: People seeking a simple, fast way to gain insight into potential security vulnerabilities within Python packages or files.
44
47
 
48
+ Creating secure software can be challenging. This tool, with its comprehensive [documentation](https://nocomplexity.com/documents/codeaudit/intro.html), acts as your helpful security colleague, making it easier to identify and address vulnerabilities.
45
49
 
46
50
  ## Features
47
51
 
@@ -59,7 +63,7 @@ Python Code Audit has the following features:
59
63
 
60
64
 
61
65
 
62
- > [!IMPORTANT]
66
+ > [!NOTE]
63
67
  > Python Code Audit uses the Python's Abstract Syntax Tree (AST) to get robust and reliable result. Using the Python AST makes contextual Vulnerability Detection possible and false positive are minimized.
64
68
 
65
69
 
@@ -71,7 +75,7 @@ pip install codeaudit
71
75
 
72
76
  or use:
73
77
 
74
- ```bash
78
+ ```console
75
79
  pip install -U codeaudit
76
80
  ```
77
81
 
@@ -103,9 +107,8 @@ Depending on the command, a directory or file name must be specified. The output
103
107
 
104
108
  Commands:
105
109
  overview Reports Complexity and statistics per Python file from a directory.
106
- directoryscan Reports potential security issues for all Python files found in a directory.
107
- filescan Reports potential security issues for a single Python file.
108
- modulescan Reports module information per file.
110
+ filescan Scans Python files or directories(packages) for vulnerabilities and reports potential issues.
111
+ modulescan Reports module vulnerability information.
109
112
  checks Creates an HTML report of all implemented security checks.
110
113
  version Prints the module version. Or use codeaudit [-v] [--v] [-version] or [--version].
111
114
 
@@ -116,7 +119,7 @@ Check https://simplifysecurity.nocomplexity.com/
116
119
 
117
120
  ## Example
118
121
 
119
- By running the `codeaudit filescan` command, detailed security information is determined for a Python file based on more than **60 validations** implemented.
122
+ By running the `codeaudit filescan` command, detailed security information is determined for a Python file based on more than **70 validations** implemented.
120
123
 
121
124
  The `codeaudit filescan` command shows all **potential** security issues that are detected in the source file in a HTML-report.
122
125
 
@@ -9,13 +9,17 @@
9
9
 
10
10
  Python Code Audit - A modern Python source code analyzer based on distrust.
11
11
 
12
- Python Code Audit is a tool to find **security issues** in Python code. This static application security testing (SAST) tool has **great** features to simplify the necessary security tasks and make it fun and easy.
12
+ Python Code Audit is a tool to find **security weaknesses** in Python code. This static application security testing (SAST) tool has **great** features to simplify the necessary security tasks and make it fun and easy.
13
+
14
+
15
+ This tool is designed for anyone who uses or creates Python programs and wants to understand and mitigate potential security risks.
13
16
 
14
17
  This tool is created for:
15
- * Users of Python programs who want to known the security risks of the used Python code.
16
- * Anyone who loves to create Python programs and want to deliver Python code without vulnerabilities. So this tool is not only professional programs, but also occasional Python programmers. Creating secure software is very difficult. This program with the extensive documentation is your friendly security colleague!
17
- * Anyone who wants a simple way to get fast insight in possible security risks with Python packages or Python files.
18
+ * Python Users who want to assess the security risks in the Python code they use.
19
+ * Python Developers: Anyone, from professionals to hobbyists, who wants to deliver secure Python code.
20
+ * Security-Conscious Users: People seeking a simple, fast way to gain insight into potential security vulnerabilities within Python packages or files.
18
21
 
22
+ Creating secure software can be challenging. This tool, with its comprehensive [documentation](https://nocomplexity.com/documents/codeaudit/intro.html), acts as your helpful security colleague, making it easier to identify and address vulnerabilities.
19
23
 
20
24
  ## Features
21
25
 
@@ -33,7 +37,7 @@ Python Code Audit has the following features:
33
37
 
34
38
 
35
39
 
36
- > [!IMPORTANT]
40
+ > [!NOTE]
37
41
  > Python Code Audit uses the Python's Abstract Syntax Tree (AST) to get robust and reliable result. Using the Python AST makes contextual Vulnerability Detection possible and false positive are minimized.
38
42
 
39
43
 
@@ -45,7 +49,7 @@ pip install codeaudit
45
49
 
46
50
  or use:
47
51
 
48
- ```bash
52
+ ```console
49
53
  pip install -U codeaudit
50
54
  ```
51
55
 
@@ -77,9 +81,8 @@ Depending on the command, a directory or file name must be specified. The output
77
81
 
78
82
  Commands:
79
83
  overview Reports Complexity and statistics per Python file from a directory.
80
- directoryscan Reports potential security issues for all Python files found in a directory.
81
- filescan Reports potential security issues for a single Python file.
82
- modulescan Reports module information per file.
84
+ filescan Scans Python files or directories(packages) for vulnerabilities and reports potential issues.
85
+ modulescan Reports module vulnerability information.
83
86
  checks Creates an HTML report of all implemented security checks.
84
87
  version Prints the module version. Or use codeaudit [-v] [--v] [-version] or [--version].
85
88
 
@@ -90,7 +93,7 @@ Check https://simplifysecurity.nocomplexity.com/
90
93
 
91
94
  ## Example
92
95
 
93
- By running the `codeaudit filescan` command, detailed security information is determined for a Python file based on more than **60 validations** implemented.
96
+ By running the `codeaudit filescan` command, detailed security information is determined for a Python file based on more than **70 validations** implemented.
94
97
 
95
98
  The `codeaudit filescan` command shows all **potential** security issues that are detected in the source file in a HTML-report.
96
99
 
@@ -15,7 +15,6 @@ To report a security issue, please use the GitHub Security Advisory ["Report a V
15
15
 
16
16
  I will send a response indicating the next steps in handling your report. After the initial reply to your report, I will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance.
17
17
 
18
- For context on Electron's security notification process, please see the Notifications section of the Security WG's Membership and Notifications Governance document.
19
18
 
20
19
  ## Learning More About Security
21
20
 
@@ -13,7 +13,7 @@
13
13
  },
14
14
  {
15
15
  "cell_type": "code",
16
- "execution_count": 1,
16
+ "execution_count": 9,
17
17
  "id": "923aba22-7103-4431-8545-ee5596efa371",
18
18
  "metadata": {},
19
19
  "outputs": [],
@@ -23,7 +23,7 @@
23
23
  },
24
24
  {
25
25
  "cell_type": "code",
26
- "execution_count": 2,
26
+ "execution_count": 10,
27
27
  "id": "057c9730-7b09-49a8-82f1-bc681d880c96",
28
28
  "metadata": {},
29
29
  "outputs": [],
@@ -33,7 +33,7 @@
33
33
  },
34
34
  {
35
35
  "cell_type": "code",
36
- "execution_count": 3,
36
+ "execution_count": 11,
37
37
  "id": "67576531-b66f-42a3-b6e4-460423ca28e0",
38
38
  "metadata": {},
39
39
  "outputs": [],
@@ -44,7 +44,7 @@
44
44
  },
45
45
  {
46
46
  "cell_type": "code",
47
- "execution_count": 4,
47
+ "execution_count": 12,
48
48
  "id": "2717fe66-9e66-4fcc-ae82-0d1ba26892c4",
49
49
  "metadata": {},
50
50
  "outputs": [],
@@ -54,19 +54,19 @@
54
54
  },
55
55
  {
56
56
  "cell_type": "code",
57
- "execution_count": 5,
57
+ "execution_count": 13,
58
58
  "id": "3f286724-0a8f-45b2-80fe-d6d061fe440a",
59
59
  "metadata": {},
60
60
  "outputs": [],
61
61
  "source": [
62
62
  "output += '% THIS FILE IS GENERATED! - Use CLIcommands.ipynb to make it better!\\n'\n",
63
- "output += '# Overview of Codeaudit commands\\n'\n",
64
- "output += f'Codeaudit commands for: {version_id}'"
63
+ "output += '# Commands Overview\\n'\n",
64
+ "output += f'Python Code Audit commands for: {version_id}'"
65
65
  ]
66
66
  },
67
67
  {
68
68
  "cell_type": "code",
69
- "execution_count": 6,
69
+ "execution_count": 14,
70
70
  "id": "693c3354-530b-4a40-a561-ed722d9bb1fa",
71
71
  "metadata": {},
72
72
  "outputs": [],
@@ -77,7 +77,7 @@
77
77
  },
78
78
  {
79
79
  "cell_type": "code",
80
- "execution_count": 7,
80
+ "execution_count": 15,
81
81
  "id": "5fa9a420-bd9a-4641-99c9-de0bcf448dbc",
82
82
  "metadata": {},
83
83
  "outputs": [],
@@ -90,19 +90,18 @@
90
90
  },
91
91
  {
92
92
  "cell_type": "code",
93
- "execution_count": 8,
93
+ "execution_count": 16,
94
94
  "id": "bf6afe56-e0f7-4fa2-a3a5-968bad11bf9c",
95
95
  "metadata": {},
96
96
  "outputs": [],
97
97
  "source": [
98
98
  "commands = { \"overview\": 'overview_report', \n",
99
99
  " \"modulescan\": 'report_module_information',\n",
100
- " \"filescan\" : 'file_scan_report',\n",
101
- " \"directoryscan\" : 'directory_scan_report',\n",
100
+ " \"filescan\" : 'scan_report', \n",
102
101
  " \"checks\" : 'report_implemented_tests',\n",
103
102
  " \"version\" : 'display_version'} \n",
104
103
  "for key, value in commands.items(): \n",
105
- " output += f'## codeaudit {key}\\n' # newlines matter when creating markdown\n",
104
+ " output += f'## Code Audit {key}\\n' # newlines matter when creating markdown\n",
106
105
  " output += '```text\\n' # raw display \n",
107
106
  " func_name = value\n",
108
107
  " output += getattr(codeaudit, func_name).__doc__\n",
@@ -114,7 +113,7 @@
114
113
  },
115
114
  {
116
115
  "cell_type": "code",
117
- "execution_count": 9,
116
+ "execution_count": 17,
118
117
  "id": "0335783c-7676-4099-94c5-c98cc8f2f205",
119
118
  "metadata": {
120
119
  "editable": true,
@@ -135,13 +134,21 @@
135
134
  },
136
135
  {
137
136
  "cell_type": "code",
138
- "execution_count": 10,
137
+ "execution_count": 18,
139
138
  "id": "4667d7ec-3727-4e2d-97b5-6f597c697ec7",
140
139
  "metadata": {},
141
140
  "outputs": [],
142
141
  "source": [
143
142
  "create_documentation_file(output)"
144
143
  ]
144
+ },
145
+ {
146
+ "cell_type": "markdown",
147
+ "id": "fd67a8f6-ed99-4f69-ab55-aad6103c7b5c",
148
+ "metadata": {},
149
+ "source": [
150
+ "## Create overview of validation commands for in documentation"
151
+ ]
145
152
  }
146
153
  ],
147
154
  "metadata": {
@@ -160,7 +167,7 @@
160
167
  "name": "python",
161
168
  "nbconvert_exporter": "python",
162
169
  "pygments_lexer": "ipython3",
163
- "version": "3.13.1"
170
+ "version": "3.13.5"
164
171
  }
165
172
  },
166
173
  "nbformat": 4,
@@ -23,7 +23,7 @@ This simple tool is designed to be simple to use and maintain.
23
23
 
24
24
  **Pull Requests are welcome!**
25
25
 
26
- When you contribute to Codeaudit, your contributions are made under the same license as the file you are working on.
26
+ When you contribute to Python Code Audit, your contributions are made under the same license as the file you are working on.
27
27
 
28
28
 
29
29
  We adopt the [Collective Code Construction Contract(C4)](https://rfc.zeromq.org/spec/42/) to streamline collaboration. C4 is meant to provide a reusable optimal collaboration model for open source software projects.
@@ -37,6 +37,16 @@ This project values respect and inclusiveness, and enforces a [Code of Conduct](
37
37
  This is an open community driven project. Contributors will be mentioned in the documentation.
38
38
  :::
39
39
 
40
+ ## Help with development
41
+
42
+ :::{admonition} Start with Code Development
43
+ :class: tip
44
+ Making code contributions to **Python Code Audit** should be fun and simple!
45
+
46
+ See the [section Development](makeitbetter) for to get a head start when making code contributions!
47
+
48
+ :::
49
+
40
50
  (CoC-label)=
41
51
  ## Code of Conduct
42
52
 
@@ -7,17 +7,19 @@ parts:
7
7
  - file: features
8
8
  - file: userguide
9
9
  sections:
10
- - file: codeauditoverview
11
- - file: directoryscan
10
+ - file: codeauditoverview
12
11
  - file: filescan
13
12
  - file: modulescan
14
13
  - file: codeauditchecks
14
+ - file: howtoscan
15
+ - file: whatissast
15
16
  - file: whysast
16
17
  - file: issues
17
18
 
18
19
 
19
20
  - caption: Security Checks
20
21
  chapters:
22
+ - file: implementedvalidations
21
23
  - file: checksinformation
22
24
  sections:
23
25
  - file: checks/assert_check
@@ -51,17 +53,23 @@ parts:
51
53
  chapters:
52
54
  #- file: astlines
53
55
  # - file: astlines2
56
+ - file: makeitbetter
54
57
  - file: complexitycheck
55
58
  - file: warnings
56
- - file: codeauditcommands
59
+ - file: codeauditcommands
57
60
  - file: changelog
58
61
 
59
62
 
63
+ - caption: API Documentation
64
+ chapters:
65
+ - file: apidocs/api_intro
66
+ sections:
67
+ - file: examples/ca_api_example_overview
68
+ - file: examples/ca_api_example_json
69
+ - file: examples/ca_api_example_basic
70
+ - file: apidocs/modules
60
71
 
61
- # - caption: API Documentation
62
- # chapters:
63
- # - file: modules
64
-
72
+
65
73
 
66
74
  - caption: About
67
75
  chapters:
@@ -70,3 +78,4 @@ parts:
70
78
  - file: sponsors
71
79
  - file: license
72
80
  - file: about
81
+
@@ -0,0 +1,19 @@
1
+ # Python Code Audit APIs
2
+
3
+ The **Python Code Audit** APIs make it easy to build your own tools and integrations, such as:
4
+
5
+
6
+ * **Reporting dashboard**: Easily create custom dashboards using the APIs. Audit scan results can be exported to a human-readable JSON file for analysis and visualization.
7
+
8
+ * **Statistical Analysis**:
9
+ Use the APIs to identify and study common Python security weaknesses across multiple packages within your organization.
10
+
11
+
12
+ * **CI/CD Integration**:
13
+ Integrate the APIs into your continuous integration and deployment pipelines — even when using remote source control systems like `GitHub.com`, `GitLab.com`, `https://codeberg.org/` or https://notabug.org/ and many others!
14
+
15
+ We’ve provided a few simple examples to demonstrate how to use the APIs effectively.
16
+
17
+
18
+ ```{tableofcontents}
19
+ ```
@@ -0,0 +1,12 @@
1
+ Code Audit Public APIs
2
+ =======================
3
+
4
+
5
+ Public Interfaces module
6
+ ------------------------
7
+
8
+ .. automodule:: codeaudit.api_interfaces
9
+ :members:
10
+ :undoc-members:
11
+ :show-inheritance:
12
+
@@ -0,0 +1,7 @@
1
+ API Reference
2
+ ==============
3
+
4
+ .. toctree::
5
+ :maxdepth: 4
6
+
7
+ codeaudit
@@ -3,7 +3,7 @@
3
3
  The Python `assert` statement itself is not insecure, but its *misuse* can lead to security vulnerabilities.
4
4
 
5
5
  :::{danger}
6
- Using `assert` can be problematic from a security perspective!
6
+ Using `assert` for checks can introduce **serious security** risks!
7
7
  :::
8
8
 
9
9
 
@@ -21,18 +21,50 @@ This means any crucial checks you rely on for security or data integrity will si
21
21
 
22
22
  * **Not for graceful error handling:** Assertions are designed to signal "this should never happen, it's a bug." They raise an `AssertionError` which typically halts the program. In a production environment, you usually want to handle anticipated errors gracefully, log them, and potentially recover or inform the user, rather than crashing the application.
23
23
 
24
- 2. Some side effects within `assert` statements can be dangerous.
24
+ 2. Dangers of Side effects in assert Statements:
25
25
 
26
- * If an `assert` statement contains code with side effects (e.g., modifying a variable, calling a function that performs an action), those side effects will also be skipped when assertions are disabled. This can lead to unexpected behavior and security gaps.
26
+ * If an assert statement contains code with side effects (e.g., modifying a variable or calling a function that performs an action), those side effects will also be skipped when assertions are disabled. For example, when running Python with the -O optimization flag. This can lead to unexpected behaviour and even security vulnerabilities.
27
27
 
28
- 3. Use assert for testing code and during development only
28
+ * If you rely on `assert` to prevent a `ZeroDivisionError` or validate user input, those checks will silently disappear in optimized environments. As a result, code may behave differently than intended, creating potential security gaps.
29
+
30
+ * Relying on assert for input validation is especially dangerous. If assertions are used to block malicious input (e.g., to prevent SQL injection or enforce type checks), an attacker could exploit the fact that these validations are stripped out in production.
31
+
32
+ * If an `assert` statement contains code with side effects (e.g., modifying a variable, calling a function that performs an action), those side effects will also be skipped when assertions are disabled. This can lead to unexpected behaviour and security gaps.
33
+
34
+ * Instead of catching an AssertionError, a program can run differently. This can have severe security consequences. E.g. if asserts are used to validate user input to prevent sql injections or user input.
35
+
36
+
37
+ ## Preventive measures
38
+
39
+
40
+ 1. Use assert for testing code and during development only!
29
41
 
30
42
  * `assert` is good to use for `pytest` or other development constructs.
31
43
 
32
44
  * `Assert` helps to find mistakes during development. But it is not a security fence to protect against external threats or a robust mechanism for handling runtime issues in a live system. For production code, especially when dealing with external inputs or critical business logic, rely on explicit `if/else` checks and robust exception handling.
33
45
 
34
46
  * `Assert` statements should in general only be used for testing and debugging purposes.
35
- `assert` statements **SHOULD** be removed when not running in debug mode (i.e. when invoking the Python command with the -O or -OO options).
47
+
48
+ `assert` statements **SHOULD** be removed when not running in debug mode. This means when invoking the Python command with the -O or -OO options.
49
+
50
+ 2. Use explicit condition checks and raise proper exceptions (e.g., `ValueError`, `TypeError`) for input validation and critical logic.
51
+
52
+ 3. **Never ever** use `assert` in production Python code for checks.
53
+
54
+ 4. The **only** safe alternative: Explicit Checks!
55
+
56
+
57
+ For production code, especially when handling external inputs or executing critical logic, always rely on explicit condition checks and robust exception handling.
58
+
59
+ :::{admonition} Instead of an assert, use standard control flow and exception raising
60
+ :class: hint
61
+
62
+ * Use if/else checks: Explicitly validate inputs and conditions.
63
+
64
+ * Raise proper exceptions: Use dedicated exceptions like `ValueError`, `TypeError`, or a custom exception to signal an issue. This provides a robust mechanism that can be caught and handled gracefully by upstream code, logging a clear error message instead of silently failing or creating a security hole.
65
+
66
+ :::
67
+
36
68
 
37
69
 
38
70
  ## Example
@@ -0,0 +1,138 @@
1
+ # Built-in Functions
2
+
3
+ Some Python built-in functions can cause severe risks.
4
+
5
+ The Python built-in functions:
6
+ * `eval`
7
+ * `exec` and
8
+ * `compile`
9
+ Should always be reviewed within the full context. By default use of this function is a **red** alert from a security perspective.
10
+
11
+ Python Code Audit checks also on Builtin that are 'hidden':
12
+
13
+ * Confusable homoglyphs like: `ℯ𝓍ℯ𝒸("print(2 + 2)")` Statements are detected.
14
+
15
+ * Obfuscating usage of builtins module calls of `eval`, `exec` and `compile` like:
16
+ ```python
17
+ import builtins
18
+ b = builtins
19
+ b.exec("2+2")
20
+ ```
21
+ Or
22
+ ```python
23
+ code_obj = d.compile('x = 5*5\nprint(x)', '<string>', 'exec')
24
+ result = d.exec(code_obj) #Input should not be obfuscated. Code Audit will detect this!
25
+ ```
26
+
27
+ ## Why check on `eval`
28
+
29
+ :::{admonition} Security risk
30
+ :class: danger
31
+ `eval()` can execute arbitrary Python code.
32
+
33
+ If the input is user-controlled or from an untrusted source, this can be exploited.
34
+ :::
35
+
36
+ So calling `eval` with user-supplied input may lead to security vulnerabilities.
37
+
38
+ The `eval` function can also be used to execute arbitrary code objects (such as those created by `compile()`).
39
+
40
+ Normal Python programs should not need to use this built-in function.
41
+
42
+
43
+ The primary security concern with Python’s built-in `eval()` is its potential to enable **Remote Code Execution (RCE)**. Passing untrusted input to `eval()` is effectively the same as letting an attacker run arbitrary Python code on your system.
44
+
45
+ Key Security Risks when using `eval`:
46
+
47
+ 1. **Arbitrary Code Execution (RCE)**
48
+
49
+ * `eval()` runs any Python code in the string it receives. If an attacker controls that string, they can execute malicious commands—stealing data, reading files, or invoking dangerous modules like `os` or `subprocess`.
50
+
51
+ 2. **Broken Sandboxing**
52
+
53
+ * Attempts to make `eval()` “safe” by restricting variables or the execution environment are unreliable. Attackers often find creative ways to escape these sandboxes and access sensitive data, functions, or the file system.
54
+
55
+ 3. **Denial of Service (DoS)**
56
+
57
+ * Even without stealing data, attackers can craft inputs that trigger infinite loops, deep recursion, or memory exhaustion. This can crash the interpreter or take down an entire service.
58
+
59
+
60
+
61
+ :::{warning}
62
+ This function is capable of executing any Python code given to it. Passing unvalidated external input (such as user input, or file contents , or API retrieved content) is a major security flaw that enables arbitrary code execution.
63
+
64
+ **Never ever not use this function on data from untrusted sources.**
65
+ :::
66
+
67
+ ## Why Check on `exec`
68
+
69
+ :::{danger}
70
+ The use of the exec() function in Python should never be permitted from a security perspective.
71
+
72
+ It can executes arbitrary code. Or be called with untrusted input. This is a direct path to a severe security compromise.
73
+ :::
74
+
75
+ This function executes arbitrary code. Calling it with user-supplied input may lead to security vulnerabilities.
76
+
77
+
78
+ Using `exec` in Python should never be tolerated from a security perspective. Key risks are:
79
+
80
+ 1. **Arbitrary Code Execution:** Executes any string as Python code; untrusted input can lead to full system compromise.
81
+ 2. **Sandboxing Fails:** Attempts to restrict execution are often bypassed.
82
+ 3. **Denial of Service:** Malicious code can cause infinite loops or memory exhaustion.
83
+ 4. **Injection Risk:** Dynamic code with user input creates exploitable injection points.
84
+ 5. **Hidden Side Effects:** Alters variables or global state unpredictably, introducing security and reliability issues.
85
+
86
+
87
+
88
+
89
+
90
+ ## Why check on `compile`
91
+
92
+ As a general rule:
93
+ * Never trust Python code that uses `compile`. Verify and understand all risks before running such a program.
94
+
95
+ Security reasons to avoid Python’s built-in `compile()`:
96
+
97
+ 1. **Arbitrary Code Execution**
98
+
99
+ * `compile()` takes raw strings and turns them into executable Python code objects. If user input is passed to it (directly or indirectly), an attacker can execute arbitrary Python code on your system.
100
+
101
+ 2. **Bypassing Sandboxing or Input Validation**
102
+
103
+ * Using `compile()` can allow malicious input to bypass normal validation layers. Even if you sanitise strings for SQL or HTML, a crafted payload compiled into Python bytecode can escape restrictions.
104
+
105
+ 3. **Denial of Service (DoS) via Resource Exhaustion**
106
+
107
+ * Large or deeply nested input passed to `compile()` can consume huge amounts of CPU, memory, or recursion depth, potentially crashing the interpreter (e.g., from complex expressions or nested structures).
108
+
109
+ 4. **Exposure of Sensitive Data**
110
+
111
+ * Once arbitrary code is compiled and run, it can access system resources, environment variables, secrets in memory, or files on disk—leading to credential leaks or other security breaches.
112
+
113
+
114
+
115
+ :::{warning}
116
+ Compiling very large or deeply nested strings into an AST object can crash the Python interpreter. This happens because Python’s AST compiler has stack depth limitations, which may be exceeded by sufficiently complex input.
117
+ :::
118
+
119
+ :::{warning}
120
+ Also the construct `ast.literal_eval` is not safe!
121
+ Using this construct can still crash the Python interpreter due to stack depth limitations in Python’s AST compiler.
122
+
123
+ [Reference](https://docs.python.org/3/library/ast.html#ast.literal_eval)
124
+ :::
125
+
126
+ ## Preventive measures
127
+
128
+ * Avoid using `eval`,`exec` and `compile`: Find a secure way by design, so rethink your design again from a security perspective. There is always a better and safer solution.
129
+
130
+
131
+
132
+ ## More information
133
+
134
+ * https://docs.python.org/3/library/functions.html#eval
135
+
136
+ * https://docs.python.org/3/library/functions.html#exec
137
+
138
+ * https://docs.python.org/3/library/functions.html#compile