• The APS Catalog has been deprecated and removed from all Plesk Obsidian versions.
    Applications already installed from the APS Catalog will continue working. However, Plesk will no longer provide support for APS applications.
  • Please be aware: with the Plesk Obsidian 18.0.78 release, the support for the ngx_pagespeed.so module will be deprecated and removed from the sw-nginx package.

Issue Cloudflare DNS Extension Fails with JsonException when Cloudflare returns non-JSON errors (502/524)

X3Web

New Pleskian
Server operating system version
Ubuntu 20.04
Plesk version and microupdate number
Plesk Obsidian 18.0.76.2
Hi everyone,

We are experiencing a failure with the “DNS Integration for Cloudflare” extension on Plesk Obsidian 18.0.76.

The extension appears to assume that all Cloudflare API responses are valid JSON. However Cloudflare occasionally returns plain text or HTML responses (for example 524, 502 Bad Gateway, or error text), which causes the extension to crash.

Environment

Code:
Plesk Obsidian 18.0.76.2
Ubuntu 20.04
Extension: cloudflaredns


Error observed in panel.log

Code:
Task failed: type=ext-cloudflaredns-task\importdnsfordomainnamelisttask
JsonException: Syntax error
file: /opt/psa/admin/plib/modules/cloudflaredns/library/CloudflareApi/HttpServiceApi.php
line: 54

Trace shows the extension trying to decode a non-JSON response:

Code:
json_decode('<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>

or

json_decode('error code: 524')

The extension then throws:

JsonException: Syntax error

instead of handling the response gracefully.


Additional error seen

Cloudflare: 403 Forbidden. Invalid access token.

But this error is not handled cleanly because the extension crashes first when parsing upstream responses.


Root cause

The Cloudflare extension assumes:

$responseBody = json_decode(...)

but Cloudflare sometimes returns:

  • HTML error pages
  • plain text error codes
  • timeout messages
These responses are not JSON, so json_decode() throws JsonException.


Suggested fix

The extension should:

  1. Check the response Content-Type
  2. Attempt JSON decoding safely
  3. Fall back to raw text parsing if response is not JSON
  4. Avoid throwing JsonException for upstream errors
Pseudo-fix example:

Code:
$body = (string)$response->getBody();

try {
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
return "Cloudflare API error: " . trim(strip_tags($body));
}


Why this matters

Currently this causes the entire extension to become unusable, including:

  • importing DNS zones
  • exporting DNS zones
  • listing Cloudflare zones
The UI cannot recover because the exception happens in the API wrapper.


Question

Has anyone encountered this issue or is there a planned update to the Cloudflare extension to handle non-JSON API responses?


Thanks!


 
Back
Top