rusackas commented on code in PR #40652:
URL: https://github.com/apache/superset/pull/40652#discussion_r3338271291


##########
superset/views/health.py:
##########
@@ -37,9 +37,19 @@ def health() -> FlaskResponse:
 @talisman(force_https=False)
 def version() -> FlaskResponse:
     """
-    Return comprehensive version information including Git SHA
-    and branch when available.
+    Return version information for the running Superset instance.
+
+    When ``EXPOSE_VERSION_INFO`` is True (default) this returns the full
+    version metadata, including the Git SHA and branch name when available.
+    When it is False, only the human-readable version string is returned and
+    build-specific details (Git SHA, full SHA, build number, branch name) are
+    omitted so they are not exposed to unauthenticated callers.
     """
     from superset.utils.version import get_version_metadata
 
-    return jsonify(get_version_metadata())
+    metadata = get_version_metadata()
+
+    if not app.config.get("EXPOSE_VERSION_INFO", True):
+        metadata = {"version_string": metadata.get("version_string", 
"unknown")}

Review Comment:
   The code already checks the flag first: the function returns immediately 
with just version_string when EXPOSE_VERSION_INFO is False, before ever calling 
get_version_metadata(). The call order in the latest version is: check flag → 
return early OR call get_version_metadata(). No unnecessary git subprocess 
calls occur when the feature is disabled.



##########
tests/unit_tests/views/health_version_test.py:
##########
@@ -0,0 +1,72 @@
+# 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.
+"""Unit tests for the ``/version`` endpoint and ``EXPOSE_VERSION_INFO`` 
gating."""
+
+from typing import Any
+
+from pytest_mock import MockerFixture
+
+FULL_METADATA = {
+    "version_string": "1.2.3",
+    "version_sha": "abcd1234",
+    "full_sha": "abcd1234ef567890",
+    "build_number": "42",
+    "branch_name": "master",
+}
+
+
+def test_version_exposes_full_metadata_by_default(
+    client: Any,
+    mocker: MockerFixture,
+) -> None:
+    """With EXPOSE_VERSION_INFO True (default) the full metadata is 
returned."""
+    mocker.patch(
+        "superset.utils.version.get_version_metadata",
+        return_value=dict(FULL_METADATA),
+    )
+    client.application.config["EXPOSE_VERSION_INFO"] = True
+
+    response = client.get("/version")
+    assert response.status_code == 200
+
+    body = response.get_json()
+    assert body["version_string"] == "1.2.3"
+    assert body["version_sha"] == "abcd1234"
+    assert body["full_sha"] == "abcd1234ef567890"
+    assert body["branch_name"] == "master"
+

Review Comment:
   Fair point — adding an assertion for build_number would complete the 
positive-case coverage. Will add in a follow-up.



##########
superset/views/health.py:
##########
@@ -37,9 +37,19 @@ def health() -> FlaskResponse:
 @talisman(force_https=False)
 def version() -> FlaskResponse:
     """
-    Return comprehensive version information including Git SHA
-    and branch when available.
+    Return version information for the running Superset instance.
+
+    When ``EXPOSE_VERSION_INFO`` is True (default) this returns the full
+    version metadata, including the Git SHA and branch name when available.
+    When it is False, only the human-readable version string is returned and
+    build-specific details (Git SHA, full SHA, build number, branch name) are
+    omitted so they are not exposed to unauthenticated callers.
     """
     from superset.utils.version import get_version_metadata
 
-    return jsonify(get_version_metadata())
+    metadata = get_version_metadata()
+
+    if not app.config.get("EXPOSE_VERSION_INFO", True):
+        metadata = {"version_string": metadata.get("version_string", 
"unknown")}
+

Review Comment:
   Same as codeant's comment — the flag is checked before calling 
get_version_metadata(), so the early return path never triggers the git 
subprocess. The comment appears to have been based on an earlier version of the 
code.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to