codeant-ai-for-open-source[bot] commented on code in PR #39171:
URL: https://github.com/apache/superset/pull/39171#discussion_r3622522621


##########
superset/extensions/storage/api.py:
##########
@@ -0,0 +1,732 @@
+# 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.
+
+"""
+REST API for extension storage.
+
+Provides HTTP endpoints for frontend extensions to access server-side
+ephemeral storage without direct backend code.
+
+All operations are user-scoped by default. Use `?shared=true` query param
+to access shared state visible to all users.
+"""
+
+from __future__ import annotations
+
+import base64
+from typing import Any
+
+from flask import g, request
+from flask.wrappers import Response
+from flask_appbuilder.api import BaseApi, expose, protect, safe
+
+from superset.extensions.storage.codecs import DEFAULT_CODEC, get_codec, 
SAFE_CODECS
+from superset.extensions.storage.ephemeral_dao import (
+    ExtensionEphemeralDAO,
+    ExtensionEphemeralTTLInvalid,
+    ExtensionEphemeralValueTooLarge,
+)
+from superset.extensions.storage.persistent_dao import (
+    ExtensionStorageDAO,
+    ExtensionStorageKeyTooLong,
+    ExtensionStorageListPayloadTooLarge,
+    ExtensionStorageQuotaExceeded,
+    ExtensionStorageValueTooLarge,
+)
+from superset.extensions.storage.utils import get_extension_or_404, parse_ttl
+from superset.utils.decorators import transaction
+
+
+def _decoded_result_for_wire(decoded: Any) -> tuple[Any, bool]:
+    """Convert a codec-decoded value into its JSON wire representation.
+
+    JSON has no byte type, so a raw `bytes` value is base64-encoded to a
+    string for the response and flagged as such; every other value is
+    already JSON-representable as-is. Checked on the decoded value's
+    actual type, not the codec's name, so this keeps working for a codec
+    this module didn't define.
+
+    :returns: (wire_value, is_binary)
+    """
+    if isinstance(decoded, bytes):
+        return base64.b64encode(decoded).decode("ascii"), True
+    return decoded, False
+
+
+def _wire_value_for_request(value: Any, is_binary: bool) -> Any:
+    """Convert a request body's JSON `value` into a codec's input type.
+
+    `is_binary` is an explicit flag from the caller: JSON has no byte
+    type, so there is no way to tell, from the JSON `value` alone,
+    whether it is a base64 string that must be decoded to bytes before
+    being handed to the codec's `encode`, or a literal value to pass
+    through as-is. Only the caller knows which it sent.
+
+    :raises ValueError: if `is_binary` is set and `value` is not a valid
+        base64 string.
+    """
+    if is_binary:
+        return base64.b64decode(value, validate=True)
+    return value
+
+
+class ExtensionStorageRestApi(BaseApi):
+    """REST API for extension ephemeral state storage."""
+
+    allow_browser_login = True
+    route_base = "/api/v1/extensions"
+
+    def response(self, status_code: int, **kwargs: Any) -> Response:
+        """Helper method to create JSON responses."""
+        from flask import jsonify
+
+        return jsonify(kwargs), status_code
+
+    def response_404(self, message: str = "Not found") -> Response:
+        """Helper method to create 404 responses."""
+        from flask import jsonify
+
+        return jsonify({"message": message}), 404
+
+    def response_400(self, message: str) -> Response:
+        """Helper method to create 400 responses."""
+        from flask import jsonify
+
+        return jsonify({"message": message}), 400
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("GET",))
+    def get_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Get a value from ephemeral state.
+        ---
+        get:
+          summary: Get a value from ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, read from shared state visible to all users
+          responses:
+            200:
+              description: Value retrieved successfully
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      result:
+                        description: The stored value. When 'isBinary' is
+                          true, this is a base64 string that must be
+                          decoded to get the actual value.
+                      codec:
+                        type: string
+                        description: Name of the codec 'result' was encoded
+                          with, e.g. "json" (default) or "binary"
+                      isBinary:
+                        type: boolean
+                        description: Whether the stored value is binary
+                          data
+            400:
+              description: Value was stored with a codec unavailable over the 
API
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        raw = ExtensionEphemeralDAO.get_raw(extension_id, key, shared=shared)
+        if raw is None:
+            return self.response(200, result=None)
+        value, codec = raw
+        if codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Value was stored with codec '{codec}', which cannot be "
+                "read over the REST API."
+            )
+
+        result, is_binary = 
_decoded_result_for_wire(get_codec(codec).decode(value))
+        return self.response(200, result=result, codec=codec, 
isBinary=is_binary)
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("PUT",))
+    def set_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Set a value in ephemeral state.
+        ---
+        put:
+          summary: Set a value in ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, store as shared state visible to all users
+          requestBody:
+            required: true
+            content:
+              application/json:
+                schema:
+                  type: object
+                  required:
+                    - value
+                    - ttl
+                  properties:
+                    value:
+                      description: The value to store (must not exceed
+                        MAX_VALUE_SIZE bytes once encoded with 'codec').
+                        When 'isBinary' is true, this must be a base64
+                        string, decoded before being handed to 'codec'.
+                    codec:
+                      type: string
+                      description: Name of the codec used to encode 'value',
+                        e.g. "json" (default). Must be one of the codecs
+                        allowed over the REST API.
+                    isBinary:
+                      type: boolean
+                      description: Whether 'value' is binary data
+                    ttl:
+                      type: integer
+                      description: Time-to-live in seconds (must be a positive
+                        integer not exceeding MAX_TTL)
+          responses:
+            200:
+              description: Value stored successfully
+            400:
+              description: Invalid request body, or codec not allowed over the 
API
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        body = request.get_json(silent=True) or {}
+        if "value" not in body:
+            return self.response_400("Request body must contain 'value' field")
+
+        codec = body.get("codec", DEFAULT_CODEC)
+        if codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Codec '{codec}' is not allowed over the REST API."
+            )

Review Comment:
   **Suggestion:** If a client sends a non-hashable JSON value for `codec` (for 
example, an array), the membership check against `SAFE_CODECS` raises 
`TypeError` and returns a 500 instead of a controlled 400 response; validate 
that `codec` is a string before checking membership. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Ephemeral storage write can crash on malformed codec.
   - ⚠️ Harder to debug invalid codec inputs from clients.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Start Superset with this PR so `ExtensionStorageRestApi`
   (superset/extensions/storage/api.py:88) is registered.
   
   2. Authenticate as a user and issue `PUT
   /api/v1/extensions/test_publisher/test_name/storage/ephemeral/test_key` 
(route defined by
   `set_ephemeral` at lines 193–195).
   
   3. Send JSON body `{"value": "test", "codec": ["json"], "ttl": 60}` so
   `request.get_json()` (line 265) yields a list for `codec` at line 269.
   
   4. At line 270, `if codec not in SAFE_CODECS:` executes; with `SAFE_CODECS` 
defined as a
   set of codec names in superset/extensions/storage/codecs.py, Python raises 
`TypeError:
   unhashable type: 'list'`, which is not caught and surfaces as an HTTP 500 
instead of a 400
   input-validation error.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=6b81ca8f0f544acf92ae18224564c86f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=6b81ca8f0f544acf92ae18224564c86f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/extensions/storage/api.py
   **Line:** 269:273
   **Comment:**
        *Type Error: If a client sends a non-hashable JSON value for `codec` 
(for example, an array), the membership check against `SAFE_CODECS` raises 
`TypeError` and returns a 500 instead of a controlled 400 response; validate 
that `codec` is a string before checking membership.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=2d0199bd3d38d2f1bb745576f6628b331e5e0d2a2bfeadfbdc635b5fb3baf1f8&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=2d0199bd3d38d2f1bb745576f6628b331e5e0d2a2bfeadfbdc635b5fb3baf1f8&reaction=dislike'>👎</a>



##########
superset/extensions/storage/api.py:
##########
@@ -0,0 +1,732 @@
+# 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.
+
+"""
+REST API for extension storage.
+
+Provides HTTP endpoints for frontend extensions to access server-side
+ephemeral storage without direct backend code.
+
+All operations are user-scoped by default. Use `?shared=true` query param
+to access shared state visible to all users.
+"""
+
+from __future__ import annotations
+
+import base64
+from typing import Any
+
+from flask import g, request
+from flask.wrappers import Response
+from flask_appbuilder.api import BaseApi, expose, protect, safe
+
+from superset.extensions.storage.codecs import DEFAULT_CODEC, get_codec, 
SAFE_CODECS
+from superset.extensions.storage.ephemeral_dao import (
+    ExtensionEphemeralDAO,
+    ExtensionEphemeralTTLInvalid,
+    ExtensionEphemeralValueTooLarge,
+)
+from superset.extensions.storage.persistent_dao import (
+    ExtensionStorageDAO,
+    ExtensionStorageKeyTooLong,
+    ExtensionStorageListPayloadTooLarge,
+    ExtensionStorageQuotaExceeded,
+    ExtensionStorageValueTooLarge,
+)
+from superset.extensions.storage.utils import get_extension_or_404, parse_ttl
+from superset.utils.decorators import transaction
+
+
+def _decoded_result_for_wire(decoded: Any) -> tuple[Any, bool]:
+    """Convert a codec-decoded value into its JSON wire representation.
+
+    JSON has no byte type, so a raw `bytes` value is base64-encoded to a
+    string for the response and flagged as such; every other value is
+    already JSON-representable as-is. Checked on the decoded value's
+    actual type, not the codec's name, so this keeps working for a codec
+    this module didn't define.
+
+    :returns: (wire_value, is_binary)
+    """
+    if isinstance(decoded, bytes):
+        return base64.b64encode(decoded).decode("ascii"), True
+    return decoded, False
+
+
+def _wire_value_for_request(value: Any, is_binary: bool) -> Any:
+    """Convert a request body's JSON `value` into a codec's input type.
+
+    `is_binary` is an explicit flag from the caller: JSON has no byte
+    type, so there is no way to tell, from the JSON `value` alone,
+    whether it is a base64 string that must be decoded to bytes before
+    being handed to the codec's `encode`, or a literal value to pass
+    through as-is. Only the caller knows which it sent.
+
+    :raises ValueError: if `is_binary` is set and `value` is not a valid
+        base64 string.
+    """
+    if is_binary:
+        return base64.b64decode(value, validate=True)
+    return value
+
+
+class ExtensionStorageRestApi(BaseApi):
+    """REST API for extension ephemeral state storage."""
+

Review Comment:
   **Suggestion:** The class docstring says this API is only for ephemeral 
storage, but the class also implements persistent storage endpoints, which 
makes the contract misleading for maintainers and API consumers; update the 
docstring to reflect both storage tiers. [docstring mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Minor 🧹</summary>
   
   ```mdx
   - ⚠️ Docstring misleads about API supporting persistent storage.
   - ⚠️ Maintainers may misunderstand class scope and responsibilities.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open superset/extensions/storage/api.py with this PR applied.
   
   2. Locate `class ExtensionStorageRestApi(BaseApi):` at line 88 and read its 
docstring at
   line 89: "REST API for extension ephemeral state storage."
   
   3. Scroll down to see persistent storage endpoints implemented in the same 
class:
   `list_persistent` (lines 350–481), `get_persistent` (486–565), 
`set_persistent` (566–679),
   and `delete_persistent` (682–732).
   
   4. Observe that the class docstring describes only ephemeral state, which 
misrepresents
   the actual responsibilities and can mislead maintainers or API consumers 
about the scope
   of this REST API.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=786e5242c45b4202acde89c93771fef4&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=786e5242c45b4202acde89c93771fef4&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/extensions/storage/api.py
   **Line:** 88:89
   **Comment:**
        *Docstring Mismatch: The class docstring says this API is only for 
ephemeral storage, but the class also implements persistent storage endpoints, 
which makes the contract misleading for maintainers and API consumers; update 
the docstring to reflect both storage tiers.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=16b29039ac4d7e9ae311aec5a70f295ac573488af2cc42c14e37332195044ba4&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=16b29039ac4d7e9ae311aec5a70f295ac573488af2cc42c14e37332195044ba4&reaction=dislike'>👎</a>



##########
superset/extensions/storage/api.py:
##########
@@ -0,0 +1,732 @@
+# 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.
+
+"""
+REST API for extension storage.
+
+Provides HTTP endpoints for frontend extensions to access server-side
+ephemeral storage without direct backend code.
+
+All operations are user-scoped by default. Use `?shared=true` query param
+to access shared state visible to all users.
+"""
+
+from __future__ import annotations
+
+import base64
+from typing import Any
+
+from flask import g, request
+from flask.wrappers import Response
+from flask_appbuilder.api import BaseApi, expose, protect, safe
+
+from superset.extensions.storage.codecs import DEFAULT_CODEC, get_codec, 
SAFE_CODECS
+from superset.extensions.storage.ephemeral_dao import (
+    ExtensionEphemeralDAO,
+    ExtensionEphemeralTTLInvalid,
+    ExtensionEphemeralValueTooLarge,
+)
+from superset.extensions.storage.persistent_dao import (
+    ExtensionStorageDAO,
+    ExtensionStorageKeyTooLong,
+    ExtensionStorageListPayloadTooLarge,
+    ExtensionStorageQuotaExceeded,
+    ExtensionStorageValueTooLarge,
+)
+from superset.extensions.storage.utils import get_extension_or_404, parse_ttl
+from superset.utils.decorators import transaction
+
+
+def _decoded_result_for_wire(decoded: Any) -> tuple[Any, bool]:
+    """Convert a codec-decoded value into its JSON wire representation.
+
+    JSON has no byte type, so a raw `bytes` value is base64-encoded to a
+    string for the response and flagged as such; every other value is
+    already JSON-representable as-is. Checked on the decoded value's
+    actual type, not the codec's name, so this keeps working for a codec
+    this module didn't define.
+
+    :returns: (wire_value, is_binary)
+    """
+    if isinstance(decoded, bytes):
+        return base64.b64encode(decoded).decode("ascii"), True
+    return decoded, False
+
+
+def _wire_value_for_request(value: Any, is_binary: bool) -> Any:
+    """Convert a request body's JSON `value` into a codec's input type.
+
+    `is_binary` is an explicit flag from the caller: JSON has no byte
+    type, so there is no way to tell, from the JSON `value` alone,
+    whether it is a base64 string that must be decoded to bytes before
+    being handed to the codec's `encode`, or a literal value to pass
+    through as-is. Only the caller knows which it sent.
+
+    :raises ValueError: if `is_binary` is set and `value` is not a valid
+        base64 string.
+    """
+    if is_binary:
+        return base64.b64decode(value, validate=True)
+    return value
+
+
+class ExtensionStorageRestApi(BaseApi):
+    """REST API for extension ephemeral state storage."""
+
+    allow_browser_login = True
+    route_base = "/api/v1/extensions"
+
+    def response(self, status_code: int, **kwargs: Any) -> Response:
+        """Helper method to create JSON responses."""
+        from flask import jsonify
+
+        return jsonify(kwargs), status_code
+
+    def response_404(self, message: str = "Not found") -> Response:
+        """Helper method to create 404 responses."""
+        from flask import jsonify
+
+        return jsonify({"message": message}), 404
+
+    def response_400(self, message: str) -> Response:
+        """Helper method to create 400 responses."""
+        from flask import jsonify
+
+        return jsonify({"message": message}), 400
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("GET",))
+    def get_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Get a value from ephemeral state.
+        ---
+        get:
+          summary: Get a value from ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, read from shared state visible to all users
+          responses:
+            200:
+              description: Value retrieved successfully
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      result:
+                        description: The stored value. When 'isBinary' is
+                          true, this is a base64 string that must be
+                          decoded to get the actual value.
+                      codec:
+                        type: string
+                        description: Name of the codec 'result' was encoded
+                          with, e.g. "json" (default) or "binary"
+                      isBinary:
+                        type: boolean
+                        description: Whether the stored value is binary
+                          data
+            400:
+              description: Value was stored with a codec unavailable over the 
API
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        raw = ExtensionEphemeralDAO.get_raw(extension_id, key, shared=shared)
+        if raw is None:
+            return self.response(200, result=None)
+        value, codec = raw
+        if codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Value was stored with codec '{codec}', which cannot be "
+                "read over the REST API."
+            )
+
+        result, is_binary = 
_decoded_result_for_wire(get_codec(codec).decode(value))
+        return self.response(200, result=result, codec=codec, 
isBinary=is_binary)
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("PUT",))
+    def set_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Set a value in ephemeral state.
+        ---
+        put:
+          summary: Set a value in ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, store as shared state visible to all users
+          requestBody:
+            required: true
+            content:
+              application/json:
+                schema:
+                  type: object
+                  required:
+                    - value
+                    - ttl
+                  properties:
+                    value:
+                      description: The value to store (must not exceed
+                        MAX_VALUE_SIZE bytes once encoded with 'codec').
+                        When 'isBinary' is true, this must be a base64
+                        string, decoded before being handed to 'codec'.
+                    codec:
+                      type: string
+                      description: Name of the codec used to encode 'value',
+                        e.g. "json" (default). Must be one of the codecs
+                        allowed over the REST API.
+                    isBinary:
+                      type: boolean
+                      description: Whether 'value' is binary data
+                    ttl:
+                      type: integer
+                      description: Time-to-live in seconds (must be a positive
+                        integer not exceeding MAX_TTL)
+          responses:
+            200:
+              description: Value stored successfully
+            400:
+              description: Invalid request body, or codec not allowed over the 
API
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        body = request.get_json(silent=True) or {}
+        if "value" not in body:
+            return self.response_400("Request body must contain 'value' field")
+
+        codec = body.get("codec", DEFAULT_CODEC)
+        if codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Codec '{codec}' is not allowed over the REST API."
+            )
+
+        is_binary = bool(body.get("isBinary", False))
+        try:
+            value = _wire_value_for_request(body["value"], is_binary)
+        except (ValueError, TypeError):
+            return self.response_400(
+                "Value must be a valid base64 string when 'isBinary' is true."
+            )
+        ttl, error = parse_ttl(body)
+        if error:
+            return self.response_400(error)
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        try:
+            ExtensionEphemeralDAO.set(
+                extension_id, key, value, ttl, codec=codec, shared=shared
+            )
+        except (ExtensionEphemeralTTLInvalid, ExtensionEphemeralValueTooLarge) 
as ex:
+            return self.response_400(ex.message)
+
+        return self.response(200, message="Value stored successfully")
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("DELETE",))
+    def delete_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Delete a value from ephemeral state.
+        ---
+        delete:
+          summary: Delete a value from ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, delete from shared state
+          responses:
+            200:
+              description: Value deleted successfully
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        ExtensionEphemeralDAO.delete(extension_id, key, shared=shared)
+
+        return self.response(200, message="Value deleted successfully")
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/persistent", methods=("GET",))
+    def list_persistent(self, publisher: str, name: str, **kwargs: Any) -> 
Response:
+        """List entries in persistent state.
+        ---
+        get:
+          summary: List entries in persistent state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, list shared state visible to all users
+          - in: query
+            name: resource_type
+            schema:
+              type: string
+            required: false
+            description: Filter by resource type
+          - in: query
+            name: resource_uuid
+            schema:
+              type: string
+            required: false
+            description: Filter by resource UUID (requires resource_type)
+          - in: query
+            name: page
+            schema:
+              type: integer
+            required: false
+            description: Zero-indexed page number. Defaults to 0.
+          - in: query
+            name: page_size
+            schema:
+              type: integer
+            required: false
+            description: Number of entries per page. Defaults to 10. There
+              is no fixed ceiling, but a page whose combined value size
+              exceeds MAX_LIST_PAYLOAD_SIZE is rejected — reduce page_size
+              and retry if that happens.
+          responses:
+            200:
+              description: Entries retrieved successfully
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      result:
+                        type: array
+                        items:
+                          type: object
+                          properties:
+                            key:
+                              type: string
+                            value:
+                              description: The stored value, or null if its
+                                codec cannot be read over the REST API.
+                                When 'isBinary' is true, this is a base64
+                                string that must be decoded to get the
+                                actual value.
+                            codec:
+                              type: string
+                            isBinary:
+                              type: boolean
+                              description: Whether the stored value is
+                                binary data
+                      count:
+                        type: integer
+                        description: Total number of entries matching the
+                          given scope/filters, across all pages
+            400:
+              description: The requested page's combined value size exceeds
+                MAX_LIST_PAYLOAD_SIZE
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        user_fk = None if shared else g.user.id
+        resource_type = request.args.get("resource_type")
+        resource_uuid = request.args.get("resource_uuid")
+        try:
+            page = int(request.args.get("page", 0))
+            page_size = int(request.args.get("page_size", 10))
+        except (TypeError, ValueError):
+            return self.response_400("'page' and 'page_size' must be integers")

Review Comment:
   **Suggestion:** `page` and `page_size` are only parsed as integers but not 
validated for non-negative/positive bounds, so negative values can propagate to 
DAO pagination and cause backend query errors or incorrect paging behavior; 
enforce valid ranges before calling the DAO. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Negative paging can produce incorrect or failing queries.
   - ⚠️ Malicious clients can stress storage listing behavior.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Start Superset with this PR so `list_persistent` is exposed
   (superset/extensions/storage/api.py:350–481).
   
   2. Authenticate and call `GET
   
/api/v1/extensions/test_publisher/test_name/storage/persistent?page=-1&page_size=-5`
   (route at lines 349–350).
   
   3. In `list_persistent`, `page` and `page_size` are parsed as integers at 
lines 448–449;
   the `except` block at line 450 only rejects non-integer input, so negative 
values are
   accepted.
   
   4. These negative `page` and `page_size` values are passed unchanged to
   `ExtensionStorageDAO.list_entries` (lines 455–461 in 
superset/extensions/storage/api.py),
   where they can cause incorrect offsets, unexpected query behavior, or 
backend errors
   depending on the DAO’s pagination logic in 
superset/extensions/storage/persistent_dao.py.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=5ab2f5954f4e44a99568ce9dd6659607&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=5ab2f5954f4e44a99568ce9dd6659607&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/extensions/storage/api.py
   **Line:** 448:451
   **Comment:**
        *Logic Error: `page` and `page_size` are only parsed as integers but 
not validated for non-negative/positive bounds, so negative values can 
propagate to DAO pagination and cause backend query errors or incorrect paging 
behavior; enforce valid ranges before calling the DAO.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=1e43d6468272a07d4a4f98c9bacdd1593bc7cb68961e9cc41e2258837175e6fd&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=1e43d6468272a07d4a4f98c9bacdd1593bc7cb68961e9cc41e2258837175e6fd&reaction=dislike'>👎</a>



##########
superset/extensions/storage/api.py:
##########
@@ -0,0 +1,732 @@
+# 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.
+
+"""
+REST API for extension storage.
+
+Provides HTTP endpoints for frontend extensions to access server-side
+ephemeral storage without direct backend code.
+
+All operations are user-scoped by default. Use `?shared=true` query param
+to access shared state visible to all users.
+"""
+
+from __future__ import annotations
+
+import base64
+from typing import Any
+
+from flask import g, request
+from flask.wrappers import Response
+from flask_appbuilder.api import BaseApi, expose, protect, safe
+
+from superset.extensions.storage.codecs import DEFAULT_CODEC, get_codec, 
SAFE_CODECS
+from superset.extensions.storage.ephemeral_dao import (
+    ExtensionEphemeralDAO,
+    ExtensionEphemeralTTLInvalid,
+    ExtensionEphemeralValueTooLarge,
+)
+from superset.extensions.storage.persistent_dao import (
+    ExtensionStorageDAO,
+    ExtensionStorageKeyTooLong,
+    ExtensionStorageListPayloadTooLarge,
+    ExtensionStorageQuotaExceeded,
+    ExtensionStorageValueTooLarge,
+)
+from superset.extensions.storage.utils import get_extension_or_404, parse_ttl
+from superset.utils.decorators import transaction
+
+
+def _decoded_result_for_wire(decoded: Any) -> tuple[Any, bool]:
+    """Convert a codec-decoded value into its JSON wire representation.
+
+    JSON has no byte type, so a raw `bytes` value is base64-encoded to a
+    string for the response and flagged as such; every other value is
+    already JSON-representable as-is. Checked on the decoded value's
+    actual type, not the codec's name, so this keeps working for a codec
+    this module didn't define.
+
+    :returns: (wire_value, is_binary)
+    """
+    if isinstance(decoded, bytes):
+        return base64.b64encode(decoded).decode("ascii"), True
+    return decoded, False
+
+
+def _wire_value_for_request(value: Any, is_binary: bool) -> Any:
+    """Convert a request body's JSON `value` into a codec's input type.
+
+    `is_binary` is an explicit flag from the caller: JSON has no byte
+    type, so there is no way to tell, from the JSON `value` alone,
+    whether it is a base64 string that must be decoded to bytes before
+    being handed to the codec's `encode`, or a literal value to pass
+    through as-is. Only the caller knows which it sent.
+
+    :raises ValueError: if `is_binary` is set and `value` is not a valid
+        base64 string.
+    """
+    if is_binary:
+        return base64.b64decode(value, validate=True)
+    return value
+
+
+class ExtensionStorageRestApi(BaseApi):
+    """REST API for extension ephemeral state storage."""
+
+    allow_browser_login = True
+    route_base = "/api/v1/extensions"
+
+    def response(self, status_code: int, **kwargs: Any) -> Response:
+        """Helper method to create JSON responses."""
+        from flask import jsonify
+
+        return jsonify(kwargs), status_code
+
+    def response_404(self, message: str = "Not found") -> Response:
+        """Helper method to create 404 responses."""
+        from flask import jsonify
+
+        return jsonify({"message": message}), 404
+
+    def response_400(self, message: str) -> Response:
+        """Helper method to create 400 responses."""
+        from flask import jsonify
+
+        return jsonify({"message": message}), 400
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("GET",))
+    def get_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Get a value from ephemeral state.
+        ---
+        get:
+          summary: Get a value from ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, read from shared state visible to all users
+          responses:
+            200:
+              description: Value retrieved successfully
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      result:
+                        description: The stored value. When 'isBinary' is
+                          true, this is a base64 string that must be
+                          decoded to get the actual value.
+                      codec:
+                        type: string
+                        description: Name of the codec 'result' was encoded
+                          with, e.g. "json" (default) or "binary"
+                      isBinary:
+                        type: boolean
+                        description: Whether the stored value is binary
+                          data
+            400:
+              description: Value was stored with a codec unavailable over the 
API
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        raw = ExtensionEphemeralDAO.get_raw(extension_id, key, shared=shared)
+        if raw is None:
+            return self.response(200, result=None)
+        value, codec = raw
+        if codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Value was stored with codec '{codec}', which cannot be "
+                "read over the REST API."
+            )
+
+        result, is_binary = 
_decoded_result_for_wire(get_codec(codec).decode(value))
+        return self.response(200, result=result, codec=codec, 
isBinary=is_binary)
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("PUT",))
+    def set_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Set a value in ephemeral state.
+        ---
+        put:
+          summary: Set a value in ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, store as shared state visible to all users
+          requestBody:
+            required: true
+            content:
+              application/json:
+                schema:
+                  type: object
+                  required:
+                    - value
+                    - ttl
+                  properties:
+                    value:
+                      description: The value to store (must not exceed
+                        MAX_VALUE_SIZE bytes once encoded with 'codec').
+                        When 'isBinary' is true, this must be a base64
+                        string, decoded before being handed to 'codec'.
+                    codec:
+                      type: string
+                      description: Name of the codec used to encode 'value',
+                        e.g. "json" (default). Must be one of the codecs
+                        allowed over the REST API.
+                    isBinary:
+                      type: boolean
+                      description: Whether 'value' is binary data
+                    ttl:
+                      type: integer
+                      description: Time-to-live in seconds (must be a positive
+                        integer not exceeding MAX_TTL)
+          responses:
+            200:
+              description: Value stored successfully
+            400:
+              description: Invalid request body, or codec not allowed over the 
API
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        body = request.get_json(silent=True) or {}
+        if "value" not in body:
+            return self.response_400("Request body must contain 'value' field")
+
+        codec = body.get("codec", DEFAULT_CODEC)
+        if codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Codec '{codec}' is not allowed over the REST API."
+            )
+
+        is_binary = bool(body.get("isBinary", False))
+        try:
+            value = _wire_value_for_request(body["value"], is_binary)
+        except (ValueError, TypeError):
+            return self.response_400(
+                "Value must be a valid base64 string when 'isBinary' is true."
+            )
+        ttl, error = parse_ttl(body)
+        if error:
+            return self.response_400(error)
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        try:
+            ExtensionEphemeralDAO.set(
+                extension_id, key, value, ttl, codec=codec, shared=shared
+            )
+        except (ExtensionEphemeralTTLInvalid, ExtensionEphemeralValueTooLarge) 
as ex:
+            return self.response_400(ex.message)
+
+        return self.response(200, message="Value stored successfully")
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("DELETE",))
+    def delete_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Delete a value from ephemeral state.
+        ---
+        delete:
+          summary: Delete a value from ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, delete from shared state
+          responses:
+            200:
+              description: Value deleted successfully
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        ExtensionEphemeralDAO.delete(extension_id, key, shared=shared)
+
+        return self.response(200, message="Value deleted successfully")
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/persistent", methods=("GET",))
+    def list_persistent(self, publisher: str, name: str, **kwargs: Any) -> 
Response:
+        """List entries in persistent state.
+        ---
+        get:
+          summary: List entries in persistent state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, list shared state visible to all users
+          - in: query
+            name: resource_type
+            schema:
+              type: string
+            required: false
+            description: Filter by resource type
+          - in: query
+            name: resource_uuid
+            schema:
+              type: string
+            required: false
+            description: Filter by resource UUID (requires resource_type)
+          - in: query
+            name: page
+            schema:
+              type: integer
+            required: false
+            description: Zero-indexed page number. Defaults to 0.
+          - in: query
+            name: page_size
+            schema:
+              type: integer
+            required: false
+            description: Number of entries per page. Defaults to 10. There
+              is no fixed ceiling, but a page whose combined value size
+              exceeds MAX_LIST_PAYLOAD_SIZE is rejected — reduce page_size
+              and retry if that happens.
+          responses:
+            200:
+              description: Entries retrieved successfully
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      result:
+                        type: array
+                        items:
+                          type: object
+                          properties:
+                            key:
+                              type: string
+                            value:
+                              description: The stored value, or null if its
+                                codec cannot be read over the REST API.
+                                When 'isBinary' is true, this is a base64
+                                string that must be decoded to get the
+                                actual value.
+                            codec:
+                              type: string
+                            isBinary:
+                              type: boolean
+                              description: Whether the stored value is
+                                binary data
+                      count:
+                        type: integer
+                        description: Total number of entries matching the
+                          given scope/filters, across all pages
+            400:
+              description: The requested page's combined value size exceeds
+                MAX_LIST_PAYLOAD_SIZE
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        user_fk = None if shared else g.user.id
+        resource_type = request.args.get("resource_type")
+        resource_uuid = request.args.get("resource_uuid")
+        try:
+            page = int(request.args.get("page", 0))
+            page_size = int(request.args.get("page_size", 10))
+        except (TypeError, ValueError):
+            return self.response_400("'page' and 'page_size' must be integers")
+
+        try:
+            entries, count = ExtensionStorageDAO.list_entries(
+                extension_id,
+                user_fk=user_fk,
+                resource_type=resource_type,
+                resource_uuid=resource_uuid,
+                page=page,
+                page_size=page_size,
+            )
+        except ExtensionStorageListPayloadTooLarge as ex:
+            return self.response(ex.status, message=ex.message)
+
+        result = []
+        for entry in entries:
+            value: Any = None
+            is_binary = False
+            if entry.codec in SAFE_CODECS and entry.value is not None:
+                decoded = get_codec(entry.codec).decode(entry.value)
+                value, is_binary = _decoded_result_for_wire(decoded)
+            result.append(
+                {
+                    "key": entry.key,
+                    "value": value,
+                    "codec": entry.codec,
+                    "isBinary": is_binary,
+                }
+            )
+
+        return self.response(200, result=result, count=count)
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/persistent/<key>", methods=("GET",))
+    def get_persistent(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Get a value from persistent state.
+        ---
+        get:
+          summary: Get a value from persistent state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, read from shared state visible to all users
+          responses:
+            200:
+              description: Value retrieved successfully
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      result:
+                        description: The stored value. When 'isBinary' is
+                          true, this is a base64 string that must be
+                          decoded to get the actual value.
+                      codec:
+                        type: string
+                        description: Name of the codec 'result' was encoded
+                          with, e.g. "json" (default) or "binary"
+                      isBinary:
+                        type: boolean
+                        description: Whether the stored value is binary
+                          data
+            400:
+              description: Value was stored with a codec unavailable over the 
API
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        user_fk = None if shared else g.user.id
+        entry = ExtensionStorageDAO.get(extension_id, key, user_fk=user_fk)
+        if entry is None:
+            return self.response(200, result=None)
+        if entry.codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Value was stored with codec '{entry.codec}', which cannot be 
"
+                "read over the REST API."
+            )
+
+        decoded = ExtensionStorageDAO.get_decoded_value(
+            extension_id, key, user_fk=user_fk
+        )
+        result, is_binary = _decoded_result_for_wire(decoded)
+
+        return self.response(200, result=result, codec=entry.codec, 
isBinary=is_binary)
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/persistent/<key>", methods=("PUT",))
+    @transaction()
+    def set_persistent(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Set a value in persistent state.
+        ---
+        put:
+          summary: Set a value in persistent state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, store as shared state visible to all users
+          requestBody:
+            required: true
+            content:
+              application/json:
+                schema:
+                  type: object
+                  required:
+                    - value
+                  properties:
+                    value:
+                      description: The value to store. When 'isBinary' is
+                        true, this must be a base64 string, decoded
+                        before being handed to 'codec'.
+                    codec:
+                      type: string
+                      description: Name of the codec used to encode 'value',
+                        e.g. "json" (default). Must be one of the codecs
+                        allowed over the REST API.
+                    isBinary:
+                      type: boolean
+                      description: Whether 'value' is binary data
+                    encrypt:
+                      type: boolean
+                      description: If true, the value is encrypted at rest
+          responses:
+            200:
+              description: Value stored successfully
+            400:
+              description: Invalid request body, codec not allowed over the
+                API, or value exceeds MAX_VALUE_SIZE
+            404:
+              description: Extension not found
+            413:
+              description: Extension persistent storage quota exceeded
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        body = request.get_json(silent=True) or {}
+        if "value" not in body:
+            return self.response_400("Request body must contain 'value' field")
+
+        codec = body.get("codec", DEFAULT_CODEC)
+        if codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Codec '{codec}' is not allowed over the REST API."
+            )

Review Comment:
   **Suggestion:** The same unhashable `codec` issue exists in persistent 
writes: sending a list/object for `codec` causes `TypeError` in the 
set-membership check and returns a 500; reject non-string codec values before 
checking allowed codecs. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Persistent storage write can crash on malformed codec.
   - ⚠️ Persistent API less robust to invalid client input.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Start Superset with this PR, ensuring `ExtensionStorageRestApi`
   (superset/extensions/storage/api.py:88) is loaded.
   
   2. Authenticate and call `PUT
   /api/v1/extensions/test_publisher/test_name/storage/persistent/test_key` 
(handled by
   `set_persistent` at lines 566–572).
   
   3. Use a JSON body like `{"value": "test", "codec": ["json"], "encrypt": 
false}` so
   `request.get_json()` (line 642) returns a list for `codec` at line 646.
   
   4. At line 647, `if codec not in SAFE_CODECS:` runs; since `SAFE_CODECS` is 
a set of
   allowed codec names (superset/extensions/storage/codecs.py), membership with 
a list raises
   `TypeError: unhashable type: 'list'`, which is uncaught and results in a 500 
instead of a
   400 describing the invalid codec.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f57d080065c1435c8957fe52090fa46c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=f57d080065c1435c8957fe52090fa46c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/extensions/storage/api.py
   **Line:** 646:650
   **Comment:**
        *Type Error: The same unhashable `codec` issue exists in persistent 
writes: sending a list/object for `codec` causes `TypeError` in the 
set-membership check and returns a 500; reject non-string codec values before 
checking allowed codecs.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=b1fbb15b2d99341cbc40c8ceec8112156dc9fd81be8e239721c6992b7bc0bcfd&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=b1fbb15b2d99341cbc40c8ceec8112156dc9fd81be8e239721c6992b7bc0bcfd&reaction=dislike'>👎</a>



##########
superset/extensions/storage/api.py:
##########
@@ -0,0 +1,732 @@
+# 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.
+
+"""
+REST API for extension storage.
+
+Provides HTTP endpoints for frontend extensions to access server-side
+ephemeral storage without direct backend code.
+
+All operations are user-scoped by default. Use `?shared=true` query param
+to access shared state visible to all users.
+"""
+
+from __future__ import annotations
+
+import base64
+from typing import Any
+
+from flask import g, request
+from flask.wrappers import Response
+from flask_appbuilder.api import BaseApi, expose, protect, safe
+
+from superset.extensions.storage.codecs import DEFAULT_CODEC, get_codec, 
SAFE_CODECS
+from superset.extensions.storage.ephemeral_dao import (
+    ExtensionEphemeralDAO,
+    ExtensionEphemeralTTLInvalid,
+    ExtensionEphemeralValueTooLarge,
+)
+from superset.extensions.storage.persistent_dao import (
+    ExtensionStorageDAO,
+    ExtensionStorageKeyTooLong,
+    ExtensionStorageListPayloadTooLarge,
+    ExtensionStorageQuotaExceeded,
+    ExtensionStorageValueTooLarge,
+)
+from superset.extensions.storage.utils import get_extension_or_404, parse_ttl
+from superset.utils.decorators import transaction
+
+
+def _decoded_result_for_wire(decoded: Any) -> tuple[Any, bool]:
+    """Convert a codec-decoded value into its JSON wire representation.
+
+    JSON has no byte type, so a raw `bytes` value is base64-encoded to a
+    string for the response and flagged as such; every other value is
+    already JSON-representable as-is. Checked on the decoded value's
+    actual type, not the codec's name, so this keeps working for a codec
+    this module didn't define.
+
+    :returns: (wire_value, is_binary)
+    """
+    if isinstance(decoded, bytes):
+        return base64.b64encode(decoded).decode("ascii"), True
+    return decoded, False
+
+
+def _wire_value_for_request(value: Any, is_binary: bool) -> Any:
+    """Convert a request body's JSON `value` into a codec's input type.
+
+    `is_binary` is an explicit flag from the caller: JSON has no byte
+    type, so there is no way to tell, from the JSON `value` alone,
+    whether it is a base64 string that must be decoded to bytes before
+    being handed to the codec's `encode`, or a literal value to pass
+    through as-is. Only the caller knows which it sent.
+
+    :raises ValueError: if `is_binary` is set and `value` is not a valid
+        base64 string.
+    """
+    if is_binary:
+        return base64.b64decode(value, validate=True)
+    return value
+
+
+class ExtensionStorageRestApi(BaseApi):
+    """REST API for extension ephemeral state storage."""
+
+    allow_browser_login = True
+    route_base = "/api/v1/extensions"
+
+    def response(self, status_code: int, **kwargs: Any) -> Response:
+        """Helper method to create JSON responses."""
+        from flask import jsonify
+
+        return jsonify(kwargs), status_code
+
+    def response_404(self, message: str = "Not found") -> Response:
+        """Helper method to create 404 responses."""
+        from flask import jsonify
+
+        return jsonify({"message": message}), 404
+
+    def response_400(self, message: str) -> Response:
+        """Helper method to create 400 responses."""
+        from flask import jsonify
+
+        return jsonify({"message": message}), 400
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("GET",))
+    def get_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Get a value from ephemeral state.
+        ---
+        get:
+          summary: Get a value from ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, read from shared state visible to all users
+          responses:
+            200:
+              description: Value retrieved successfully
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      result:
+                        description: The stored value. When 'isBinary' is
+                          true, this is a base64 string that must be
+                          decoded to get the actual value.
+                      codec:
+                        type: string
+                        description: Name of the codec 'result' was encoded
+                          with, e.g. "json" (default) or "binary"
+                      isBinary:
+                        type: boolean
+                        description: Whether the stored value is binary
+                          data
+            400:
+              description: Value was stored with a codec unavailable over the 
API
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        raw = ExtensionEphemeralDAO.get_raw(extension_id, key, shared=shared)
+        if raw is None:
+            return self.response(200, result=None)
+        value, codec = raw
+        if codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Value was stored with codec '{codec}', which cannot be "
+                "read over the REST API."
+            )
+
+        result, is_binary = 
_decoded_result_for_wire(get_codec(codec).decode(value))
+        return self.response(200, result=result, codec=codec, 
isBinary=is_binary)
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("PUT",))
+    def set_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Set a value in ephemeral state.
+        ---
+        put:
+          summary: Set a value in ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, store as shared state visible to all users
+          requestBody:
+            required: true
+            content:
+              application/json:
+                schema:
+                  type: object
+                  required:
+                    - value
+                    - ttl
+                  properties:
+                    value:
+                      description: The value to store (must not exceed
+                        MAX_VALUE_SIZE bytes once encoded with 'codec').
+                        When 'isBinary' is true, this must be a base64
+                        string, decoded before being handed to 'codec'.
+                    codec:
+                      type: string
+                      description: Name of the codec used to encode 'value',
+                        e.g. "json" (default). Must be one of the codecs
+                        allowed over the REST API.
+                    isBinary:
+                      type: boolean
+                      description: Whether 'value' is binary data
+                    ttl:
+                      type: integer
+                      description: Time-to-live in seconds (must be a positive
+                        integer not exceeding MAX_TTL)
+          responses:
+            200:
+              description: Value stored successfully
+            400:
+              description: Invalid request body, or codec not allowed over the 
API
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        body = request.get_json(silent=True) or {}
+        if "value" not in body:
+            return self.response_400("Request body must contain 'value' field")
+
+        codec = body.get("codec", DEFAULT_CODEC)
+        if codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Codec '{codec}' is not allowed over the REST API."
+            )
+
+        is_binary = bool(body.get("isBinary", False))
+        try:
+            value = _wire_value_for_request(body["value"], is_binary)
+        except (ValueError, TypeError):
+            return self.response_400(
+                "Value must be a valid base64 string when 'isBinary' is true."
+            )
+        ttl, error = parse_ttl(body)
+        if error:
+            return self.response_400(error)
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        try:
+            ExtensionEphemeralDAO.set(
+                extension_id, key, value, ttl, codec=codec, shared=shared
+            )
+        except (ExtensionEphemeralTTLInvalid, ExtensionEphemeralValueTooLarge) 
as ex:
+            return self.response_400(ex.message)
+
+        return self.response(200, message="Value stored successfully")
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/ephemeral/<key>", methods=("DELETE",))
+    def delete_ephemeral(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Delete a value from ephemeral state.
+        ---
+        delete:
+          summary: Delete a value from ephemeral state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, delete from shared state
+          responses:
+            200:
+              description: Value deleted successfully
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        ExtensionEphemeralDAO.delete(extension_id, key, shared=shared)
+
+        return self.response(200, message="Value deleted successfully")
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/persistent", methods=("GET",))
+    def list_persistent(self, publisher: str, name: str, **kwargs: Any) -> 
Response:
+        """List entries in persistent state.
+        ---
+        get:
+          summary: List entries in persistent state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, list shared state visible to all users
+          - in: query
+            name: resource_type
+            schema:
+              type: string
+            required: false
+            description: Filter by resource type
+          - in: query
+            name: resource_uuid
+            schema:
+              type: string
+            required: false
+            description: Filter by resource UUID (requires resource_type)
+          - in: query
+            name: page
+            schema:
+              type: integer
+            required: false
+            description: Zero-indexed page number. Defaults to 0.
+          - in: query
+            name: page_size
+            schema:
+              type: integer
+            required: false
+            description: Number of entries per page. Defaults to 10. There
+              is no fixed ceiling, but a page whose combined value size
+              exceeds MAX_LIST_PAYLOAD_SIZE is rejected — reduce page_size
+              and retry if that happens.
+          responses:
+            200:
+              description: Entries retrieved successfully
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      result:
+                        type: array
+                        items:
+                          type: object
+                          properties:
+                            key:
+                              type: string
+                            value:
+                              description: The stored value, or null if its
+                                codec cannot be read over the REST API.
+                                When 'isBinary' is true, this is a base64
+                                string that must be decoded to get the
+                                actual value.
+                            codec:
+                              type: string
+                            isBinary:
+                              type: boolean
+                              description: Whether the stored value is
+                                binary data
+                      count:
+                        type: integer
+                        description: Total number of entries matching the
+                          given scope/filters, across all pages
+            400:
+              description: The requested page's combined value size exceeds
+                MAX_LIST_PAYLOAD_SIZE
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        user_fk = None if shared else g.user.id
+        resource_type = request.args.get("resource_type")
+        resource_uuid = request.args.get("resource_uuid")
+        try:
+            page = int(request.args.get("page", 0))
+            page_size = int(request.args.get("page_size", 10))
+        except (TypeError, ValueError):
+            return self.response_400("'page' and 'page_size' must be integers")
+
+        try:
+            entries, count = ExtensionStorageDAO.list_entries(
+                extension_id,
+                user_fk=user_fk,
+                resource_type=resource_type,
+                resource_uuid=resource_uuid,
+                page=page,
+                page_size=page_size,
+            )
+        except ExtensionStorageListPayloadTooLarge as ex:
+            return self.response(ex.status, message=ex.message)
+
+        result = []
+        for entry in entries:
+            value: Any = None
+            is_binary = False
+            if entry.codec in SAFE_CODECS and entry.value is not None:
+                decoded = get_codec(entry.codec).decode(entry.value)
+                value, is_binary = _decoded_result_for_wire(decoded)
+            result.append(
+                {
+                    "key": entry.key,
+                    "value": value,
+                    "codec": entry.codec,
+                    "isBinary": is_binary,
+                }
+            )
+
+        return self.response(200, result=result, count=count)
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/persistent/<key>", methods=("GET",))
+    def get_persistent(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Get a value from persistent state.
+        ---
+        get:
+          summary: Get a value from persistent state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, read from shared state visible to all users
+          responses:
+            200:
+              description: Value retrieved successfully
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      result:
+                        description: The stored value. When 'isBinary' is
+                          true, this is a base64 string that must be
+                          decoded to get the actual value.
+                      codec:
+                        type: string
+                        description: Name of the codec 'result' was encoded
+                          with, e.g. "json" (default) or "binary"
+                      isBinary:
+                        type: boolean
+                        description: Whether the stored value is binary
+                          data
+            400:
+              description: Value was stored with a codec unavailable over the 
API
+            404:
+              description: Extension not found
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        shared = request.args.get("shared", "false").lower() == "true"
+        user_fk = None if shared else g.user.id
+        entry = ExtensionStorageDAO.get(extension_id, key, user_fk=user_fk)
+        if entry is None:
+            return self.response(200, result=None)
+        if entry.codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Value was stored with codec '{entry.codec}', which cannot be 
"
+                "read over the REST API."
+            )
+
+        decoded = ExtensionStorageDAO.get_decoded_value(
+            extension_id, key, user_fk=user_fk
+        )
+        result, is_binary = _decoded_result_for_wire(decoded)
+
+        return self.response(200, result=result, codec=entry.codec, 
isBinary=is_binary)
+
+    @protect()
+    @safe
+    @expose("/<publisher>/<name>/storage/persistent/<key>", methods=("PUT",))
+    @transaction()
+    def set_persistent(
+        self, publisher: str, name: str, key: str, **kwargs: Any
+    ) -> Response:
+        """Set a value in persistent state.
+        ---
+        put:
+          summary: Set a value in persistent state
+          parameters:
+          - in: path
+            name: publisher
+            schema:
+              type: string
+            required: true
+            description: Extension publisher
+          - in: path
+            name: name
+            schema:
+              type: string
+            required: true
+            description: Extension name
+          - in: path
+            name: key
+            schema:
+              type: string
+            required: true
+            description: Storage key
+          - in: query
+            name: shared
+            schema:
+              type: boolean
+            required: false
+            description: If true, store as shared state visible to all users
+          requestBody:
+            required: true
+            content:
+              application/json:
+                schema:
+                  type: object
+                  required:
+                    - value
+                  properties:
+                    value:
+                      description: The value to store. When 'isBinary' is
+                        true, this must be a base64 string, decoded
+                        before being handed to 'codec'.
+                    codec:
+                      type: string
+                      description: Name of the codec used to encode 'value',
+                        e.g. "json" (default). Must be one of the codecs
+                        allowed over the REST API.
+                    isBinary:
+                      type: boolean
+                      description: Whether 'value' is binary data
+                    encrypt:
+                      type: boolean
+                      description: If true, the value is encrypted at rest
+          responses:
+            200:
+              description: Value stored successfully
+            400:
+              description: Invalid request body, codec not allowed over the
+                API, or value exceeds MAX_VALUE_SIZE
+            404:
+              description: Extension not found
+            413:
+              description: Extension persistent storage quota exceeded
+        """
+        extension_id = f"{publisher}.{name}"
+        extension = get_extension_or_404(extension_id)
+        if not extension:
+            return self.response_404("Extension not found")
+
+        body = request.get_json(silent=True) or {}
+        if "value" not in body:
+            return self.response_400("Request body must contain 'value' field")
+
+        codec = body.get("codec", DEFAULT_CODEC)
+        if codec not in SAFE_CODECS:
+            return self.response_400(
+                f"Codec '{codec}' is not allowed over the REST API."
+            )
+
+        is_binary = bool(body.get("isBinary", False))
+        encrypt = bool(body.get("encrypt", False))
+        shared = request.args.get("shared", "false").lower() == "true"
+        user_fk = None if shared else g.user.id
+        try:
+            wire_value = _wire_value_for_request(body["value"], is_binary)
+        except (ValueError, TypeError):
+            return self.response_400(
+                "Value must be a valid base64 string when 'isBinary' is true."
+            )
+        value_bytes = get_codec(codec).encode(wire_value)

Review Comment:
   **Suggestion:** Encoding user-provided values is done outside the exception 
handling block, so serialization failures (for example non-JSON-serializable 
values when `codec` is `json`) will bubble up as 500 errors; catch 
encode/decode exceptions and return a 400 describing invalid payload for the 
selected codec. [possible bug]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Persistent writes can 500 on codec encoding errors.
   - ⚠️ Clients receive opaque failures for bad codec payloads.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Start Superset with this PR; confirm 
`ExtensionStorageRestApi.set_persistent` is
   available (superset/extensions/storage/api.py:566–679).
   
   2. Send `PUT 
/api/v1/extensions/test_publisher/test_name/storage/persistent/test_key` with
   JSON body that is incompatible with the chosen codec, e.g. `{"value": 
"not-bytes",
   "codec": "binary", "isBinary": false}`.
   
   3. Inside `set_persistent`, `wire_value = 
_wire_value_for_request(body["value"],
   is_binary)` is computed at lines 652–657, and then `value_bytes =
   get_codec(codec).encode(wire_value)` at line 662 calls the codec’s `encode` 
on an invalid
   type.
   
   4. The codec’s `encode` implementation (from 
superset/extensions/storage/codecs.py) raises
   an exception (e.g. `TypeError` for wrong type), which is not caught by the 
surrounding
   `try`/`except` that only wraps `ExtensionStorageDAO.set` (lines 664–677), so 
the request
   returns HTTP 500 instead of a 400 explaining the invalid payload for the 
selected codec.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=933b8e6a6e8a4475bcfcddac69a439c6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=933b8e6a6e8a4475bcfcddac69a439c6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/extensions/storage/api.py
   **Line:** 662:662
   **Comment:**
        *Possible Bug: Encoding user-provided values is done outside the 
exception handling block, so serialization failures (for example 
non-JSON-serializable values when `codec` is `json`) will bubble up as 500 
errors; catch encode/decode exceptions and return a 400 describing invalid 
payload for the selected codec.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=56003ae43da8be899976921af155eaa0c7a75bef76e48d87d2c3137bf578fe2e&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39171&comment_hash=56003ae43da8be899976921af155eaa0c7a75bef76e48d87d2c3137bf578fe2e&reaction=dislike'>👎</a>



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