Wie man Problem mit CSP behebt

Hallo! Ich habe ein Problem mit CSP, wie kann ich das beheben?

screen

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src https://mydomain.com/logs/ https://mydomain.com/sidekiq/ https://mydomain.com/mini-profiler-resources/ https://mydomain.com/assets/ https://mydomain.com/brotli_asset/ https://mydomain.com/extra-locales/ https://mydomain.com/highlight-js/ https://mydomain.com/javascripts/ https://mydomain.com/plugins/ https://mydomain.com/theme-javascripts/ https://mydomain.com/svg-sprite/ https://mydomain.com". Either the 'unsafe-inline' keyword, a hash ('sha256-ScCk7JwXKy22dTO0VFM7aV1chV+yd/MUda4X6VnGans='), or a nonce ('nonce-...') is required to enable inline execution.

Für den Test bin ich in einen Safe Mode gegangen, im Safe Mode gibt es das gleiche Problem.

1 „Gefällt mir“

Das ist nicht meine Stärke, aber ich habe gesucht und Sie müssen möglicherweise das Inline-Skript, das Sie verwenden möchten, neu schreiben:

2 „Gefällt mir“

Ich möchte den CSP-Schutz nicht deaktivieren und habe keine externen Skripte. Ich habe versucht, alle Plugins und Komponenten des Themas zu deaktivieren, aber es hat nicht geholfen.

Ich versuche, all diese Links zu content security policy script src in den Admin-Einstellungen hinzuzufügen. Das Problem war sicher :frowning:
https://mydomain.com/logs/ https://mydomain.com/sidekiq/ https://mydomain.com/mini-profiler-resources/ https://mydomain.com/assets/ https://mydomain.com/brotli_asset/ https://mydomain.com/extra-locales/ https://mydomain.com/highlight-js/ https://mydomain.com/javascripts/ https://mydomain.com/plugins/ https://mydomain.com/theme-javascripts/ https://mydomain.com/svg-sprite/ https://mydomain.com`

1 „Gefällt mir“

Sie müssen Ihre Website-URL angeben, damit wir Ihnen helfen können.

3 „Gefällt mir“

Kann ich es Ihnen per PM schicken?

Hm…

Ich scheine den Grund gefunden zu haben. Es scheint, dass das Problem auftritt, weil ich das CSP-Meta-Tag in meinem Theme verwende:

<meta http-equiv="Content-Security-Policy" content="img-src https://imgur.com https://giphy.com">

Ich muss die img-src-Direktive verwenden, um die Anzeige von Bildern von verbotenen Hosts einzuschränken.

Diese CSP-Direktive wird Discourse tatsächlich komplett lahmlegen.

2 „Gefällt mir“

Wie kann ich die Standard-CSP-Direktiven im Header ändern, um img-src hinzuzufügen, ohne ein Meta-Tag zu verwenden? Ich habe dies in Rails versucht, aber es hat sich nichts geändert:

Rails.application.config.action_dispatch.default_headers.merge!({'Content-Security-Policy' => "upgrade-insecure-requests; base-uri 'self'; object-src 'none'; script-src https://mydomain.com/logs/ https://mydomain.com/sidekiq/ https://mydomain.com/mini-profiler-resources/ https://mydomain.com/assets/ https://mydomain.com/brotli_asset/ https://mydomain.com/extra-locales/ https://mydomain.com/highlight-js/ https://mydomain.com/javascripts/ https://mydomain.com/plugins/ https://mydomain.com/theme-javascripts/ https://mydomain.com/svg-sprite/; worker-src 'self' https://mydomain.com/assets/ https://mydomain.com/brotli_asset/ https://mydomain.com/javascripts/ https://mydomain.com/plugins/; frame-ancestors 'self'; manifest-src 'self'; img-src data: https://mydomain.com https://imgur.com"})

Ich lösche diesen Meta-Tag, baue neu und das Problem war behoben :frowning: