fix: n8n's JSON-LD endpoint only overwrites plain html content elements

PUT /api/json-ld/{uid} replaced the bodytext of any content element, so a
wrong uid in n8n could wipe visible page content (text, plugins, ...).
Elements of any other CType than html are now refused with 409 before
anything is written.

The group's "Explicitly allow tt_content:CType:html" does not guard this on
its own, since the endpoint bypasses DataHandler's record access checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
frommeandClaude Opus 5.5 committed 2026-11-03 09:22:39 +01:00
1 parent 2a510339c3
commit 48f22a7787
2 files changed
+16 -7

No files matched your search

+5 -4
View File
@@ -104,8 +104,9 @@ Configuration (extension configuration `ep_products`, tab ContentFeed): `content
n8n writes the JSON-LD (SEO markup) of a content element (`EP\EpProducts\JsonLd\JsonLdApi`).
n8n is the source of truth: the element's `bodytext` is replaced with the posted object wrapped in
`<script type="application/ld+json">`, whatever the element held before. Other fields (CType,
hidden, …) are left alone; each translation is its own uid.
`<script type="application/ld+json">`, whatever the element held before. Only plain html elements
(`CType` `html`) are written, any other type is refused, so a wrong uid cannot replace visible page
content. Other fields (hidden, …) are left alone; each translation is its own uid.
- Key: `jsonLdApiKey` (extension configuration `ep_products`, tab JsonLd), only as header
`X-Api-Key`; `?key=` is not accepted.
@@ -116,8 +117,8 @@ hidden, …) are left alone; each translation is its own uid.
- `200 {"uid": 13169, "pid": 24, "changed": true}`; `changed: false` when the stored markup is
already identical (nothing written).
- `400` for invalid JSON or a scalar, `403` for a wrong or missing key, `404` for an unknown or
deleted uid, `405` for other methods, `503` when the backend user `_n8n` is missing, `500` with
`errors` when DataHandler refuses the write.
deleted uid, `405` for other methods, `409` when the element is not of type `html`, `503` when
the backend user `_n8n` is missing, `500` with `errors` when DataHandler refuses the write.
The write goes through DataHandler as the backend user `_n8n` (no password, so no login; group
`n8n` with *Tables (modify)* `tt_content` and *Explicitly allow* `tt_content:CType:html`; page
@@ -17,8 +17,10 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
* PUT /api/json-ld/{uid}: n8n replaces the JSON-LD of an html content element (SEO markup).
*
* n8n is the source of truth: the element's bodytext is overwritten with the posted object,
* whatever it held before. The write goes through DataHandler as the backend user `_n8n`, so every
* change is in the record history (and can be undone there) and the page cache is cleared.
* whatever it held before. Only plain html elements are written: a uid of any other type (text,
* plugin, …) is refused, so a wrong uid in n8n cannot replace visible page content. The write
* goes through DataHandler as the backend user `_n8n`, so every change is in the record history
* (and can be undone there) and the page cache is cleared.
*/
class JsonLdApi
{
@@ -26,6 +28,8 @@ class JsonLdApi
private const string BACKEND_USER = '_n8n';
private const string CTYPE = 'html';
// JSON_HEX_TAG: a "</script>" inside a value must not end the script element
private const int JSON_FLAGS = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_THROW_ON_ERROR;
@@ -46,13 +50,17 @@ class JsonLdApi
$uid = substr($request->getUri()->getPath(), strlen(self::PATH_PREFIX));
$record = 1 === preg_match('/^[1-9]\d*$/', $uid)
? BackendUtility::getRecord('tt_content', (int) $uid, 'uid,pid,bodytext')
? BackendUtility::getRecord('tt_content', (int) $uid, 'uid,pid,CType,bodytext')
: null;
if (null === $record) {
return new JsonResponse(['message' => 'Content element not found'], 404);
}
if (self::CTYPE !== $record['CType']) {
return new JsonResponse(['message' => 'Content element is of type "' . $record['CType'] . '", only "' . self::CTYPE . '" is written'], 409);
}
try {
// Decoded as objects, not arrays, so an empty {} stays an object
$jsonLd = json_decode((string) $request->getBody(), false, 512, JSON_THROW_ON_ERROR);