Giter VIP home page Giter VIP logo

Comments (3)

nukeador avatar nukeador commented on July 26, 2024 1

Talking with @willemarcel it seems you faced some challenges implementing this, so I wanted to share some tips from my personal experience implementing the recommendations on other sites:

  1. Try to implement all recommendations EXCEPT CSP. This will boost the security of the site to B, which is very important to avoid non-secure connections to the site or its resources or XSS and click-jacking attacks.

  2. During a second phase, play with the different CSP options, starting with the more permissive one and moving to the most restrictive one in different phases:

https://infosec.mozilla.org/guidelines/web_security#content-security-policy

For this there are at least 3 important factors: Have a list of external urls where you load resources from (or try to self-host most libraries to improve privacy) and analyze how much inline js and css you use on your code (to try to plan to move these to a file instead).

Please, ping me if you have other questions where my experience can be helpful.

Cheers.

/cc @eternaltyro @dakotabenjamin

from tech.

eternaltyro avatar eternaltyro commented on July 26, 2024

@nukeador Thank you for the guidelines. There are multiple challenges in play here.

Try to implement all recommendations EXCEPT CSP. This will boost the security of the site to B, which is very important to avoid non-secure connections to the site or its resources or XSS and click-jacking attacks.

The HOT website is hosted on Github pages which, sadly, does not allow setting HTTP headers. So we are restricted to http <meta> tags for setting these security flags. Meta tags as you may know are not supported by all browsers and is not considered standard.

During a second phase, play with the different CSP options, starting with the more permissive one and moving to the most restrictive one in different phases:

Missing any domains in the CSP whitelist causes drastic problems with functionality. Therefore, I had to know every single resource included in the HOT website. I used a browser tool that generates CSP policies and loaded (what I thought was) all the pages so that the tool can capture a list of resources being loaded. I overestimated the coverage here and the implementation broke the website and several blogposts.

I'm trying to now find tools (or build a simple one myself) that read the sitemap and visit all the pages in the sitemap to build a list of resources.

Alternatively, I could use the content-security-policy-report-only header and use a tool that parses reports to the report-uri. Unfortunately, report-only tag can't be passed through <meta> tags.

In the end, it seems like using the sitemap.xml to crawl all pages and gather resources seems like the most reliable way to go. I'll keep this ticket updated as I make progress.

from tech.

nukeador avatar nukeador commented on July 26, 2024

The HOT website is hosted on Github pages which, sadly, does not allow setting HTTP headers. So we are restricted to http <meta> tags for setting these security flags. Meta tags as you may know are not supported by all browsers and is not considered standard.

Do you have specific browsers in mind? According to this table all major browsers have full compatibility with the main CSP attributes that the observatory recommends to change:

https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#browser_compatibility

My experience implementing CSP thought meta tags on github pages recently didn't resulted into compatibility issues.

Missing any domains in the CSP whitelist causes drastic problems with functionality. Therefore, I had to know every single resource included in the HOT website. I used a browser tool that generates CSP policies and loaded (what I thought was) all the pages so that the tool can capture a list of resources being loaded. I overestimated the coverage here and the implementation broke the website and several blogposts.
In the end, it seems like using the sitemap.xml to crawl all pages and gather resources seems like the most reliable way to go. I'll keep this ticket updated as I make progress.

This can be quite complex yes, specially if you want optimize for any existing external resource, that's why doing CSP in a second phase is advised.

I would say that the security recommendations is to have control over external resources loaded, so allowing anyone to add images from any domain might be a policy change to consider. What other sites have done is to fetch and copy locally all these images to avoid the burden of having a huge allow list.

This also applies to external css and js, where most of the times the most productive approach is to copy them locally to have full control on the code that is executed.

from tech.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.