Download tasks/codeql_python_benchmark51_v2/pyvul-533cc1a8c090c7529184/patch.diff from Benchanything/checkerbench: direct link, hf CLI and curl.
- Browser
- Download file 2.66 kB
-
https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/codeql_python_benchmark51_v2/pyvul-533cc1a8c090c7529184/patch.diff
- Command line
-
hf download hf://datasets/Benchanything/checkerbench/tasks/codeql_python_benchmark51_v2/pyvul-533cc1a8c090c7529184/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/codeql_python_benchmark51_v2/pyvul-533cc1a8c090c7529184/patch.diff
2.66 kB
| diff --git a/.github/semgrep-rules/insecure-unpack-archive.yml b/.github/semgrep-rules/insecure-unpack-archive.yml | |
| new file mode 100644 | |
| index 0000000..d40f645 | |
| --- /dev/null | |
| +++ b/.github/semgrep-rules/insecure-unpack-archive.yml | |
| +rules: | |
| + - id: insecure-shutil-unpack-archive-use | |
| + message: The Python 'shutil' shutil.extract_archive is vulnerable to | |
| + arbitrary file overwrites | |
| + languages: | |
| + - python | |
| + severity: ERROR | |
| + metadata: | |
| + category: security | |
| + technology: | |
| + - python | |
| + owasp: | |
| + - A06:2017 - Security Misconfiguration | |
| + - A05:2021 - Security Misconfiguration | |
| + cwe: | |
| + - "CWE-22: Improper Limitation of a Pathname to a Restricted Directory | |
| + ('Path Traversal')" | |
| + license: Commons Clause License Condition v1.0[LGPL-2.1-only] | |
| + pattern-either: | |
| + - pattern: | | |
| + shutil.unpack_archive(...) | |
| \ No newline at end of file | |
| diff --git a/.github/workflows/semgrep.yml b/.github/workflows/semgrep.yml | |
| index e16e8ba..80320c4 100644 | |
| --- a/.github/workflows/semgrep.yml | |
| +++ b/.github/workflows/semgrep.yml | |
| jobs: | |
| - uses: actions/checkout@v3 | |
| - run: semgrep --config auto --sarif --output semgrep.sarif ./guarddog | |
| + - run: semgrep --config .github/semgrep-rules --sarif --output semgrep-custom.sarif ./guarddog | |
| - name: Upload SARIF file for GitHub Advanced Security Dashboard | |
| uses: github/codeql-action/upload-sarif@v2 | |
| with: | |
| + category: semgrep-builtin | |
| sarif_file: semgrep.sarif | |
| - if: always() | |
| + | |
| + - name: Upload SARIF file for custom Semgrep rules for GitHub Advanced Security Dashboard | |
| + uses: github/codeql-action/upload-sarif@v2 | |
| + with: | |
| + category: semgrep-custom | |
| + sarif_file: semgrep-custom.sarif | |
| + | |
| diff --git a/guarddog/scanners/package_scanner.py b/guarddog/scanners/package_scanner.py | |
| index 79f216f..0647c9a 100644 | |
| --- a/guarddog/scanners/package_scanner.py | |
| +++ b/guarddog/scanners/package_scanner.py | |
| import json | |
| import os | |
| -import shutil | |
| -import tarsafe # type: ignore | |
| +import tarsafe # type:ignore | |
| import tempfile | |
| import requests | |
| class PackageScanner(Scanner): | |
| with open(zippath, "wb") as f: | |
| f.write(response.raw.read()) | |
| - shutil.unpack_archive(zippath, unzippedpath) | |
| - os.remove(zippath) | |
| + if zippath.endswith('.tar.gz'): | |
| + tarsafe.open(zippath).extractall(unzippedpath) | |
| + os.remove(zippath) | |
| + else: | |
| + raise ValueError("unsupported archive extension: " + zippath) | |