- 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
Error observed in panel.log
Trace shows the extension trying to decode a non-JSON response:
or
The extension then throws:
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:
but Cloudflare sometimes returns:
Suggested fix
The extension should:
Why this matters
Currently this causes the entire extension to become unusable, including:
Question
Has anyone encountered this issue or is there a planned update to the Cloudflare extension to handle non-JSON API responses?
Thanks!
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
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 errorinstead of handling the response gracefully.
Cloudflare: 403 Forbidden. Invalid access token.
But this error is not handled cleanly because the extension crashes first when parsing upstream responses.
The Cloudflare extension assumes:
$responseBody = json_decode(...)but Cloudflare sometimes returns:
- HTML error pages
- plain text error codes
- timeout messages
The extension should:
- Check the response Content-Type
- Attempt JSON decoding safely
- Fall back to raw text parsing if response is not JSON
- Avoid throwing JsonException for upstream errors
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));
}
Currently this causes the entire extension to become unusable, including:
- importing DNS zones
- exporting DNS zones
- listing Cloudflare zones
Has anyone encountered this issue or is there a planned update to the Cloudflare extension to handle non-JSON API responses?