Skip to content

webhook_handler: pyscript_running includes a non-serializable request and sensitive arguments #898

Closed

Description

@carferrer

With Pyscript 2.1.1, a @webhook_handler produces this Home Assistant error:

Event is not JSON serializable: <Event pyscript_running ...>:
Type is not JSON serializable: HomeAssistantRequest

The event's func_args contains the request object, webhook_id and the complete
JSON payload. If the payload contains an authentication token, that token
and the webhook identifier appear in the serialization error log.

The handler can still execute and return its normal response.

In decorator.py, the event is emitted with data.func_args before invoking
the user's function. Therefore, sanitizing logs inside that function does
not prevent this exposure.

Expected behavior:

  • Emit only serializable, non-sensitive metadata in pyscript_running.
  • Exclude request, webhook_id and payload from the public event.
  • Preserve the original arguments internally for the handler, including
    request.remote and HTTP response handling.

Converting request to a string would not resolve the exposure of the
payload and webhook identifier. Related debug and timeout logs should
also be reviewed.

Activity

  1. craigbarratt commented on Nov 18, 2026

    @craigbarratt
    Member

    Thanks for the detailed report, @carferrer. This is fixed on master and will be in the next release:

    • e104bda removes the request from the pyscript_running event, which fixes the Event is not JSON serializable error (and the log message that included the payload and webhook id).
    • keep only logbook func_args in pyscript_running event #900 (thanks @dmamelin) goes further: the event now only includes the arguments the logbook uses (trigger_type, event_type, var_name, value and trigger_time). So the webhook id and payload are no longer stored by the recorder or sent to event subscribers. Your function still receives all of its arguments, including request.
    • 6212284 makes the @webhook_handler timeout and unparsable-body warnings name the function instead of the webhook id.

    One caveat: if you turn on debug logging for pyscript, the debug messages still include full function arguments, including webhook payloads. Debug logging is opt-in and meant for troubleshooting, so we've left that as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions