scommerce/csp-helper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

scommerce/csp-helper

Composer 安装命令:

composer require scommerce/csp-helper

包简介

Scommerce CSP Helper Module for Magento 2.0

README 文档

README

This Magento 2 extension helps you resolve Content Security Policy (CSP) issues caused by inline JavaScript code in your store. It achieves this by automatically adding a nonce attribute to all your inline script tags.

Features

• Automatic nonce generation for inline scripts.

• Dependency injection for easy integration into your custom code.

• Improved code maintainability by separating script logic from security concerns.

Installation

  1. Add the repository:
composer require scommerce/csp-helper
  1. In your code, wherever a <script> tag is used, incorporate the helper class and append the getNonce function as shown below
<?php $cspHelper = $this->helper('\Scommerce\CspHelper\Helper\CspHelper'); ?>
<script type="text/javascript" <?= $cspHelper->generateNonce(); ?>>
       // Your script code here
</script>

Important Note

If the generateNonce() function fails to generate a nonce (potentially on Magento versions 2.4.6 and below), an empty string will be added to the nonce attribute.

How it Works

The extension utilises the Scommerce\CspHelper\Helper\CspHelper class. This class injects itself into your Helper, Block, or ViewModel classes using dependency injection. The getNonce() function within this class generates a unique, random string called a nonce. This nonce is then added as the nonce attribute to your inline script tags.

Benefits

• Simplifies CSP compliance.

• Reduces the risk of malicious script execution.

• Improves code maintainability.

Need Help

If you require assistance with implementing this on your website to resolve CSP inline JavaScript errors, feel free to reach out to us via email at support@scommerce-mage.com.

Looking for a Complete Solution?

For a comprehensive resolution of other CSP errors on your site, consider utilising our CSP Whitelist Extension. It provides the capability to whitelist URLs for any CSP directive directly from the Magento admin panel. Learn more about it here.

Disclaimer

This extension is provided as-is with no warranty. It is recommended to thoroughly test the extension in a development environment before deploying it to a live store.

统计信息

  • 总下载量: 2.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: 未知许可证
  • 更新时间: 2024-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固