Skip to content

Commit 05a1720

Browse files
authored
Merge pull request #17282 from github/support-ga-in-deprecated-versions
Fix CSP errors on older versions
2 parents d9b85f4 + 518ab47 commit 05a1720

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

middleware/csp.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ module.exports = async (req, res, next) => {
5656

5757
// Exception for Algolia instantsearch in deprecated Enterprise docs (Node.js era)
5858
if (versionSatisfiesRange(requestedVersion, '<=2.19') && versionSatisfiesRange(requestedVersion, '>2.12')) {
59-
csp.directives.scriptSrc.push("'unsafe-eval'")
59+
csp.directives.scriptSrc.push("'unsafe-eval'", "'unsafe-inline'", 'http://www.google-analytics.com', 'https://ssl.google-analytics.com')
60+
csp.directives.connectSrc.push('https://www.google-analytics.com')
61+
csp.directives.imgSrc.push('http://www.google-analytics.com', 'https://ssl.google-analytics.com')
6062
}
6163

6264
// Exception for search in deprecated Enterprise docs <=2.12 (static site era)

tests/routing/deprecated-enterprise-versions.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ describe('JS and CSS assets', () => {
169169
expect(result.get('Content-Type')).toBe('image/svg+xml; charset=utf-8')
170170
})
171171

172+
it('returns the expected node_modules', async () => {
173+
const result = await supertest(app)
174+
.get('/node_modules/algoliasearch/dist/algoliasearch.min.js')
175+
.set('Referrer', '/en/enterprise/2.17')
176+
177+
expect(result.statusCode).toBe(200)
178+
expect(result.get('x-is-archived')).toBe('true')
179+
expect(result.get('Content-Type')).toBe('application/javascript; charset=utf-8')
180+
})
181+
172182
it('returns the expected favicon', async () => {
173183
const result = await supertest(app)
174184
.get('/assets/images/site/favicon.svg')
@@ -179,7 +189,7 @@ describe('JS and CSS assets', () => {
179189
expect(result.get('Content-Type')).toBe('image/svg+xml; charset=utf-8')
180190
})
181191

182-
it('returns the expected CSS file ( <2.13 )', async () => {
192+
it('returns the expected CSS file ( <2.13 )', async () => {
183193
const result = await supertest(app)
184194
.get('/assets/stylesheets/application.css')
185195
.set('Referrer', '/en/enterprise/2.12')

0 commit comments

Comments
 (0)