Giter VIP home page Giter VIP logo

Comments (4)

javulticat avatar javulticat commented on July 28, 2024 2

It looks like the nonce does not get sent in the header if no nonce is being evaluated in your template. Once my template was evaluating a nonce, things work as expected. Perhaps the docs should be updated to reflect this? I'd be happy to give it a shot if folks are open to it.

from django-csp.

sgelis avatar sgelis commented on July 28, 2024

Thanks for opening this issue. Was hit with the exact same one today.

from django-csp.

DylanYoung avatar DylanYoung commented on July 28, 2024

Took a stab at a PR here.

I wonder if it makes sense to change this behaviour slightly though as it seems somewhat unsafe. If the nonce isn't used and it's not going to be included in the header, shouldn't the source list be set to 'none'?

from django-csp.

some1ataplace avatar some1ataplace commented on July 28, 2024

It might be because of the middleware SimpleLazyObject. The SimpleLazyObject may not be properly calling the _make_nonce method. To fix this, you can change the process_request method to directly call the _make_nonce method:

class CSPMiddleware(MiddlewareMixin):
    def _make_nonce(self, request):
        if not getattr(request, '_csp_nonce', None):
            request._csp_nonce = (
                base64
                .b64encode(os.urandom(16))
                .decode("ascii")
            )
        return request._csp_nonce

    def process_request(self, request):
        request.csp_nonce = self._make_nonce(request)

    # rest of the code remains unchanged

from django-csp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.