| 
 | 1 | +# Contributor Guide  | 
 | 2 | + | 
 | 3 | +This guide provides an overview of how you can help, the standards we adhere to, and the steps to get your contributions reviewed for the subpages in [wg-best-practices-os-developers/docs/Secure-Coding-Guide-for-Python/](https://github.com/ossf/wg-best-practices-os-developers/docs/Secure-Coding-Guide-for-Python/)  | 
 | 4 | + | 
 | 5 | +## Code of Conduct  | 
 | 6 | + | 
 | 7 | +Please read and adhere to our [Code of Conduct](https://github.com/ossf/wg-best-practices-os-developers/blob/main/code-of-conduct.md). We are committed to creating a welcoming and inclusive environment for all contributors.  | 
 | 8 | + | 
 | 9 | +## Getting Started  | 
 | 10 | + | 
 | 11 | +1. __Fork the repository:__ Click the "Fork" button at the top of this page to create a copy of the repository under your GitHub account.  | 
 | 12 | + | 
 | 13 | +2. __Clone your fork:__ Use the following command to clone the repository to your local machine:  | 
 | 14 | + | 
 | 15 | +    ```bash  | 
 | 16 | +    git clone https://github.com/your-username/repo-name.git  | 
 | 17 | +    ```  | 
 | 18 | + | 
 | 19 | +3. Set up the development environment with a Python environment >= `3.9` and a `Markdown` reader.  | 
 | 20 | + | 
 | 21 | +## How to Contribute  | 
 | 22 | + | 
 | 23 | +We welcome contributions in many forms—whether it’s fixing a bug or typo, improving the readability of the guide, adding a new code example, or creating entirely new pages to cover missing material. Before you start, please check for existing issues.  | 
 | 24 | + | 
 | 25 | +Become part of the reviewers for upcoming pull requests (PRs) that are organized via:  | 
 | 26 | + | 
 | 27 | +* [OpenSSF.slack.com #secure-coding-guide-for-python #C07LH7RH8MT](https://openssf.slack.com/archives/C07LH7RH8MT)  | 
 | 28 | +* [Meeting Notes](https://docs.google.com/document/d/1JY8FREBPCUUFpuv7-4B9EjeS2MLDpel0dbG5DFWrTns/edit)  | 
 | 29 | + | 
 | 30 | +It is helpful to know:  | 
 | 31 | + | 
 | 32 | +* Why we do this, as explained in our mission statement.  | 
 | 33 | +* Our documentation style  | 
 | 34 | +* Code standards, Python and Markdown linters and such  | 
 | 35 | +* Folder, file layout and naming conventions  | 
 | 36 | + | 
 | 37 | +## Target Audience  | 
 | 38 | + | 
 | 39 | +Target audience is new designers, security researchers and anyone teaching secure coding.  | 
 | 40 | + | 
 | 41 | +### New designers  | 
 | 42 | + | 
 | 43 | +This resource provides a baseline of knowledge for self-study while learning Python. It also helps free up experienced team members by standardizing training on common secure coding practices.  | 
 | 44 | + | 
 | 45 | +### Security Researchers  | 
 | 46 | + | 
 | 47 | +The noncompliantXX.py code examples are designed to allow throwing analysis tools at them. The code is split into a 'defend' and 'attack' section via:  | 
 | 48 | + | 
 | 49 | +```py  | 
 | 50 | +...  | 
 | 51 | +#####################  | 
 | 52 | +# Trying to exploiting above code example  | 
 | 53 | +#####################  | 
 | 54 | +...  | 
 | 55 | +```  | 
 | 56 | + | 
 | 57 | +The attack section is not suitable for automated analysis and would need to be stripped or ignored.  | 
 | 58 | + | 
 | 59 | +The `compliantXX.py` code examples are not suitable for automated analysis as they address only one issue or CWE, they do NOT supply end to end secure code.  | 
 | 60 | + | 
 | 61 | +The overview table listing the most prominent CVEs allows to gain understanding of CVSS rating and blind spots in relation to EPSS frequency ratings. There is plenty that can be improved on this subject.  | 
 | 62 | + | 
 | 63 | +### Teaching secure coding  | 
 | 64 | + | 
 | 65 | +Although not specifically designed as a teaching resource, the material provided can be effectively used in educational settings.  | 
 | 66 | + | 
 | 67 | +## Mission Statement  | 
 | 68 | + | 
 | 69 | +The goal is to provide a learning resource for secure coding in `Python` that is as comprehensive as those available for `Java`, `C`, `C++`, or `Go`.  | 
 | 70 | + | 
 | 71 | +Similar to Python itself, the learning shall be as fun as possible by providing:  | 
 | 72 | + | 
 | 73 | +* Working code examples  | 
 | 74 | +* Usable in a local coding programming IDE or online either CLI or web.  | 
 | 75 | +* Independence of any specific web framework or module.  | 
 | 76 | +* Documentation free of bias towards a single commercial vendor of security tooling  | 
 | 77 | +* Short concise and way below 40+ hours of other secure coding resources for a full study.  | 
 | 78 | +* Overview table of rule vs risk rating.  | 
 | 79 | +* Evidence based approach on risk rating.  | 
 | 80 | + | 
 | 81 | +Join us to explore how this resource can become an indispensable part of your secure coding toolkit  | 
 | 82 | + | 
 | 83 | +## Documentation Style  | 
 | 84 | + | 
 | 85 | +* Bottom Line Up Front (BLUF), conclusion is in the first sentence of a rule    | 
 | 86 | +* Keep It Small and Simple (KISS)  | 
 | 87 | +* Working code examples  | 
 | 88 | +* Academic in wording whilst aiming for low word count.  | 
 | 89 | +* No fluff, "in software security it is important to be aware of ...."  | 
 | 90 | +* Use imperative "do x and y to ensure z" instead of vague wording "might want to, could be a good idea..."  | 
 | 91 | +* bibliography, follow the Harvard reference guide  | 
 | 92 | + | 
 | 93 | +A template for a rule is available here: [README_TEMPLATE.md](README_TEMPLATE.md) with inline documentation on each section.  | 
 | 94 | + | 
 | 95 | +Each rule should have:  | 
 | 96 | + | 
 | 97 | +* At least one `noncompliant01.py` demonstrating an antipattern.  | 
 | 98 | +* At least one `compliant01.py` providing a fix for the issue demonstrated in `noncompliant01.py`.  | 
 | 99 | +* Be within 20 lines of code per file.  | 
 | 100 | + | 
 | 101 | +## Structure Guide  | 
 | 102 | + | 
 | 103 | +### From a reader perspective  | 
 | 104 | + | 
 | 105 | +The guide is structed in two levels. The top level readme is to list all rules whilst also providing an idea of:  | 
 | 106 | + | 
 | 107 | +* Chapter  | 
 | 108 | +* Related risks  | 
 | 109 | +* Available automated detection  | 
 | 110 | +* Available automated correction  | 
 | 111 | + | 
 | 112 | +The sublevel has an a individual rule with a single CWE where possible.  | 
 | 113 | + | 
 | 114 | +> [!NOTE]  | 
 | 115 | +> We are aware that CWEs are not designed as 'read throughs'. Their numbering is not designed to become a step by step guide. The [Introduction to Multithreading and Multiprocessing](../Intro_to_multiprocessing_and_multithreading/readme.md) in Python is an example where we had to provide an alternative layout with three levels. Eventually we will have to shuffle the individual rules into a more suitable sequence.  | 
 | 116 | +> Same CWE number with different titles will also have to be fixed at some stage.  | 
 | 117 | + | 
 | 118 | +### From a author perspective  | 
 | 119 | + | 
 | 120 | +* Top-level folders are Pillars `CWE-1000` such as `CWE-707`  | 
 | 121 | +* Second-level folders are either a CWE of Base, Variant, or Class type representing one rule such as `CWE-89`  | 
 | 122 | +* If multiple rules match a single CWE such as `CWE-197` we create another subfolder with a two-digit number starting at `01`  | 
 | 123 | +since `00` is in the main folder.  | 
 | 124 | +* Rules without a matching CWE are stored in an incrementing placeholder `XXX-000`, `XXX-001`.  | 
 | 125 | +* Rules matching multiple CWEs to use the best matching one as a folder and list it at the top of its reference list  | 
 | 126 | + | 
 | 127 | +Example structure with mocked up data:  | 
 | 128 | + | 
 | 129 | +```bash  | 
 | 130 | +./README.md  | 
 | 131 | +./licenses/MIT.txt  | 
 | 132 | +./licenses/CC-BY-4.0.txt  | 
 | 133 | +    | 
 | 134 | +./Concepts/Multithreading_Multiprocessing.md  | 
 | 135 | +    | 
 | 136 | +# Top level using Pillar CWE-707:  | 
 | 137 | +./CWE-707/README.md  | 
 | 138 | +    | 
 | 139 | +# Second level representing a Rule is either a CWE of type Base, Variant or Class:  | 
 | 140 | +./CWE-664/CWE-197/README.md  | 
 | 141 | +./CWE-664/CWE-197/compliant01.py  | 
 | 142 | +./CWE-664/CWE-197/example01.py  | 
 | 143 | +./CWE-664/CWE-197/noncompliant01.py  | 
 | 144 | +    | 
 | 145 | +# Multiple rules matching one CWE of type Base, Variant or Class:  | 
 | 146 | +./CWE-664/CWE-197/01/README.md  | 
 | 147 | +./CWE-664/CWE-197/01/compliant01.py  | 
 | 148 | +./CWE-664/CWE-197/01/noncompliant01.py  | 
 | 149 | +    | 
 | 150 | +# Rule matching no CWE of type Base, Variant, or Class:  | 
 | 151 | +./CWE-707/XXX-000/README.md  | 
 | 152 | +./CWE-707/XXX-000/noncompliant01.py  | 
 | 153 | +./CWE-707/XXX-000/compliant01.py  | 
 | 154 | +    | 
 | 155 | +./CWE-707/XXX-001/README.md  | 
 | 156 | +./CWE-707/XXX-001/noncompliant01.py  | 
 | 157 | +./CWE-707/XXX-001/compliant01.py  | 
 | 158 | +    | 
 | 159 | +# Rule matching multiple CWEs of type Base, Variant or Class:  | 
 | 160 | +./CWE-707/CWE-117/README.md  | 
 | 161 | +./CWE-707/CWE-117/compliant01.py  | 
 | 162 | +./CWE-707/CWE-117/noncompliant01.py  | 
 | 163 | +```  | 
 | 164 | + | 
 | 165 | +## Coding Examples  | 
 | 166 | + | 
 | 167 | +Idealistically we have a `noncompliantXX.py` code matching in number the `XX` number of a `compliantXX.py` example with minimal changes between the two. The noncompliant and compliant code example's are also expected to contain the defensive code at the top while having the attacker code after the "#attempting to exploit" comment. Any code examples that do not qualify as compliant or noncompliant are named `exampleXX.py`.  | 
 | 168 | +
  | 
 | 169 | +To avoid running into linters or lighting up the programming IDE of others ensure to have the following installed:  | 
 | 170 | +
  | 
 | 171 | +* `Ruff` with enabled `flake8-bandit` plugin  | 
 | 172 | +* `GitHub` `Markdown` linter such as `markdownlint` (this is enforced via GitHub action) * `Python` type hints.  | 
 | 173 | +
  | 
 | 174 | +Linter warnings should be kept to a minimum.  | 
 | 175 | +
  | 
 | 176 | +Keep code examples as short while using simple Python, it's not about showing off python programming skills and must be kept accessible to beginners.  | 
 | 177 | + | 
 | 178 | +There is the option to add `# TODO:` instead of overloading compliant code examples with all aspects of an end to end secure solution.  | 
 | 179 | + | 
 | 180 | +## Submitting Your Contribution  | 
 | 181 | + | 
 | 182 | +1. __Create a new branch:__ Use descriptive names for branches, e.g., `pySCG-issue-123` or  `pySCG-add-logging-feature` using `git checkout -b branch-name`  | 
 | 183 | + | 
 | 184 | +2. __Make your changes:__ Commit your changes with clear and concise commit messages.  | 
 | 185 | + | 
 | 186 | +3. __Push your changes:__ Push your branch to your forked repository.  | 
 | 187 | +`git push origin branch-name`  | 
 | 188 | + | 
 | 189 | +4. __Submit a pull request:__ Go to the original repository and click on "New Pull Request". Fill out the template provided, detailing your changes and their purpose.  | 
 | 190 | + | 
 | 191 | +## Review Process  | 
 | 192 | + | 
 | 193 | +A Pull Request is expected to have approval of at least 2 reviewers. One reviewer must be part of the core team for this Python project. The second can be anyone feeling brave enough who has a GitHub account.  | 
 | 194 | + | 
 | 195 | +Once you submit a pull request:  | 
 | 196 | + | 
 | 197 | +* A project maintainer will review your submission.  | 
 | 198 | +* You may be asked to make revisions based on feedback.  | 
 | 199 | +* Once approved, your changes will be merged into the main branch.  | 
0 commit comments