Merged
Conversation
Contributor
Author
|
Ah I was unaware of the playwright tests - looks like they caught a bug in my implementation. Cool, I will sort it out. |
lovasoa
requested changes
May 4, 2025
Collaborator
lovasoa
left a comment
There was a problem hiding this comment.
Thank you for taking the time to dive in !
This is a good start, but the logic is a little bit wrong here. Each nonce has to be used only once. We cannot define a random nonce on startup and then use it repeatedly. Otherwise an attacker can easily make a script injection that contains the known nonce.
How I think it should work:
- in app_config, we store a parsed csp string. It could be something as simple as
struct CSPFormat { before_nonce: String, after_nonce: String } - add a method to request_context.content_security_policy that takes a
CSPFormatand generates a header. - in render.rs, replace the csp insertion with
request_context.content_security_policy.add_to_response(&mut response, app_state.config.content_security_policy)
Contributor
Author
|
Yep makes sense +1. I'll take another run at this tomorrow and ensure each nonce is per-request. |
…ght test to verify subsequent requests return a different nonce.
Contributor
Author
|
OK this should now be correct (I added an e2e test to verify). Let me know what you think! |
lovasoa
requested changes
May 5, 2025
we are still re-parsing the csp template on every request
af329fc to
a88f350
Compare
Collaborator
|
Done. Thank you @guspower ! |
Contributor
Author
|
Excellent thank you @lovasoa !!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A first pass implementation as discussed in issue #909
Let me know what you think - I'll update the docs when you're happy with it.