1

We have one custom plugin that is used for product import. when we try to visit the page of this extension in the admin we are getting an error. check below stack trace.

1 exception(s):
Exception #0 (InvalidArgumentException): Either remote URL or hashable content is required to whitelist

Exception #0 (InvalidArgumentException): Either remote URL or hashable content is required to whitelist
<pre>#1 Magento\Csp\Helper\InlineUtil\Proxy->processTag() called at [vendor/magento/framework/View/Helper/SecureHtmlRenderer.php:66]
#2 Magento\Framework\View\Helper\SecureHtmlRenderer->renderTag() called at [vendor/magento/module-backend/Block/Widget/Form/Container.php:254]
#3 Magento\Backend\Block\Widget\Form\Container->getFormScripts() called at [vendor/magento/module-backend/view/adminhtml/templates/widget/form/container.phtml:59]
#4 include() called at [vendor/magento/framework/View/TemplateEngine/Php.php:71]
#5 Magento\Framework\View\TemplateEngine\Php->render() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#6 Magento\Framework\View\TemplateEngine\Php\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#7 Magento\Framework\View\TemplateEngine\Php\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#8 Magento\Framework\View\TemplateEngine\Php\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/TemplateEngine/Php/Interceptor.php:23]
#9 Magento\Framework\View\TemplateEngine\Php\Interceptor->render() called at [vendor/magento/framework/View/Element/Template.php:273]
#10 Magento\Framework\View\Element\Template->fetchView() called at [vendor/magento/framework/View/Element/Template.php:303]
#11 Magento\Framework\View\Element\Template->_toHtml() called at [vendor/magento/module-backend/Block/Template.php:141]
#12 Magento\Backend\Block\Template->_toHtml() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1114]
#13 Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1118]
#14 Magento\Framework\View\Element\AbstractBlock->_loadCache() called at [vendor/magento/framework/View/Element/AbstractBlock.php:678]
#15 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [vendor/magento/framework/View/Layout.php:578]
#16 Magento\Framework\View\Layout->_renderBlock() called at [vendor/magento/framework/View/Layout.php:555]
#17 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149]
#18 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#19 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140]
#20 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#21 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#22 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149]
#23 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#24 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140]
#25 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#26 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#27 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149]
#28 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#29 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140]
#30 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#31 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#32 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149]
#33 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#34 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140]
#35 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#36 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#37 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149]
#38 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#39 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140]
#40 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#41 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#42 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149]
#43 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#44 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140]
#45 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#46 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#47 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149]
#48 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#49 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140]
#50 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#51 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#52 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149]
#53 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#54 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140]
#55 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#56 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#57 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:149]
#58 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#59 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:140]
#60 Magento\Framework\View\Layout\Interceptor->renderElement() called at [vendor/magento/framework/View/Layout.php:975]
#61 Magento\Framework\View\Layout->getOutput() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:347]
#62 Magento\Framework\View\Layout\Interceptor->getOutput() called at [vendor/magento/framework/View/Result/Page.php:260]
#63 Magento\Framework\View\Result\Page->render() called at [vendor/magento/framework/View/Result/Layout.php:171]
#64 Magento\Framework\View\Result\Layout->renderResult() called at [generated/code/Magento/Backend/Model/View/Result/Page/Interceptor.php:140]
#65 Magento\Backend\Model\View\Result\Page\Interceptor->renderResult() called at [vendor/magento/framework/App/Http.php:120]
#66 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23]
#67 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:264]
#68 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:29]
</pre>

when we investigated the plugin we noticed that this error may be thrown because of one particular line that was added to the plugin code.

app/code/Vendor/Plugin/Block/Adminhtml/Import/Edit.php

$this->_formScripts[] = ""; this line is added in the constructor of the above file. check below code from the mentioned file

namespace Vendor\Plugin\Block\Adminhtml\Import;

class Edit extends \Magento\Backend\Block\Widget\Form\Container
{
    protected function _construct() {
        $this->_objectId = 'id';
        $this->_blockGroup = 'Vendor_Plugin';
        $this->_controller = 'adminhtml_import';

        parent::_construct();
        $this->buttonList->remove('back');
        $this->buttonList->remove('save');
        $this->buttonList->remove('reset');
        $this->_formScripts[] = "";
        
        /* Rest of the code */
    }
}

We believe that $this->_formScripts[] = "" is the cause of the error because when we comment this line from the code the plugin page works fine in the admin. it seems that after commenting this line we started to have other complications. the plugin has tabs in the admin and basically when we upload a file in the first tab then it automatically redirects to the next tab. this is how the extension was working in Magento 2.3.x but after removing $this->_formScripts[] = "" it stopped working and the control is not going to the next tab automatically.

so can anyone tell us what is the purpose of $this->_formScripts[] = ""? How can we keep this in the extension and fix the error that was mentioned above?

1 Answer 1

1

The purpose of $this->_formScripts[] to load additional scripts, using requireJS, for your form. Take a look at Magento\Widget\Block\Adminhtml\Widget for an example.

Apparently your module tries to load a script from a remote url. The culprit should be visible in your browser console. Try adding the domain that is hosting the script to your csp_whitelist.xml.

HTH, Tom

4
  • the thing is that the page is completely down. I cannot see the request URLs in the console or Network. so there is no way to see if the page contains an external URL. Dec 7, 2022 at 12:08
  • grep the module's source code: grep -r "http" /path/to/module/* Dec 7, 2022 at 12:12
  • Thanks, I ran the given command but the only common entries that I found from the whole plugin are these: "<config xmlns:xsi="w3.org/2001/XMLSchema-instance", "<schema xmlns:xsi="w3.org/2001/XMLSchema-instance" and "<page xmlns:xsi="w3.org/2001/XMLSchema-instance". didn't find any external URL. in fact I also tried to search for "https" using grep but no luck! Dec 9, 2022 at 9:48
  • Then url is probably in database. Search core_config_data for entries. i.e. "select * from core_config_data where path like 'section_id/%'" Replace section_id with the section_id from the module's section_id in etc/adminhtml/system.xml The Mailchimp module does something similar after you connect to their api. HTH, Tom Dec 9, 2022 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.