Swagger UI getCSPNonce() method error when using nelmio/security-bundle
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- composer require nelmio/security-bundle
- Create a route with API Platform
- 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.
- Lingua principale
- PHP
- Stelle
- 2.6k
- Fork
- 982
- Merge medio
- 1g 16h
- PR unite (30g)
- 59
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di api-platform/core
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
api-platform/core#8564 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
api-platform/core#8495 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
api-platform/core#8471 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
api-platform/core#8475 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
api-platform/core#8447 ·
Tutte le issue di api-platform/core
Issue simili
-
Solved site promotion gate fails on runner PHP patch drift (expects 8.2.33, runner installs 8.2.34) Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Automattic/blocks-engine#2161 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Automattic/static-site-importer#1824 ·
-
[Chore] Keep one viget-block-generator skill and replicate it, instead of four tracked copies Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Cannot reset column width Aperta0. Needs triage bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
0. Needs triage 35-feedback bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100