Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare Proxy Causes Issue if CSRFP_TOKEN Name is Uppercase #159

Open
sectri-sitler opened this issue Jul 21, 2023 · 0 comments
Open

Comments

@sectri-sitler
Copy link

Describe the bug
When using a server that leverages Cloudflare's Proxy and while attempting an AJAX call (PHP/Javascript), you will receive a 403 Forbidden response from csrfprotector.

To Reproduce
Configure the CSRFP_TOKEN with uppercase characters. Then attempt an AJAX call (PHP/Javascript) with PHP files that use csrfprotector. You will receive a 403 Forbidden response.

Expected behavior
The AJAX call works fine and returns expected data when Cloudflare Proxy is not enabled.

Solution
Rename the CSRFP_TOKEN to lowercase and this will resolve the issue. This resolves the issue because Cloudflare is renaming the CSRFP_TOKEN in the request header to all lowercase. While this is definitely a Cloudflare issue, it may be a good idea to include this issue in the csrfprotector documentation or update the functions to allow for uppercase or lowercase, as long as the name matches.

Additional Details

Csrfprotector checks the request headers to find the csrf token. It uses the function getTokenFromRequest() to do this. getTokenFromRequest() looks at the request headers and searches for the name configured in config.php ($config['CSRFP_TOKEN']]). If it doesn’t find it, the function returns false, thus the token is not set. Because the token is not set, the function failedValidationAction() is called and csrf protector stops the web application from executing any more code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant