LemmyNet / lemmy-ui

The official web app for lemmy.
https://join-lemmy.org/
GNU Affero General Public License v3.0
900 stars 336 forks source link

Strengthen Content-Security-Policy header #1914

Open SineSwiper opened 1 year ago

SineSwiper commented 1 year ago

Requirements

Summary

Issue #1641 introduced some unsafe content security policies. It appears unsafe-eval has been removed, but unsafe-inline still exists. (Although, unsafe-eval hasn't been specifically blocked...) As reported in issue #83, this breaks recommendations by Mozilla Observatory.

There are a ton of other bad practices that need to be fixed with the CSP. Fixing these gives us a layer of protection from future XSS attacks.

Steps to Reproduce

  1. Load web page and inspect Content-Security-Policy headers
  2. Inspect line of code that adds property
  3. Read Mozilla Observatory report

Technical Details

Any

Lemmy Instance Version

0.18.1

Lemmy Instance URL

https://observatory.mozilla.org/analyze/lemmy.world

sunaurus commented 1 year ago

FYI unsafe-inline for scripts was already removed in 0.18.2.

The current rating for 0.18.2 on that observatory website is A+: https://observatory.mozilla.org/analyze/lemm.ee

Some things can still be improved, most notably unsafe-inline for style-src can be abused to deface websites:

image