josiasmontag / laravel-recaptchav3

Laravel package for Google's Recaptcha V3
MIT License
203 stars 37 forks source link

Content Security Policy Nonce #17

Open eliasjtg opened 3 years ago

eliasjtg commented 3 years ago

My server has Content Security Policy enabled, i want to initialize js code with a nonce to allow recaptcha script execution.

Google docs recommend use nonce: FAQ

Can be added a function called initJsNonce() or related?

    /**
     * @param string $nonce
     * @return string
     */
    public function initJsNonce(string $nonce): string
    {
        return '<script src="' . $this->origin . '/api.js?render=' . $this->sitekey . '" nonce="'.$nonce.'"></script>';
    }

As workaround how can add/override RecaptchaV3 class to add this?

I'm not familiarized with Laravel Container to do that, if anyone can help me I would appreciate.