From 5742d41c9336c3b0c167716b9569c642d952ea4a Mon Sep 17 00:00:00 2001 From: James Groom Date: Tue, 15 Oct 2024 03:22:29 +1000 Subject: [PATCH] CSP round 3(?) (#2003) * Make `Content-Security-Policy` not so hardcoded * Add more `Content-Security-Policy` directives --- .../ApplicationBuilderExtensions.cs | 26 +++++++++++++++++-- TASVideos/Program.cs | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/TASVideos/Extensions/ApplicationBuilderExtensions.cs b/TASVideos/Extensions/ApplicationBuilderExtensions.cs index e6cc81231..332e88b43 100644 --- a/TASVideos/Extensions/ApplicationBuilderExtensions.cs +++ b/TASVideos/Extensions/ApplicationBuilderExtensions.cs @@ -46,8 +46,30 @@ public static IApplicationBuilder UseStaticFilesWithExtensionMapping(this IAppli }); } - public static IApplicationBuilder UseMvcWithOptions(this IApplicationBuilder app, IHostEnvironment env) + public static IApplicationBuilder UseMvcWithOptions(this IApplicationBuilder app, IHostEnvironment env, AppSettings settings) { + var userAgentReportURL = $"{settings.BaseUrl}/Diagnostics/UserAgentInterventionReports"; + string[] trustedJSHosts = [ + "https://cdn.jsdelivr.net", + "https://cdnjs.cloudflare.com", + "https://code.jquery.com", + "https://www.google.com/recaptcha/", + "https://www.gstatic.com/recaptcha/", + "https://www.youtube.com", + ]; + string[] cspDirectives = [ + "base-uri 'none'", // neutralises the `` footgun + "default-src 'self'", // fallback for other `*-src` directives + "font-src 'self' https://cdnjs.cloudflare.com/ajax/libs/font-awesome/", // CSS `font: url();` and `@font-face { src: url(); }` will be blocked unless they're from one of these domains (this also blocks nonstandard fonts installed on the system maybe) + "form-action 'self'", // domains allowed for `
` (POST target page) + "frame-src 'self' https://www.youtube.com/embed/", // allow these domains in