You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/06/02 02:01:49 UTC
(superset) 01/01: fix: harden ZIP safety checks and extension backend path matching
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch fix/zip-import-hardening
in repository https://gitbox.apache.org/repos/asf/superset.git
commit d2039799dec8039e6fae63fdf63053109b5a574a
Author: Claude Code <no...@anthropic.com>
AuthorDate: Mon Jun 1 19:01:28 2026 -0700
fix: harden ZIP safety checks and extension backend path matching
- check_is_safe_zip only bounded per-file size and the compression ratio. Add
a total-decompressed-size cap (ZIP_FILE_MAX_TOTAL_SIZE, default 1GB) so an
archive of many individually-allowed entries can't exhaust memory, and guard
the ratio division so an entry reporting zero compressed size raises a clean
error instead of ZeroDivisionError.
- Tighten BACKEND_REGEX to reject parent (".." ) path components in extension
backend entry names (defense in depth; check_is_safe_zip already runs first).
Add unit tests for the total-size cap and the zero-compress-size guard.
Co-Authored-By: Claude Opus 4.8 <no...@anthropic.com>
---
superset/config.py | 2 ++
superset/extensions/utils.py | 4 +++-
superset/utils/core.py | 13 +++++++++++--
tests/unit_tests/utils/test_core.py | 24 ++++++++++++++++++++++++
4 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/superset/config.py b/superset/config.py
index 2a29ce87147..d2db7865829 100644
--- a/superset/config.py
+++ b/superset/config.py
@@ -2422,6 +2422,8 @@ WELCOME_PAGE_LAST_TAB: Literal["examples", "all"] | tuple[str, list[dict[str, An
ZIPPED_FILE_MAX_SIZE = 100 * 1024 * 1024 # 100MB
# Max allowed compression ratio for a zipped file
ZIP_FILE_MAX_COMPRESS_RATIO = 200.0
+# Max allowed total decompressed size across all entries in a zipped file
+ZIP_FILE_MAX_TOTAL_SIZE = 1024 * 1024 * 1024 # 1GB
# Configuration for environment tag shown on the navbar. Setting 'text' to '' will hide the tag. # noqa: E501
# 'color' support only Ant Design semantic colors (e.g., 'error', 'warning', 'success', 'processing', 'default) # noqa: E501
diff --git a/superset/extensions/utils.py b/superset/extensions/utils.py
index 6332c97435d..7410401d2e9 100644
--- a/superset/extensions/utils.py
+++ b/superset/extensions/utils.py
@@ -36,7 +36,9 @@ from superset.utils.core import check_is_safe_zip
logger = logging.getLogger(__name__)
FRONTEND_REGEX = re.compile(r"^frontend/dist/([^/]+)$")
-BACKEND_REGEX = re.compile(r"^backend/src/(.+)$")
+# Reject parent ("..") path components so a crafted entry name cannot produce
+# a traversal-style module path (defense in depth; check_is_safe_zip runs first).
+BACKEND_REGEX = re.compile(r"^backend/src/(?!.*\.\.)(.+)$")
class InMemoryLoader(importlib.abc.Loader):
diff --git a/superset/utils/core.py b/superset/utils/core.py
index f361034e10b..bf1f2f61622 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -2107,8 +2107,17 @@ def check_is_safe_zip(zip_file: ZipFile) -> None:
raise SupersetException("Found file with size above allowed threshold")
uncompress_size += zip_file_element.file_size
compress_size += zip_file_element.compress_size
- compress_ratio = uncompress_size / compress_size
- if compress_ratio > app.config["ZIP_FILE_MAX_COMPRESS_RATIO"]:
+ # Bound the total decompressed size, not just the per-file size, so an
+ # archive of many individually-allowed entries cannot exhaust memory.
+ if uncompress_size > app.config["ZIP_FILE_MAX_TOTAL_SIZE"]:
+ raise SupersetException("Found total uncompressed size above allowed threshold")
+ # Guard the division: a zero compressed size would otherwise raise
+ # ZeroDivisionError instead of a clean error. The total-size cap above
+ # still bounds memory when compress_size is reported as zero.
+ if (
+ compress_size
+ and uncompress_size / compress_size > app.config["ZIP_FILE_MAX_COMPRESS_RATIO"]
+ ):
raise SupersetException("Zip compress ratio above allowed threshold")
diff --git a/tests/unit_tests/utils/test_core.py b/tests/unit_tests/utils/test_core.py
index 5e663dd095a..7ce2c6ace50 100644
--- a/tests/unit_tests/utils/test_core.py
+++ b/tests/unit_tests/utils/test_core.py
@@ -471,6 +471,30 @@ def test_check_if_safe_zip_hidden_bomb(app_context: None) -> None:
check_is_safe_zip(ZipFile)
+def test_check_if_safe_zip_total_size(app_context: None) -> None:
+ """Total decompressed size above the threshold is rejected even when each
+ individual entry is within the per-file limit and the ratio is low."""
+ hundred_mb = 100 * 1024 * 1024
+ ZipFile = MagicMock() # noqa: N806
+ # 11 entries x 100MB = 1.1GB total (> 1GB cap); per-file == limit, ratio 1.
+ ZipFile.infolist.return_value = [
+ MockZipInfo(file_size=hundred_mb, compress_size=hundred_mb) for _ in range(11)
+ ]
+ with pytest.raises(SupersetException):
+ check_is_safe_zip(ZipFile)
+
+
+def test_check_if_safe_zip_zero_compress_size(app_context: None) -> None:
+ """A zero compressed size must not raise ZeroDivisionError."""
+ ZipFile = MagicMock() # noqa: N806
+ ZipFile.infolist.return_value = [
+ MockZipInfo(file_size=0, compress_size=0),
+ MockZipInfo(file_size=1000, compress_size=0),
+ ]
+ # Must complete without raising (ZeroDivisionError previously).
+ check_is_safe_zip(ZipFile)
+
+
def test_generic_constraint_name_exists():
# Create a mock SQLAlchemy database object
database_mock = MagicMock()