Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Swagger UI getCSPNonce() method error when using nelmio/security-bundle

オープン
#8,560 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php, symfony
領域
api, backend, security

調査の方向性

The error originates in SwaggerUiProcessor.php line 62, where a static call is made to a non-static method getCSPNonce() from Nelmio\SecurityBundle\Twig\CSPRuntime. Examine the resolveCspNonce method and the surrounding code to understand how the nonce is retrieved. Check the nelmio/security-bundle documentation for the correct way to obtain the nonce, and see if API Platform needs to adapt its integration. Verify the fix by reproducing the issue with the bundle installed and visiting the Swagger UI endpoint.

索引モデルが issue の本文から書いたものです。

説明

API Platform version(s) affected: v5.0.0

Description
I posted about this also on #8310 but unsure if that will be seen: When using API Platform v5.0.0 with nelmio/security-bundle v3.9.0 we get the following error when visiting the Swagger UI:

{
  "@context": "/api/contexts/Error",
  "@id": "/api/errors/500",
  "@type": "Error",
  "title": "An error occurred",
  "detail": "Non-static method Nelmio\\SecurityBundle\\Twig\\CSPRuntime::getCSPNonce() cannot be called statically",
  "status": 500,
  "type": "/errors/500",
  "description": "Non-static method Nelmio\\SecurityBundle\\Twig\\CSPRuntime::getCSPNonce() cannot be called statically",
  "trace": [
    {
      "file": "/var/www/html/vendor/api-platform/symfony/Bundle/SwaggerUi/SwaggerUiProcessor.php",
      "line": 62,
      "function": "resolveCspNonce",
      "class": "ApiPlatform\\Symfony\\Bundle\\SwaggerUi\\SwaggerUiProcessor",
      "type": "->"
    },
    {
      "file": "/var/www/html/vendor/api-platform/state/CallableProcessor.php",
      "line": 52,
      "function": "process",
      "class": "ApiPlatform\\Symfony\\Bundle\\SwaggerUi\\SwaggerUiProcessor",
      "type": "->"
    },
    {
      "file": "/var/www/html/vendor/api-platform/state/Processor/WriteProcessor.php",
      "line": 58,
      "function": "process",
      "class": "ApiPlatform\\State\\CallableProcessor",
      "type": "->"
    },
    {
      "file": "/var/www/html/vendor/api-platform/symfony/Validator/State/ValidateProcessor.php",
      "line": 44,
      "function": "process",
      "class": "ApiPlatform\\State\\Processor\\WriteProcessor",
      "type": "->"
    },
    {
      "file": "/var/www/html/vendor/api-platform/symfony/Action/EntrypointAction.php",
      "line": 61,
      "function": "process",
      "class": "ApiPlatform\\Symfony\\Validator\\State\\ValidateProcessor",
      "type": "->"
    },
    {
      "file": "/var/www/html/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 188,
      "function": "__invoke",
      "class": "ApiPlatform\\Symfony\\Action\\EntrypointAction",
      "type": "->"
    },
    {
      "file": "/var/www/html/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 79,
      "function": "handleRaw",
      "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
      "type": "->"
    },
    {
      "file": "/var/www/html/vendor/symfony/http-kernel/Kernel.php",
      "line": 143,
      "function": "handle",
      "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
      "type": "->"
    },
    {
      "file": "/var/www/html/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php",
      "line": 34,
      "function": "handle",
      "class": "Symfony\\Component\\HttpKernel\\Kernel",
      "type": "->"
    },
    {
      "file": "/var/www/html/vendor/autoload_runtime.php",
      "line": 32,
      "function": "run",
      "class": "Symfony\\Component\\Runtime\\Runner\\Symfony\\HttpKernelRunner",
      "type": "->"
    },
    {
      "file": "/var/www/html/public/index.php",
      "line": 7,
      "function": "require_once"
    }
  ]
}

This issue seems to have been fixed for the API Platform v5.0.0 release when not using nelmio/security-bundle based on the PR description, since a similar error is produced. However, when requiring nelmio/security-bundle we get the afforementioned error.

How to reproduce

  1. composer require nelmio/security-bundle
  2. Create a route with API Platform
  3. Visit url.example.com/api

Possible Solution
At the moment using a custom decorator that gets the nonce using the nelmio/security-bundle functions seems to work but that is just a workaround and not an official solution.

主要言語
PHP
スター
2.6k
フォーク
982
平均マージ
1日 16時間
マージ済み PR(30日)
59

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

api-platform/core のほかの issue

api-platform/core の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。