Loading

Intermittent HTTP 401 Unauthorized Errors from Downstream REST APIs When Using the Mule 4 HTTP Request Connector with Cookie Management Enabled

Fecha de publicación: Oct 2, 2026
Descripción

When a Mule 4 application invokes a downstream REST API via the HTTP Request Connector, requests may intermittently fail with HTTP/1.1 401 Unauthorized — even though the Authorization header (Basic Auth, Bearer token, OAuth) is correctly supplied. The issue typically appears under sequential, high-frequency, or long-running flows (for example, polling job status after an authenticated POST) and is caused by stale session cookies being replayed from the HTTP Requester's shared cookie jar.

Product

HTTP Connector (Mule 4) / Mule Runtime Engine

Description__c

When executing HTTP POST or GET requests to any downstream REST endpoint, requests intermittently or consistently fail with:

HTTP/1.1 401 Unauthorized

Common conditions that surface the problem:

  • Sequential requests sharing a single http:request-config.
  • High-frequency / multi-threaded request bursts to the same host.
  • Follow-up GET calls (status polling, pagination, job tracking) after an initial authenticated POST.
  • Flows that run long enough for a server-side session (JSESSIONID / routing cookie) to expire while the Mule cookie jar still holds it.
  • Downstream services that mix cookie-based session state with header-based authentication (Basic Auth, Bearer, OAuth2).

The first request typically succeeds. Subsequent requests fail intermittently, often with no change to the Authorization header.



Solución

CAUSE

The Mule 4 HTTP Request Connector supports cookie management via the enableCookies attribute on http:request-config. When cookie management is active, the connector:

  1. Captures Set-Cookie headers (e.g. JSESSIONID, backend load-balancer / sticky-routing cookies) returned by the downstream service.
  2. Stores them in a cookie jar scoped to the http:request-config.
  3. Automatically replays those stored cookies on every subsequent request that uses the same configuration.

This produces 401 errors in two common ways:

  • Stale / expired session cookies. The downstream server's session (e.g. JSESSIONID) expires or is invalidated, but the connector keeps sending the cached cookie. The server treats the stale cookie as the authoritative session identity and rejects the request with 401, even though the explicit Authorization header is still valid.
  • Cookie-vs-header precedence conflict. Some APIs evaluate the inbound session cookie before the Authorization header. Once a cookie is present, the explicit credentials are effectively ignored, and any mismatch between the two authentication contexts fails the request.

A related cookie-aggregation issue during HTTP redirects was fixed under W-12161504 — see the HTTP Service Release Notes.

Enabling cookie management under heavy load has also been observed to introduce latency in HTTP responses — see KB005132594.

SOLUTION

Disable cookie management on the HTTP Request configuration so each request is stateless and relies strictly on the explicit Authorization header.

  1. Open your Mule application configuration XML in Anypoint Studio.
  2. Locate the global http:request-config element used to call the downstream REST API.
  3. Set enableCookies="false":
<http:request-config name="Downstream_API_Config" enableCookies="false" doc:name="HTTP Request configuration">
    <http:request-connection host="api.example.com" protocol="HTTPS" port="443"/>
</http:request-config>
  1. If using the Anypoint Studio graphical editor:

    a. Open the Global Elements tab. b. Select the HTTP Request Configuration for the downstream API and click Edit. c. Under Advanced (or the main Settings tab), locate Enable cookies. d. Set it to false (or clear the checkbox). e. Save and redeploy the application.

 

Recursos adicionales

Additional guidance

  • Use a dedicated http:request-config per downstream system. Do not share one configuration across unrelated APIs — a cookie set by one service should never be replayed to another.
  • If a downstream API genuinely requires cookie-based session state (e.g. login-cookie pattern), keep enableCookies="true" but isolate it to its own configuration and ensure the login flow refreshes the session before expiry.
  • Verify the fix by capturing an HTTP wire trace (or using org.mule.service.http.impl.service.HttpMessageLogger at DEBUG) and confirming no Cookie: header is sent on the second request after the change.

APPLIES TO

  • Mule Runtime Engine (all supported versions)
  • HTTP Connector (Mule 4)
  • Any integration using the Mule 4 HTTP Request Connector against a REST API that uses header-based authentication (Basic Auth, Bearer token, OAuth2) and also returns session or sticky-routing cookies
Número del artículo de conocimiento

005460939

 
Cargando
Salesforce Help | Article