github-advanced-security[bot] commented on code in PR #58929:
URL: https://github.com/apache/airflow/pull/58929#discussion_r2580387274


##########
providers/influxdb3/src/airflow/providers/influxdb3/hooks/influxdb3.py:
##########
@@ -0,0 +1,234 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module allows to connect to an InfluxDB 3 database.
+
+InfluxDB 3.x (Core/Enterprise/Cloud Dedicated) uses SQL queries and a different
+API compared to InfluxDB 2.x. This provider is specifically designed for 
InfluxDB 3.x.
+"""
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Any
+
+try:
+    from influxdb3 import InfluxDBClient3, Point
+    INFLUXDB_CLIENT_3_AVAILABLE = True
+except ImportError:
+    try:
+        # Alternative import path
+        from influxdb_client_3 import InfluxDBClient3, Point
+        INFLUXDB_CLIENT_3_AVAILABLE = True
+    except ImportError:
+        INFLUXDB_CLIENT_3_AVAILABLE = False
+        InfluxDBClient3 = None  # type: ignore[assignment, misc]
+        Point = None  # type: ignore[assignment, misc]
+
+from airflow.providers.common.compat.sdk import BaseHook
+
+import pandas as pd
+
+if TYPE_CHECKING:
+    from airflow.models import Connection
+
+
+class InfluxDB3Hook(BaseHook):
+    """
+    Interact with InfluxDB 3.x (Core/Enterprise/Cloud Dedicated).
+
+    Performs a connection to InfluxDB 3.x and retrieves client.
+
+    :param influxdb3_conn_id: Reference to :ref:`InfluxDB 3 connection id 
<howto/connection:influxdb3>`.
+    """
+
+    conn_name_attr = "influxdb3_conn_id"
+    default_conn_name = "influxdb3_default"
+    conn_type = "influxdb3"
+    hook_name = "InfluxDB 3"
+
+    def __init__(self, conn_id: str = default_conn_name, *args, **kwargs) -> 
None:
+        super().__init__(*args, **kwargs)
+        self.influxdb3_conn_id = conn_id
+        self.connection = kwargs.pop("connection", None)
+        self.client: InfluxDBClient3 | None = None
+        self.extras: dict = {}
+        self.uri = None
+
+    @classmethod
+    def get_connection_form_widgets(cls) -> dict[str, Any]:
+        """Return connection widgets to add to connection form."""
+        from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
+        from flask_babel import lazy_gettext
+        from wtforms import StringField
+
+        return {
+            "token": StringField(lazy_gettext("Token"), 
widget=BS3TextFieldWidget(), default=""),
+            "database": StringField(
+                lazy_gettext("Database"),
+                widget=BS3TextFieldWidget(),
+                default="",
+            ),
+            "org": StringField(
+                lazy_gettext("Organization Name (optional)"),
+                widget=BS3TextFieldWidget(),
+                default="",
+            ),
+        }
+
+    def get_client(self, uri: str, kwargs: dict) -> InfluxDBClient3:
+        """Get InfluxDB 3.x client."""
+        if not INFLUXDB_CLIENT_3_AVAILABLE:
+            raise ImportError(
+                "influxdb3-python is required for InfluxDB 3.x support. "
+                "Install it with: pip install influxdb3-python"
+            )
+
+        database = kwargs.pop("database", None) or kwargs.pop("db", None)
+        if not database:
+            raise ValueError("database parameter is required for InfluxDB 3.x")
+
+        return InfluxDBClient3(
+            host=uri,
+            token=kwargs.get("token"),
+            database=database,
+            org=kwargs.get("org", ""),
+        )
+
+    def get_uri(self, conn: Connection) -> str:
+        """Build URI from connection parameters."""
+        conn_scheme = "https" if conn.schema is None else conn.schema
+        
+        # Use appropriate default port based on scheme
+        if conn.port is None:
+            conn_port = 443 if conn_scheme == "https" else 8086
+        else:
+            conn_port = conn.port
+        
+        # For InfluxDB Cloud Dedicated, if host ends with .influxdb.io and 
using HTTPS,
+        # default to port 443 if port is 8086 (common misconfiguration)
+        if (
+            conn_scheme == "https"
+            and conn.host
+            and ".influxdb.io" in conn.host.lower()

Review Comment:
   ## Incomplete URL substring sanitization
   
   The string [.influxdb.io](1) may be at an arbitrary position in the 
sanitized URL.
   
   [Show more 
details](https://github.com/apache/airflow/security/code-scanning/558)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to