Skip to content

Commit 0f36af2

Browse files
committed
added dummy 209 to allow referenceing and linking, updated template with suggested changes
Signed-off-by: Helge Wehder <[email protected]>
1 parent ac80b10 commit 0f36af2

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# CWE-209: Generation of Error Message Containing Sensitive Information
2+
3+
Dummy file to be repaced during PR <https://github.com/ossf/wg-best-practices-os-developers/pull/945>

docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-409/README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Prefabricated zip bombs and zip slip archives for testing can be found on: [[por
100100

101101
## Non-Compliant Code Example - No File Validation
102102

103-
The `noncompliant01.py` example simply extracts all the files in the archive without performing any verification. The `extractall()` method will attempt to normalize the path name. Any archive from an untrusted source should be inspected prior to extraction. There is no attempt to control where the files are extracted, which is the script current working directory.
103+
The `extractall()` method in `noncompliant01.py` will attempt to normalize the path name while making no attempt to control where the files are extracted to. The script uses the current working directory as a starting point and allows to escape the default path. Any archive from an untrusted source must be inspected prior to extraction and extracted forced below a specific path in order to prevent traversal attacks.
104104

105105
_[noncompliant01.py](noncompliant01.py):_
106106

@@ -117,13 +117,13 @@ with zipfile.ZipFile("zip_attack_test.zip", mode="r") as archive:
117117

118118
The `noncompliant01.py` code will extract any quantity of payloads. With a unmodified `example01.py` we get only `4 x 150MB` `zipbombfileX.txt`'s that are much bigger than the `0.58MB` `zip_attack_test.zip` archive.
119119

120-
The directory traversal payload will try to extract a `\Temp\zip_slip_windows.txt` for Windows and a `/tmp/zip_slip_posix.txt` for Unix based systems. Depending on the zip library in use the files may either end up in their indented target, under the same directory as the `zipbombfile.txt` files, or not at all.
120+
The directory traversal payload will try to extract a `\Temp\zip_slip_windows.txt` for Windows and a `/tmp/zip_slip_posix.txt` for Unix based systems. Depending on the zip library in use the files may either end up in their intended target, under the same directory as the `zipbombfile.txt` files, or not at all.
121121

122122
## Non-Compliant Code Example - Incorrect File Validation
123123

124124
Experiment with the code by varying the `MAXSIZE`.
125125

126-
The `noncompliant02.py` code example tries to check the file_size from the `ZipInfo` instances provided by the `infolist()` method from `ZipFile`. This information is read from the `zip` archive metadata, so it is not reliable and can be forged by an attacker. The `extract()` method will attempt to normalize the path name. Again, there is no attempt to control where the files are extracted to in order to prevent traversal attacks. The underlaying zip library may or may not prevent traversal attacks.
126+
The `noncompliant02.py` code example tries to check the `file_size` from the `ZipInfo` instances provided by the `infolist()` method from `ZipFile`. This information is read from the `zip` archive metadata, so it is not reliable and can be forged by an attacker. The `extract()` method will attempt to normalize the path name. Again, there is no attempt to control where the files are extracted to in order to prevent traversal attacks. The underlying zip library may or may not prevent traversal attacks.
127127

128128
_[noncompliant02.py](noncompliant02.py):_
129129

@@ -146,7 +146,7 @@ with zipfile.ZipFile("zip_attack_test.zip", mode="r") as archive:
146146

147147
```
148148

149-
Depending on the underlaying zip library we should see `noncompliant02.py` prevent a zip bomb but not a traversal attack.
149+
Depending on the underlying zip library we should see `noncompliant02.py` prevent a zip bomb but not a traversal attack.
150150

151151
__Example `noncompliant02.py` output:__
152152

@@ -227,7 +227,7 @@ def extract_files(filepath: str, base_path: str, exist_ok: bool = True):
227227
ZipExtractException: If there are to big files
228228
ZipExtractException: If a directory traversal is detected
229229
"""
230-
# TODO: avoid exposing sensitive data to a lesser trusted entity via errors
230+
# TODO: avoid CWE-209: Generation of Error Message Containing Sensitive Information
231231
with zipfile.ZipFile(filepath, mode="r") as archive:
232232
# limit number of files:
233233
if len(archive.infolist()) > MAXAMT:
@@ -315,10 +315,18 @@ The `compliant01.py` code will extract everything below the provided `base_path`
315315
<td><a href="http://cwe.mitre.org/">MITRE CWE</a></td>
316316
<td>Base: <a href="https://cwe.mitre.org/data/definitions/180.html">CWE-180: Incorrect behavior order: Validate before Canonicalize</a></td>
317317
</tr>
318+
<tr>
319+
<td><a href="http://cwe.mitre.org/">MITRE CWE</a></td>
320+
<td>Base: <a href="https://cwe.mitre.org/data/definitions/209.html">CWE-209: Generation of Error Message Containing Sensitive Information</a></td>
321+
</tr>
318322
<tr>
319323
<td>Secure Coding in Python</td>
320324
<td>Base: <a href="../../CWE-707/CWE-180/README.md">CWE-180: Incorrect behavior order: Validate before Canonicalize</a></td>
321325
</tr>
326+
<tr>
327+
<td>Secure Coding in Python</td>
328+
<td>Base: <a href="../../CWE-664/CWE-209/README.md">CWE-209: Generation of Error Message Containing Sensitive Information</a></td>
329+
</tr>
322330
<tr>
323331
<td><a href="https://wiki.sei.cmu.edu/confluence/display/java/SEI+CERT+Oracle+Coding+Standard+for+Java">[SEI CERT Oracle Coding Standard for Java]</a></td>
324332
<td><a href="https://wiki.sei.cmu.edu/confluence/display/java/IDS04-J.+Safely+extract+files+from+ZipInputStream">IDS04-J, Safely extract files from ZipInputStream</a></td>

docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-409/compliant01.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def extract_files(filepath: str, base_path: str, exist_ok: bool = True):
4747
ZipExtractException: If there are to big files
4848
ZipExtractException: If a directory traversal is detected
4949
"""
50-
# TODO: avoid exposing sensitive data to a lesser trusted entity via errors
50+
# TODO: avoid CWE-209: Generation of Error Message Containing Sensitive Information
5151

5252
with zipfile.ZipFile(filepath, mode="r") as archive:
5353
# limit number of files:

docs/Secure-Coding-Guide-for-Python/templates/README_TEMPLATE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Short explanation of expected outcome of running the code example, e.g. "The cod
9696
</tr>
9797
<tr>
9898
<td><a href="http://cwe.mitre.org/">MITRE CWE</a></td>
99-
<td>Base: <a href="https://cwe.mitre.org/data/definitions/1335.html">[CWE-1335: Incorrect Bitwise Shift of Integer (4.12)]</a></td>
99+
<td>Base or Class (choose which one it is based on the abstraction on the CWE page): <a href="https://cwe.mitre.org/data/definitions/1335.html">[CWE-1335: Incorrect Bitwise Shift of Integer (4.12)]</a></td>
100100
</tr>
101101
<tr>
102102
<td><a href="https://wiki.sei.cmu.edu/confluence/display/java/SEI+CERT+Oracle+Coding+Standard+for+Java">[SEI CERT Oracle Coding Standard for Java]</a></td>
@@ -120,3 +120,4 @@ Short explanation of expected outcome of running the code example, e.g. "The cod
120120
<td>CERT C Coding Standard [online]. Available from: <a href=https://www.securecoding.cert.org/confluence/display/seccode/CERT+C+Coding+Standard>https://www.securecoding.cert.org/confluence/display/seccode/CERT+C+Coding+Standard</a> [Accessed 6 May 2025]</td>
121121
</tr>
122122
</table>
123+
When writing bibliography, follow the [Harvard reference guide](https://dkit.ie.libguides.com/harvard/citing-referencing)

0 commit comments

Comments
 (0)