mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
fix: check that imports are ZIPs (#21875)
This commit is contained in:
@@ -20,7 +20,7 @@ import logging
|
||||
from datetime import datetime
|
||||
from io import BytesIO
|
||||
from typing import Any, Dict, List, Optional
|
||||
from zipfile import ZipFile
|
||||
from zipfile import is_zipfile, ZipFile
|
||||
|
||||
from flask import request, Response, send_file
|
||||
from flask_appbuilder.api import expose, protect, rison, safe
|
||||
@@ -29,7 +29,10 @@ from marshmallow import ValidationError
|
||||
from sqlalchemy.exc import NoSuchTableError, OperationalError, SQLAlchemyError
|
||||
|
||||
from superset import app, event_logger
|
||||
from superset.commands.importers.exceptions import NoValidFilesFoundError
|
||||
from superset.commands.importers.exceptions import (
|
||||
IncorrectFormatError,
|
||||
NoValidFilesFoundError,
|
||||
)
|
||||
from superset.commands.importers.v1.utils import get_contents_from_bundle
|
||||
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
|
||||
from superset.databases.commands.create import CreateDatabaseCommand
|
||||
@@ -961,6 +964,8 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
|
||||
upload = request.files.get("formData")
|
||||
if not upload:
|
||||
return self.response_400()
|
||||
if not is_zipfile(upload):
|
||||
raise IncorrectFormatError("Not a ZIP file")
|
||||
with ZipFile(upload) as bundle:
|
||||
contents = get_contents_from_bundle(bundle)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user