Skip to content

Script Tags Inside $this->Html->scriptStart() Not Recognized #18243

@zunnu

Description

@zunnu

Description

For security reasons and to comply with Content Security Policy (CSP), we are wrapping all our <script> tags using $this->Html->scriptStart(['block' => true]). However, CakePHP does not recognize the <script> tags inside and throws an error in the console. If we remove the tags, we lose syntax highlighting, which is important for development.

Example:

<?php $this->Html->scriptStart(['block' => true]) ?>
    <script type="text/javascript">
        initSocketIo(function(socket) {

        })
    </script>
<?php $this->Html->scriptEnd() ?>

Expected Behavior:

  • CakePHP should recognize the <script> tags inside $this->Html->scriptStart() without errors.
  • Syntax highlighting should remain available in IDEs.
  • On render, CakePHP should strip the <script> tags from the block to ensure correct output while keeping syntax highlighting during development.

Actual Behavior:

  • CakePHP does not recognize the script tags and throws an error in the browser console.
  • Removing the <script> tags resolves the error but results in loss of syntax highlighting.

CakePHP Version

4.5

PHP Version

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions