Benchanything's picture
Add 300 CheckerBench tasks, dataset card, and restoration tools (part 3)
8247f19 verified
Raw History Blame Contribute Delete
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
@@ -0,0 +1,21 @@
+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
@@ -26,9 +26,17 @@ 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
@@ -1,7 +1,6 @@
import json
import os
-import shutil
-import tarsafe # type: ignore
+import tarsafe # type:ignore
import tempfile
import requests
@@ -160,5 +159,8 @@ 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)