Skip to content

Commit d8c750a

Browse files
Merge pull request #6358 from eisbilir/fix-security-headers
add csp header for tco
2 parents 69b103f + d46f467 commit d8c750a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/server/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ ts = moment(ts.timestamp).valueOf();
5050
const sw = `sw.js${process.env.NODE_ENV === 'production' ? '' : '?debug'}`;
5151
const swScope = '/challenges'; // we are currently only interested in improving challenges pages
5252

53+
const tcoPattern = new RegExp(/^tco\d{2}\.topcoder(?:-dev)?\.com$/i);
54+
5355
const EXTRA_SCRIPTS = [
5456
`<script type="application/javascript">
5557
if('serviceWorker' in navigator){
@@ -135,13 +137,14 @@ async function onExpressJsSetup(server) {
135137
res.header('Referrer-Policy', 'strict-origin-when-cross-origin');
136138
res.header('Permissions-Policy', 'geolocation=(), microphone=(), camera=()');
137139

138-
if (req.url.startsWith('/__community__/veterans') || req.hostname === 'veterans.topcoder.com') {
140+
if (req.url.startsWith('/__community__/veterans') || req.hostname === 'veterans.topcoder.com' || req.url.startsWith('/__community__/tco') || tcoPattern.test(req.hostname)) {
139141
res.header(
140142
'Content-Security-Policy',
141143
"default-src 'self';"
142144
+ " script-src 'report-sample' 'self' 'unsafe-inline' 'unsafe-eval'"
143145
+ ` ${config.CDN.PUBLIC}`
144146
+ ' http://www.google-analytics.com'
147+
+ ' https://www.google-analytics.com'
145148
+ ' https://43d132d5dbff47c59d9d53ad448f93c2.js.ubembed.com'
146149
+ ' https://assets.ubembed.com'
147150
+ ' https://assets.zendesk.com'
@@ -187,6 +190,7 @@ async function onExpressJsSetup(server) {
187190
+ ` ${config.URL.AUTH}`
188191
+ ' https://www.youtube.com;'
189192
+ " img-src 'self'"
193+
+ ' data:'
190194
+ ` ${config.CDN.PUBLIC}`
191195
+ ' https://cdn.segment.com'
192196
+ ' https://d1of0acg2orgco.cloudfront.net'
@@ -196,11 +200,14 @@ async function onExpressJsSetup(server) {
196200
+ ' https://heapanalytics.com'
197201
+ ' https://q.quora.com'
198202
+ ' https://topcoder-prod-media.s3.amazonaws.com'
203+
+ ' https://topcoder-dev-media.s3.amazonaws.com'
199204
+ ' https://www.facebook.com'
200205
+ ' https://www.google-analytics.com'
201206
+ ' https://www.google.com'
202207
+ ' https://www.googletagmanager.com'
203-
+ ' https://i.ytimg.com;'
208+
+ ' https://i.ytimg.com'
209+
+ ' https://images.contentful.com'
210+
+ ' https://d0.awsstatic.com/logos/;'
204211
+ " manifest-src 'self';"
205212
+ " media-src 'self';"
206213
+ ' report-uri https://623d4c23f90d055298b24042.endpoint.csper.io/?v=0;'

0 commit comments

Comments
 (0)