diff --git a/utils/subpath.go b/utils/subpath.go index 6c2304d43f..457627af30 100644 --- a/utils/subpath.go +++ b/utils/subpath.go @@ -70,13 +70,13 @@ func UpdateAssetsSubpath(subpath string) error { script := fmt.Sprintf("window.publicPath='%s'", newPath) scriptHash := sha256.Sum256([]byte(script)) - reCSP := regexp.MustCompile(``) + reCSP := regexp.MustCompile(``) if results := reCSP.FindAllString(newRootHtml, -1); len(results) == 0 { return fmt.Errorf("failed to find 'Content-Security-Policy' meta tag to rewrite") } newRootHtml = reCSP.ReplaceAllLiteralString(newRootHtml, fmt.Sprintf( - ``, + ``, base64.StdEncoding.EncodeToString(scriptHash[:]), )) diff --git a/utils/subpath_test.go b/utils/subpath_test.go index 4d8d05506c..66641e00ee 100644 --- a/utils/subpath_test.go +++ b/utils/subpath_test.go @@ -67,7 +67,7 @@ func TestUpdateAssetsSubpath(t *testing.T) { baseManifestJson, }, { - "content security policy not found", + "content security policy not found (missing quotes)", contentSecurityPolicyNotFoundHtml, baseCss, baseManifestJson, @@ -77,6 +77,17 @@ func TestUpdateAssetsSubpath(t *testing.T) { baseCss, baseManifestJson, }, + { + "content security policy not found (missing unsafe-eval)", + contentSecurityPolicyNotFound2Html, + baseCss, + baseManifestJson, + "/subpath", + fmt.Errorf("failed to find 'Content-Security-Policy' meta tag to rewrite"), + contentSecurityPolicyNotFound2Html, + baseCss, + baseManifestJson, + }, { "subpath", baseRootHtml, @@ -215,21 +226,23 @@ func TestGetSubpathFromConfig(t *testing.T) { } } -const contentSecurityPolicyNotFoundHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` +const contentSecurityPolicyNotFoundHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` -const baseRootHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` +const contentSecurityPolicyNotFound2Html = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` + +const baseRootHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` const baseCss = `@font-face{font-family:FontAwesome;src:url(/static/files/674f50d287a8c48dc19ba404d20fe713.eot);src:url(/static/files/674f50d287a8c48dc19ba404d20fe713.eot?#iefix&v=4.7.0) format("embedded-opentype"),url(/static/files/af7ae505a9eed503f8b8e6982036873e.woff2) format("woff2"),url(/static/files/fee66e712a8a08eef5805a46892932ad.woff) format("woff"),url(/static/files/b06871f281fee6b241d60582ae9369b9.ttf) format("truetype"),url(/static/files/677433a0892aaed7b7d2628c313c9775.svg#fontawesomeregular) format("svg");font-weight:400;font-style:normal}` -const subpathRootHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` +const subpathRootHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` const subpathCss = `@font-face{font-family:FontAwesome;src:url(/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot);src:url(/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot?#iefix&v=4.7.0) format("embedded-opentype"),url(/subpath/static/files/af7ae505a9eed503f8b8e6982036873e.woff2) format("woff2"),url(/subpath/static/files/fee66e712a8a08eef5805a46892932ad.woff) format("woff"),url(/subpath/static/files/b06871f281fee6b241d60582ae9369b9.ttf) format("truetype"),url(/subpath/static/files/677433a0892aaed7b7d2628c313c9775.svg#fontawesomeregular) format("svg");font-weight:400;font-style:normal}` -const newSubpathRootHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` +const newSubpathRootHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` const newSubpathCss = `@font-face{font-family:FontAwesome;src:url(/nested/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot);src:url(/nested/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot?#iefix&v=4.7.0) format("embedded-opentype"),url(/nested/subpath/static/files/af7ae505a9eed503f8b8e6982036873e.woff2) format("woff2"),url(/nested/subpath/static/files/fee66e712a8a08eef5805a46892932ad.woff) format("woff"),url(/nested/subpath/static/files/b06871f281fee6b241d60582ae9369b9.ttf) format("truetype"),url(/nested/subpath/static/files/677433a0892aaed7b7d2628c313c9775.svg#fontawesomeregular) format("svg");font-weight:400;font-style:normal}` -const resetRootHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` +const resetRootHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` const baseManifestJson = `{ "icons": [ diff --git a/web/static.go b/web/static.go index 6c56b7a06d..57267ab80a 100644 --- a/web/static.go +++ b/web/static.go @@ -23,7 +23,9 @@ var robotsTxt = []byte("User-agent: *\nDisallow: /\n") func (w *Web) InitStatic() { if *w.ConfigService.Config().ServiceSettings.WebserverMode != "disabled" { - utils.UpdateAssetsSubpathFromConfig(w.ConfigService.Config()) + if err := utils.UpdateAssetsSubpathFromConfig(w.ConfigService.Config()); err != nil { + mlog.Error("Failed to update assets subpath from config", mlog.Err(err)) + } staticDir, _ := fileutils.FindDir(model.CLIENT_DIR) mlog.Debug(fmt.Sprintf("Using client directory at %v", staticDir))