Undefined variable $cspNonce #3728

Closed
opened 2026-02-05 07:16:19 +03:00 by OVERLORD · 7 comments
Owner

Originally created by @AidasK on GitHub (Apr 3, 2023).

Describe the Bug

2023/04/02 07:53:03 [error] 303#303: *72606 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught ErrorException: Undefined variable $cspNonce in /app/www/storage/framework/views/872733693c1f8e7d46945825e715cc42e8efb276.php:68
Stack trace:
#0 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(266): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#1 /app/www/storage/framework/views/872733693c1f8e7d46945825e715cc42e8efb276.php(68): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}()
#2 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(109): require('...')
#3 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(110): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem\{closure}()
#4 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(58): Illuminate\Filesystem\Filesystem->getRequire()
#5 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(70): Illuminate\View...PHP message: PHP Fatal error:  Uncaught ErrorException: Undefined variable $cspNonce in /app/www/storage/framework/views/872733693c1f8e7d46945825e715cc42e8efb276.php:68
Stack trace:
#0 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(266): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#1 /app/www/storage/framework/views/872733693c1f8e7d46945825e715cc42e8efb276.php(68): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}()
#2 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(109): require('...')
#3 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(110): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem\{closure}()
#4 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(58): Illuminate\Filesystem\Filesystem->getRequire()
#5 /app/www/vendor/laravel/framework/src/Illuminate/Vie
    <div component="back-to-top" class="back-to-top print-hidden">
        <div class="inner">
            <?php echo icon('chevron-up'); ?> <span><?php echo e(trans('common.back_to_top')); ?></span>
        </div>
    </div>

    <?php echo $__env->yieldContent('bottom'); ?>
    <script src="<?php echo e(versioned_asset('dist/app.js')); ?>" nonce="<?php echo e($cspNonce); ?>"></script>
    <?php echo $__env->yieldContent('scripts'); ?>

    <?php echo $__env->make('layouts.parts.base-body-end', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
</body>
</html>

68 line is <script src="<?php echo e(versioned_asset('dist/app.js')); ?>" nonce="<?php echo e($cspNonce); ?>"></script>

Steps to Reproduce

Not sure, just happened after I have renamed an article title.

Expected Behaviour

No errors should be reported

Screenshots or Additional Context

No response

Browser Details

No response

Exact BookStack Version

BookStack v23.02.1

PHP Version

8.0

Hosting Environment

Docker installation via https://hub.docker.com/r/linuxserver/bookstack

Originally created by @AidasK on GitHub (Apr 3, 2023). ### Describe the Bug ``` 2023/04/02 07:53:03 [error] 303#303: *72606 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught ErrorException: Undefined variable $cspNonce in /app/www/storage/framework/views/872733693c1f8e7d46945825e715cc42e8efb276.php:68 Stack trace: #0 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(266): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() #1 /app/www/storage/framework/views/872733693c1f8e7d46945825e715cc42e8efb276.php(68): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}() #2 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(109): require('...') #3 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(110): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem\{closure}() #4 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(58): Illuminate\Filesystem\Filesystem->getRequire() #5 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(70): Illuminate\View...PHP message: PHP Fatal error: Uncaught ErrorException: Undefined variable $cspNonce in /app/www/storage/framework/views/872733693c1f8e7d46945825e715cc42e8efb276.php:68 Stack trace: #0 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(266): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() #1 /app/www/storage/framework/views/872733693c1f8e7d46945825e715cc42e8efb276.php(68): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}() #2 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(109): require('...') #3 /app/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(110): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem\{closure}() #4 /app/www/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(58): Illuminate\Filesystem\Filesystem->getRequire() #5 /app/www/vendor/laravel/framework/src/Illuminate/Vie ``` ```php <div component="back-to-top" class="back-to-top print-hidden"> <div class="inner"> <?php echo icon('chevron-up'); ?> <span><?php echo e(trans('common.back_to_top')); ?></span> </div> </div> <?php echo $__env->yieldContent('bottom'); ?> <script src="<?php echo e(versioned_asset('dist/app.js')); ?>" nonce="<?php echo e($cspNonce); ?>"></script> <?php echo $__env->yieldContent('scripts'); ?> <?php echo $__env->make('layouts.parts.base-body-end', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?> </body> </html> ``` 68 line is `<script src="<?php echo e(versioned_asset('dist/app.js')); ?>" nonce="<?php echo e($cspNonce); ?>"></script>` ### Steps to Reproduce Not sure, just happened after I have renamed an article title. ### Expected Behaviour No errors should be reported ### Screenshots or Additional Context _No response_ ### Browser Details _No response_ ### Exact BookStack Version BookStack v23.02.1 ### PHP Version 8.0 ### Hosting Environment Docker installation via https://hub.docker.com/r/linuxserver/bookstack
OVERLORD added the 🐛 Bug label 2026-02-05 07:16:19 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Apr 3, 2023):

Hi @AidasK,

  • Is this consistently reproducible?
  • Can you provide the exact version of the BookStack container image in use?
  • Do you have any example config of your setup (docker-compose.yml) and/or can you describe your docker/hosting environment a bit?
@ssddanbrown commented on GitHub (Apr 3, 2023): Hi @AidasK, - Is this consistently reproducible? - Can you provide the exact version of the BookStack container image in use? - Do you have any example config of your setup (`docker-compose.yml`) and/or can you describe your docker/hosting environment a bit?
Author
Owner

@AidasK commented on GitHub (Apr 3, 2023):

This starts to happen everytime and lasts for a bit if:

  • I rename an article and url changes.
  • I come to the old url and page just crashes.
  • If I visit other urls everything is still crashing with 500 error code.
  • After some time probably cookie expires and everything works as before.

This is my build https://hub.docker.com/layers/linuxserver/bookstack/23.02.1/images/sha256-3626275c7b1af92e98dc7ffc8bf5eda6bf4ff3ca7c4c09e91f137ca47581c1ff?context=explore

This is my compose file:

---
version: "3.9"
services:
 bookstack:
   image: ghcr.io/linuxserver/bookstack
   container_name: bookstack
   environment:
     - PUID=1000
     - PGID=1000
     - APP_URL=https://wiki.website.com
     - DB_HOST=qqqqq
     - DB_USER=qqqqq
     - DB_PASS=qqqq
     - DB_DATABASE=qqqq
     - VIRTUAL_HOST=wiki.website.com
     - SELF_SIGNED_HOST=wiki.website.com
   volumes:
     - ./data:/config
   ports:
     - "80:80"
   restart: always

 nginx-proxy:
   image: jwilder/nginx-proxy
   container_name: nginx-proxy
   restart: always
   ports:
     - "443:443"
   volumes:
     - /var/run/docker.sock:/tmp/docker.sock:ro
     - ./certs:/etc/nginx/certs:ro
     - ./docker-nginx.conf:/etc/nginx/conf.d/my_proxy.conf

 proxy-companion:
   container_name: proxy-companion
   restart: always
   image: sebastienheyd/self-signed-proxy-companion
   volumes:
           - /var/run/docker.sock:/var/run/docker.sock:ro
           - ./certs:/etc/nginx/certs:rw

Wiki is running on cloudflare cdn which routes to our server via self signed certificate.

@AidasK commented on GitHub (Apr 3, 2023): This starts to happen everytime and lasts for a bit if: - I rename an article and url changes. - I come to the old url and page just crashes. - If I visit other urls everything is still crashing with 500 error code. - After some time probably cookie expires and everything works as before. This is my build https://hub.docker.com/layers/linuxserver/bookstack/23.02.1/images/sha256-3626275c7b1af92e98dc7ffc8bf5eda6bf4ff3ca7c4c09e91f137ca47581c1ff?context=explore This is my compose file: ```yml --- version: "3.9" services: bookstack: image: ghcr.io/linuxserver/bookstack container_name: bookstack environment: - PUID=1000 - PGID=1000 - APP_URL=https://wiki.website.com - DB_HOST=qqqqq - DB_USER=qqqqq - DB_PASS=qqqq - DB_DATABASE=qqqq - VIRTUAL_HOST=wiki.website.com - SELF_SIGNED_HOST=wiki.website.com volumes: - ./data:/config ports: - "80:80" restart: always nginx-proxy: image: jwilder/nginx-proxy container_name: nginx-proxy restart: always ports: - "443:443" volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./certs:/etc/nginx/certs:ro - ./docker-nginx.conf:/etc/nginx/conf.d/my_proxy.conf proxy-companion: container_name: proxy-companion restart: always image: sebastienheyd/self-signed-proxy-companion volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - ./certs:/etc/nginx/certs:rw ``` Wiki is running on cloudflare cdn which routes to our server via self signed certificate.
Author
Owner

@ssddanbrown commented on GitHub (Apr 3, 2023):

@AidasK Thanks, I'm not sure how it'd lead to this particular error, but the issues mentioned sound like the pattern of server-side caching issues. Can you ensure caching is disabled at all proxy/https layers, for any type of resource or asset in relation to BookStack requests?

@ssddanbrown commented on GitHub (Apr 3, 2023): @AidasK Thanks, I'm not sure how it'd lead to this particular error, but the issues mentioned sound like the pattern of server-side caching issues. Can you ensure caching is disabled at all proxy/https layers, for any type of resource or asset in relation to BookStack requests?
Author
Owner

@AidasK commented on GitHub (Apr 4, 2023):

We are using default cloudflare config, so no cache is enforced. If bookstack returns a public cache header it will be cached by cloudflare, but that's expected. So I doubt it has anything to do with cloudflare.

maybe as a quick workaround we could update the blade file to: {{$cspNonce ?? ''}}. So it won't break even though it's missing?

@AidasK commented on GitHub (Apr 4, 2023): We are using default cloudflare config, so no cache is enforced. If bookstack returns a public cache header it will be cached by cloudflare, but that's expected. So I doubt it has anything to do with cloudflare. maybe as a quick workaround we could update the blade file to: `{{$cspNonce ?? ''}}`. So it won't break even though it's missing?
Author
Owner

@AidasK commented on GitHub (Apr 4, 2023):

I suspect that cspNonce error overshadows other error occured in laravel exception handler which has not triggered ApplyCspRules middleware

@AidasK commented on GitHub (Apr 4, 2023): I suspect that cspNonce error overshadows other error occured in laravel exception handler which has not triggered ApplyCspRules middleware
Author
Owner

@ssddanbrown commented on GitHub (Apr 4, 2023):

There was a time where that would occur, due to CSP nonce usage on error pages, but I thought we had addressed that.

maybe as a quick workaround we could update the blade file to: {{$cspNonce ?? ''}}. So it won't break even though it's missing?

Yeah, Could do that temporarily to see if the error becomes more transparent, but not sure I'd want to apply that to the codebase since I do expect that to always be present, and we should know about scenarios where that expectation is broken.

It'd be worth checking the application log if you haven't already done so. (About 7:40 mark of this video: https://youtu.be/6A8hLuQTkKQ?t=448)

@ssddanbrown commented on GitHub (Apr 4, 2023): There was a time where that would occur, due to CSP nonce usage on error pages, but I thought we had addressed that. > maybe as a quick workaround we could update the blade file to: {{$cspNonce ?? ''}}. So it won't break even though it's missing? Yeah, Could do that temporarily to see if the error becomes more transparent, but not sure I'd want to apply that to the codebase since I do expect that to always be present, and we should know about scenarios where that expectation is broken. It'd be worth checking the application log if you haven't already done so. (About 7:40 mark of this video: https://youtu.be/6A8hLuQTkKQ?t=448)
Author
Owner

@ssddanbrown commented on GitHub (Apr 17, 2023):

Since there's been no follow-up I'm going to close this. If the issue remains and is something you still require to be fixed respond to my previous comment and this can then be re-opened.

@ssddanbrown commented on GitHub (Apr 17, 2023): Since there's been no follow-up I'm going to close this. If the issue remains and is something you still require to be fixed respond to my previous comment and this can then be re-opened.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#3728