openresty / openresty/set-misc-nginx-module
set_secure_random_alphanum doesn't work well with fastcgi_cache
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 401
- Forks
- 100
- Avg merge
- 1h 28m
- Merged PRs (30d)
- 2
Description
I'm trying to use a secure nonce to allow some inline code through a CSP. However, this doesn't work when combined with fastcgi_cache as the nonce value used in the web page is cached, but the nonce value output in the header is created anew.
The server config looks something like this:
fastcgi_param CSP_NONCE $nonce;
more_set_headers "Content-Security-Policy: style-src 'nonce-$nonce';";
location = / {
set_secure_random_alphanum $nonce 10;
fastcgi_pass php;
}
The result is that a nonce is generated and inserted into the CSP header and passed to PHP which inserts it into the HTML. But, as mentioned, when using fastcgi_cache, the header/nonce is not cached along with the page.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported nginx configuration using set_secure_random_alphanum, fastcgi_cache, fastcgi_param, and more_set_headers. Investigate how the nonce is generated and how cached responses handle the page, header, and FastCGI parameter; done means the nonce remains consistent between the cached HTML and CSP header.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, nginx
- Domain
- backend, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100