IchHabRecht / content_defender

Define allowed or denied content element types in your backend layouts
GNU General Public License v2.0
80 stars 35 forks source link

$incomingFieldArray['colPos'] is accessed before checking if it's available #107

Open magicHatOfTYPO3 opened 1 year ago

magicHatOfTYPO3 commented 1 year ago

When using PHP 8.1 the DatamapDataHandlerHook fails with an backend error message if colPos is not explicitly provided.

Core: Exception handler (WEB): Uncaught TYPO3 Exception: #1476107295: PHP Warning: Undefined array key "colPos" in /var/www/html/public/typo3conf/ext/content_defender/Classes/Hooks/DatamapDataHandlerHook.php line 51

subnoodle commented 1 year ago

Hi Nicole, i hit the same issue in your and another extension. Please see: typo3-content-defener-bug Can you tell me is the fix is already released? (Don't get a clue how to overwatch that here).

I added E_WARNING to be excluded from PHP error reporting, but that did not help: error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_WARNING

Any clue for a workarround until next release?

Thx, Sam

IchHabRecht commented 1 year ago

Hi, I would love to understand the situation and get in insight how to reproduce the problem. If anyone could tell me how to trigger the warning, I can try to fix it.

subnoodle commented 1 year ago

Hi Nicole, it's a while ago, but as far as i remember:

General problem i've got with another ext: the PHP-Warning leads to a Typo3-Exception: The current prozess stops working then. So, best is to avoid warning from the code then, i suggest.

Thank you very much for the awesome content defender!

Cheers, Thomas

IchHabRecht commented 1 year ago

Hi @subnoodle

Thank you for your answer. The problem is that I run locally an instance with complete error reporting. But I'm not able to trigger any warning. So I really need some configuration that helps me to run into the problem. I'm using the provided test fixtures (https://github.com/IchHabRecht/content_defender/tree/main/Tests/Functional/Fixtures/TSconfig/BackendLayouts) in my local system.

subnoodle commented 1 year ago

Hi Nicole, here it comes again... Screenshot 2023-01-17 Exception Content Defender

In this case, it occures whenever i add a content element, enter some content and click the save button.

The configuration is: Typo3: 11.5.22 PHP: 8.1.x

Details from Typo3's system -> log Core: Exception handler (WEB): Uncaught TYPO3 Exception: #1476107295: PHP Warning: Undefined array key "colPos" in /html/typo3/Public/typo3conf/ext/content_defender/Classes/Hooks/DatamapDataHandlerHook.php line 51 | TYPO3\CMS\Core\Error\Exception thrown in file /html/typo3/Public/typo3/sysext/core/Classes/Error/ErrorHandler.php in line 137. Requested URL: https://amer2.bs-dev.work/typo3/record/edit?token=--AnonymizedToken--&edit%5Btt_content%5D%5B313%5D=new&returnUrl=%2Ftypo3%2Fmodule%2Fweb%2Flayout%3Ftoken%3D--AnonymizedToken--%26id%3D313&defVals%5Btt_content%5D%5BCType%5D=header&defVals%5Btt_content%5D%5BcolPos%5D=0&defVals%5Btt_content%5D%5Bsys_language_uid%5D=0&route=%2Frecord%2Fedit

[SYS][belogErrorReporting] = 30711 (chaning it to 0 does not change anything)

Two backendlayouts: default.typoscript.txt subpage.typoscript.txt

(renamed for uoload only)

Worked all fine with PHP 8.0. (as far as i remember)

Some automatic typecasts are gone so far i understand possibly the problem, so invalid array keys got critical since then. Content defender is not the only extension suffering from that.

Any solution & feedback is very appreciated.

Many thanks! Thomas

subnoodle commented 1 year ago

Addition: I discoverd and fixed an error on my provided file subpage.typosript:7 and change the line from rowCount = 3 to correct value: rowCount = 2

I tought it might help, but the behavior stayed the same (after clearing cache, etc).

anderlk commented 1 year ago

Same Problem here, but only when Configuration Preset is in Debug Mode. In Live Mode there is no Problem. PHP 8.2 TYPO3 11.5.19

Bildschirmfoto 2023-01-23 um 12 01 03

Regards Andreas

IchHabRecht commented 1 year ago

Hi all,

I still don't know how to reproduce the problem. Open questions:

It seems the colPos is missing from the request but I'm unable to reproduce and understand it. I don't want to commit anything "blindly", so I need to be able to trigger the warning by myself. Any hint would be really appreciated.

anderlk commented 1 year ago

Hi Nicole, I've debugged around a bit.

In Configuration Preset "Live" there is no problem. The problem only comes up in Debug mode.

No Matter wich Role. The problem exists for Admins, too.

The PHP version seems to be decisive. With PHP 7.4 the problem does not exist. From PHP 8.0 and up it exists.

I don't know if this helps, but I use content defender in conjunction with the extension: container

But the problem is still here although I have uninstalled the container extension.

IchHabRecht commented 1 year ago

Hi @anderlk

Thank you for the further information. I'm still not able to trigger a warning with the current given information. Maybe you can give some additional help.

Furthermore: a warning isn't any "real" problem. This is why the exception is shown in debug mode only but not in live configuration. This is how TYPO3 works when notices and/or warnings (or other PHP related problems) are triggered.

anderlk commented 1 year ago

Hi Nicole, I have now installed a test system with a fresh typo3 installation with content_defender and introduction package. After the problem did not exist here, I have rebuilt piece by piece my template extension until I found the bug.

Sorry, but it was my own fault. In a completely different TSconfig file the command TCEFORM.tt_content.colPos.disabled = 1 was set.

Why this didn't work with your Extesnion, only in debug mode and how this is related to the PHP version is really a mystery to me?

Thanks for your great help, without which I would not have found the bug.

Maybe has the other reporter a similar problem. Then the bugreport can be closed by me.

Regards Andreas

IchHabRecht commented 1 year ago

@anderlk

Thank you very much for all your effort. With the additional information about the disabled colPos field I was finally able to reproduce and fix the issue!

anderlk commented 1 year ago

Hi Nicole, thanks for the Fix und your good work for this helpful Extension.

Regards Andreas

subnoodle commented 1 year ago

Hi Nicole, thank you very much for your engagement! Regards, Thomas

kitzberger commented 7 months ago

@IchHabRecht, thanks for already having looked into this issue :muscle:

But I'm afraid your solution isn't covering all cases. My scenario is:

kitzberger commented 3 weeks ago

@IchHabRecht, just stumped upon this again with a different scenario:

image

150 is fixing the issue for this btw.