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

Add contentSecurityPolicy Case to HttpEquiv Enumeration #153

Closed
wants to merge 1 commit into from
Closed

Add contentSecurityPolicy Case to HttpEquiv Enumeration #153

wants to merge 1 commit into from

Conversation

mattt
Copy link

@mattt mattt commented Sep 14, 2018

Related to #152, another modern web standard that you can use to improve the security of https://pointfree.co is to define a Content Security Policy.

A CSP can be defined either in an HTTP header or a <meta> tag. I couldn't find a straightforward way to add a new default header to connections serving HTML responses, so I went with a <meta> tag.

To do this, I added a new contentSecurityPolicy case to the HttpEquiv enumeration. With this in place, you could update your standard layout to include a new meta tag.

As far as defining a CSP, the easiest way would be to simply hardcode a string. As an alternative, you might also consider this DSL I created.

I haven't tested this myself, but I believe that the following CSP would be valid for https://pointfree.co:

default-src 'self' *.pointfree.co;
script-src 'self' *.pointfree.co 'unsafe-inline' https://www.google-analytics.com;
connect-src 'self' *.pointfree.co https://www.google-analytics.com;
base-uri 'none';
upgrade-insecure-requests;

@stephencelis
Copy link
Member

stephencelis commented Sep 15, 2018

Ah nice! The Html module here has been deprecated in favor of https://github.com/pointfreeco/swift-html, and I've removed the enum since it provides a false sense of safety (the implementation didn't require that keys match up with their proper value types). We'd be happy to add a function alongside these, though: https://github.com/pointfreeco/swift-html/blob/master/Sources/Html/Elements.swift#L1033-L1059

And nice DSL :)

@stephencelis
Copy link
Member

Oh, and if you're curious about the reason for deprecation, we consider swift-web to be the experimental platform that drives www.pointfree.co. Our plan is to slowly release battle-tested, production-ready modules separately, as we have with https://github.com/pointfreeco/swift-html.

@mattt
Copy link
Author

mattt commented Sep 22, 2018

Ah, got it. Thanks for the heads-up. I agree that the new approach is superior. I'll open up a new PR over there unless y'all end up beating me to it :)

@mattt mattt closed this Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants