• Halloween is coming! To celebrate the occasion, we dusted off a couple of old skins, and even created a brand new one (Pixel).
    To get into the festive spirit, install the Skins extension.
  • The new Python extension is now available. It allows customers to deploy and manage WSGI-based Python applications on their websites directly from Plesk.
  • The Plesk Mobile apps for iOS and Android and the Plesk Mobile Center extension have been deprecated, and are no longer available for new installations. In Plesk Obsidian 18.0.84, the Plesk Mobile Center extension will be removed from servers during the upgrade, and the Plesk Mobile apps will lose their server management features.
  • The Social Login extension has been deprecated and will be removed in Plesk Obsidian 18.0.84. After that, it will no longer be possible to log in to Plesk with a Google, Facebook, GitHub account, or with a passkey. Plesk usernames and passwords, as well as logging in with a WebPros Account, are not affected.

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