Skip to content

\Magento\Csp\Helper\CspNonceProvider is not an actual Helper class - misleading naming #40266

@ioweb-gr

Description

@ioweb-gr

Summary

ON magento 2.4.8-p3 I noticed that \Magento\Csp\Helper\CspNonceProvider is misleadingly named

it lives under the Helper namespace but does not extend \Magento\Framework\App\Helper\AbstractHelper.

It behaves however as a standalone service used for generating CSP nonces, not as a traditional Magento helper.

This inconsistency can confuse developers and tools expecting helper behavior.

Examples

  • Misleading:

    use Magento\Csp\Helper\CspNonceProvider;
    $nonce = $this->cspNonceProvider->generateNonce(); // not a real Helper
  • What it should have been:

    use Magento\Csp\Service\CspNonceProvider;
    // or
    use Magento\Csp\Model\CspNonceProvider;
  • Expected Helper (if it really were one):

    class CspNonceProvider extends \Magento\Framework\App\Helper\AbstractHelper
    {
        // typical helper access to store config, context, etc.
    }

In short: the class name implies framework helper semantics, but it’s just a regular service.

Morever if it's not extending AbstractHelper then it's not possible to use it directly in PHTML files but you have to inject the viewModel instead.

In any case either the namespace should be corrected or it should extend the AbstractHelper, leaving it like this is misleading as to it's purpose.

Proposed solution

Either move it under another namespace or extend AbstractHelper

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Labels

Area: FrameworkComponent: Framework/AppIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Reported on 2.4.8-p3Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Ready for Development

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions