mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix: datasource save, improve data validation (#22038)
This commit is contained in:
committed by
AAfghahi
parent
e048c07fb5
commit
53c71eec1d
@@ -18,7 +18,7 @@ import json
|
||||
from collections import Counter
|
||||
from typing import Any
|
||||
|
||||
from flask import g, request
|
||||
from flask import current_app, g, request
|
||||
from flask_appbuilder import expose
|
||||
from flask_appbuilder.api import rison
|
||||
from flask_appbuilder.security.decorators import has_access_api
|
||||
@@ -39,6 +39,8 @@ from superset.exceptions import SupersetException, SupersetSecurityException
|
||||
from superset.extensions import security_manager
|
||||
from superset.models.core import Database
|
||||
from superset.superset_typing import FlaskResponse
|
||||
from superset.utils.core import DatasourceType
|
||||
from superset.utils.urls import is_safe_url
|
||||
from superset.views.base import (
|
||||
api,
|
||||
BaseSupersetView,
|
||||
@@ -74,8 +76,22 @@ class Datasource(BaseSupersetView):
|
||||
datasource_id = datasource_dict.get("id")
|
||||
datasource_type = datasource_dict.get("type")
|
||||
database_id = datasource_dict["database"].get("id")
|
||||
default_endpoint = datasource_dict["default_endpoint"]
|
||||
if (
|
||||
default_endpoint
|
||||
and not is_safe_url(default_endpoint)
|
||||
and current_app.config["PREVENT_UNSAFE_DEFAULT_URLS_ON_DATASET"]
|
||||
):
|
||||
return json_error_response(
|
||||
_(
|
||||
"The submitted URL is not considered safe,"
|
||||
" only use URLs with the same domain as Superset."
|
||||
),
|
||||
status=400,
|
||||
)
|
||||
|
||||
orm_datasource = ConnectorRegistry.get_datasource(
|
||||
datasource_type, datasource_id, db.session
|
||||
DatasourceType(datasource_type), datasource_id, db.session
|
||||
)
|
||||
orm_datasource.database_id = database_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user