TYPO3-Headless / headless

TYPO3 Headless JSON API providing content for PWA application (e.g. javaScript apps like nuxt-typo3)
https://t3headless.io
GNU General Public License v2.0
160 stars 61 forks source link

Potential JSON hardening #795

Open ohader opened 3 days ago

ohader commented 3 days ago

Describe the bug
While working with the TYPO3 Headless extension, I noticed that JSON data in some places is generated using string concatenation. This approach can occasionally result in unintended JSON structures, especially if the input data contains unexpected characters. For example, when using pages.abstract, the concatenation may lead to malformed or invalid JSON output.

To Reproduce
Steps to reproduce the behavior:

  1. Configure the TYPO3 Headless extension to use pages.abstract in the TypoScript JSON generation.
  2. Provide input data in pages.abstract containing characters like:
    >>>","example":{"unexpected":true},"end":"<<<.
  3. Observe the generated JSON output.
  4. Notice that the concatenated JSON might not produce the expected or valid structure.

Expected behavior
To ensure the JSON output is always correct and well-formed, it would be great to use programmatic methods for building JSON (e.g., serialization tools) instead of relying on string concatenation. This can help manage escaping and ensure that all data integrates seamlessly.

Additional context
The functionality is defined in this TypoScript configuration:
https://github.com/TYPO3-Headless/headless/blob/master/Configuration/TypoScript/ContentElement/MenuAbstract.typoscript#L19-L20

Using concatenation works in many cases, but there’s a risk of unintentional results when input data includes special characters or formatting. A programmatic approach to building JSON (using serialization libraries or helper functions) would make this process more robust and predictable.