High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
Add sandboxing headers to uploaded media.
Kailash Nadh00329644c78b
diff --git a/cmd/init.go b/cmd/init.goindex 61465a0a..3a8555de 100644--- a/cmd/init.go+++ b/cmd/init.go@@ -1068,11 +1068,38 @@ func initHTTPServer(cfg *Config, urlCfg *UrlConfig, i *i18n.I18n, fs stuffbin.FiuploadFsURI = ko.String("upload.filesystem.upload_uri")publicURL = ko.String("upload.s3.public_url"))++ // Sandbox uploaded media.+ uploadSecurityHdrs := func(next echo.HandlerFunc) echo.HandlerFunc {+ return func(c *echo.Context) error {+ // All uploaded media is sandboxed.+ c.Response().Header().Set("Content-Security-Policy", "sandbox")+ c.Response().Header().Set("X-Content-Type-Options", "nosniff")++ resp, err := echo.UnwrapResponse(c.Response())+ if err != nil {+ return err+ }++ resp.Before(func() {+ h := c.Response().Header()+ // Render images and PDFs inline; force a download for all other types.+ typ, _, _ := mime.ParseMediaType(h.Get("Content-Type"))+ if strings.HasPrefix(typ, "image/") || typ == "application/pdf" {+ h.Set("Content-Disposition", "inline")+ } else {+ h.Set("Content-Disposition", "attachment")+ }+ })+ return next(c)+ }+ }+switch {case uploadProvider == media.ProviderFilesystem && uploadFsURI != "":- srv.Static(uploadFsURI, ko.String("upload.filesystem.upload_path"))+ srv.Static(uploadFsURI, ko.String("upload.filesystem.upload_path"), uploadSecurityHdrs)case uploadProvider == media.ProviderS3 && strings.HasPrefix(publicURL, "/"):- srv.GET(path.Join(publicURL, "/:filepath"), app.ServeS3Media)+ srv.GET(path.Join(publicURL, "/:filepath"), app.ServeS3Media, uploadSecurityHdrs)}// Register all HTTP handlers.diff --git a/cmd/public.go b/cmd/public.goindex f0952957..b54e87c3 100644--- a/cmd/public.go+++ b/cmd/public.go@@ -277,7 +277,7 @@ func (a *App) ViewCampaignMessage(c *echo.Context) error {makeMsgTpl(a.i18n.T("globals.terms.error"), "", a.i18n.Ts("public.errorFetchingCampaign")))}- return c.HTML(http.StatusOK, string(msg.Body()))+ return renderSandboxedHTML(c, string(msg.Body()))}// SubscriptionPage renders the subscription management page and handles unsubscriptions.