File tree 3 files changed +20
-5
lines changed
3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
12
12
getService ,
13
13
getSpaceId ,
14
14
articleVote ,
15
+ ALLOWED_DOMAINS ,
15
16
} from '../services/contentful' ;
16
17
17
18
const cors = require ( 'cors' ) ;
@@ -37,7 +38,11 @@ routes.use(
37
38
version,
38
39
} = req . params ;
39
40
const spaceId = getSpaceId ( spaceName ) ;
40
- res . redirect ( `https://${ ASSETS_DOMAIN } /spaces/${ spaceId } /environments/${ environment } /${ id } /${ version } /${ name } ` ) ;
41
+ if ( ! ALLOWED_DOMAINS . includes ( ASSETS_DOMAIN ) ) {
42
+ throw new Error ( 'Invalid domain detected!' ) ;
43
+ }
44
+ const url = new URL ( `https://${ ASSETS_DOMAIN } /spaces/${ spaceId } /environments/${ environment } /${ id } /${ version } /${ name } ` ) ;
45
+ res . redirect ( url . href ) ;
41
46
} ,
42
47
) ;
43
48
@@ -52,8 +57,12 @@ routes.use(
52
57
spaceName,
53
58
version,
54
59
} = req . params ;
60
+ if ( ! ALLOWED_DOMAINS . includes ( IMAGES_DOMAIN ) ) {
61
+ throw new Error ( 'Invalid domain detected!' ) ;
62
+ }
55
63
const spaceId = getSpaceId ( spaceName ) ;
56
- res . redirect ( `https://${ IMAGES_DOMAIN } /spaces/${ spaceId } /environments/${ environment } /${ id } /${ version } /${ name } ` ) ;
64
+ const url = new URL ( `https://${ IMAGES_DOMAIN } /spaces/${ spaceId } /environments/${ environment } /${ id } /${ version } /${ name } ` ) ;
65
+ res . redirect ( url . href ) ;
57
66
} ,
58
67
) ;
59
68
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ const PREVIEW_URL = 'https://preview.contentful.com/spaces';
21
21
export const ASSETS_DOMAIN = 'assets.ctfassets.net' ;
22
22
export const IMAGES_DOMAIN = 'images.ctfassets.net' ;
23
23
24
+ export const ALLOWED_DOMAINS = [ ASSETS_DOMAIN , IMAGES_DOMAIN ] ;
24
25
const MAX_FETCH_RETRIES = 5 ;
25
26
26
27
/**
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ import './style.scss';
44
44
/* global window, document */
45
45
46
46
const BASE_URL = config . URL . BASE ;
47
+ const VALID_BASE_URLS = [ 'https://www.topcoder-dev.com' , 'https://www.topcoder.com' ] ;
47
48
48
49
const MENU = [ {
49
50
title : 'Compete' ,
@@ -426,9 +427,13 @@ export default class TopcoderHeader extends React.Component {
426
427
ref = { ( input ) => { this . searchInput = input ; } }
427
428
onKeyPress = { ( event ) => {
428
429
if ( event . key === 'Enter' ) {
429
- window . location = `${ BASE_URL } /search/members?q=${
430
- encodeURIComponent ( event . target . value )
431
- } `;
430
+ if ( ! VALID_BASE_URLS . includes ( BASE_URL ) ) {
431
+ return ;
432
+ }
433
+ const query = event . target . value . trim ( ) ;
434
+ const url = new URL ( `${ BASE_URL } /search/members` ) ;
435
+ url . searchParams . append ( 'q' , query ) ;
436
+ window . location = url . href ;
432
437
}
433
438
} }
434
439
onBlur = { closeSearch }
You can’t perform that action at this time.
0 commit comments