Skip to content

[🐛 Bug]: HTTP provider sends double-encoded JSON when workflow body uses {{ alert }} template #6547

Description

@ausias-armesto

Describe the bug
The HTTP provider is not handling as JSON the content pass on the body content

To Reproduce
When a workflow action uses the HTTP provider with a template like:

    - name: http-request
      provider:
        type: http
        with:
          url: "http://host:port"
          method: POST
          headers:
            Content-Type: "application/json"
          body: "{{ alert }}"

, Keep's template engine renders {{ alert }} into a JSON string (e.g. '{"id": "123", ...}'). That string is then passed to requests.post(json=body), which serialises it again — sending a JSON-encoded string (""..."") to the target endpoint instead of a JSON object ({...}). The receiving endpoint gets the wrong content type and payload shape.

Activity

  1. added
    Bug
    Provider
    on May 28, 2026
  2. dosubot commented on May 28, 2026

    @dosubot

    Thanks for the detailed report — I can confirm this is a real issue in the codebase.

    The root cause is a two-step serialization problem:

    1. Template rendering stringifies the alert: AlertDto.__str__() returns json.dumps(self.dict(), ...) [1], and the template engine (IOHandler) calls str(val) on rendered values [2]. So by the time body reaches the HTTP provider, it's already a JSON string like '{"id": "123", ...}'.

    2. HTTP provider always uses json=: The _notify() method unconditionally passes the body via requests.post(..., json=body) [3] with no type check. When body is a string, requests calls json.dumps() on it again, producing a double-encoded payload ("\"...\"") on the wire.

    A fix could check the body type before choosing the serialization strategy, e.g.:

    if isinstance(body, str):
        try:
            body = json.loads(body)  # attempt to parse back to dict
        except (json.JSONDecodeError, TypeError):
            pass
    
    if isinstance(body, dict):
        response = requests.post(url, json=body, headers=headers)
    else:
        response = requests.post(url, data=body, headers=headers)

    This is also related to #6488 , where dict-type workflow parameters containing expressions get stringified via str(val) instead of being preserved as dicts in the template rendering layer.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about keep with Dosu Add Dosu to your team

  3. added a commit that references this issue on Aug 12, 2026
    5ad6f1f
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

    BugProvider

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions