yiisoft / yii-web

Yii web components
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
78 stars 46 forks source link

Missing support for the Content Security Policy Header #66

Closed bicf closed 5 years ago

bicf commented 7 years ago

Due missing of CSP in Yii2 I develop a basic support of CSP.

Following the "Git workflow for Yii 2 contributors" I open this issue.

bizley commented 7 years ago

What support do you require? CSP can be already used.

I've prepared something for this:

bicf commented 7 years ago

I try to reduce as much as possible the impact of the modify in the code but I've some doubts:

TIA

bizley commented 7 years ago

It was prepared rather for internal usage hence lack of documentation. I could gladly help with adding something similar to the core. But if this should stay as outside package I can publish it properly.

bicf commented 7 years ago

LOL If it's good for you, I'll write the missing documentation as java-comment in a new commit

bizley commented 7 years ago

I'm a bit confused. I thought you don't understand some parts of my code - not whether we are adding this to Yii 2 core or not. None of Yii 2 team members said anything yet. I'm perfectly capable of writing documentation on my own, thank you.

My question is more for an idea behind this component:

bicf commented 7 years ago

Sorry, I totally misunderstood your comments. I was thinking you're talking about my PR 13964!

About this implementaton I think that:

I see your codes and my comments are:

PS I don't want to be "negative" with my "don't like"

uran1980 commented 6 years ago

@see https://github.com/paragonie/csp-builder

bicf commented 6 years ago

Hi, I develop a an yii2 extension to release all the security headers based on modules. It realease the CSP header too @see https://github.com/bicf/yii2-security-headers

ADD Even if the code is working (ex quite good HAHAHAHA), all the documentation is still WIP and I'll apreciate feed-back

samdark commented 5 years ago

There's https://github.com/middlewares/csp we can use right away.

samdark commented 5 years ago

Closing for now. Will consider our own if the one above won't work well.

bicf commented 5 years ago

Hi,

I like very much the PSR-7 implementation of https://github.com/middlewares/csp but how is the integration of PSR-7 in yii2?

https://github.com/paragonie/csp-builder has a strong approach on generating HASH by "scanning" the sources (CSS, JS) directories but this approach need at least one more step (regenerate the hashes) after an update by composer or any changes in the JS/CSS files.

Futhermore this approach do not allow the nonce signature, "only" to send the CSP header, and that's a big limitation when you cannot trust self because a carrier or a virus inject a malicious JS in your pages.

I've refactored my yii2-security-headers now it has a smaller footprint and a better documentation. I think it could be more effective with a PSR-7 + PSR-15 implementation and optionally integrate the https://github.com/paragonie/csp-builder so I'm hope in a quick response about the PSR-7 integration in yii.

samdark commented 5 years ago

how is the integration of PSR-7 in yii2?

There won't be any integration of PSR-7 into Yii 2. It is Yii 3 only.