shopware icon indicating copy to clipboard operation
shopware copied to clipboard

`WebhookEventMessageHandler` is ignoring custom headers defined in an App `flow-action.xml` manifest when admin worker is disabled

Open stefanpartheym opened this issue 1 year ago • 1 comments

PHP Version

8.1

Shopware Version

6.4.20.2

Expected behaviour

The request sent by WebhookEventMessageHandler should consider the headers defined in the app's flow-action.xml file:

<flow-actions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/Framework/App/FlowAction/Schema/flow-action-1.0.xsd">
  <flow-action>
    <meta>
      <name>REDACTED_VALID_NAME</name>
      <label>READCTED</label>
      <label lang="de-DE">READCTED</label>
      <url>REDACTED_VALID_URL</url>
      <sw-icon>regular-envelope</sw-icon>
      <requirements>orderAware</requirements>
    </meta>
    <headers>
      <parameter type="string" name="content-type" value="application/json" />
      <parameter type="string" name="authorization" value="{{ authType }} {{ authToken }}" />
    </headers>
    <!-- Further stuff like config, etc... -->
  </flow-action>
</flow-actions>

Actual behaviour

The request sent by WebhookEventMessageHandler only contains headers set in WebhookEventMessageHandler::__invoke. see:

Headers set on those lines are:

  • Content-Type
  • sw-version
  • sw-user-language
  • sw-context-language

But custom headers like authorization as described in the flow-action.xml file are ignored.

However, if the admin worker is enabled (enable_admin_worker: true), the webhook will be sent by the WebhookDispatcher itself synchronously, which considers all headers of the AppFlowActionEvent (see WebhookDispatcher.php line 303).

How to reproduce

Disable the admin worker:

shopware:
  admin_worker:
    enable_admin_worker: false

Create a custom App with flow action definition as described in this guide.

Customize a flow (like "Order placed") to trigger the custom flow action.

Observe the resulting records in the webhook_event_log table in column request_content, which will not contain custom headers in the headers property.

stefanpartheym avatar Dec 16 '23 14:12 stefanpartheym