File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
dotcom-rendering/src/server/lib Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,13 @@ import type { Handler } from 'express';
5
5
const isStringTuple = ( _ : [ string , unknown ] ) : _ is [ string , string ] =>
6
6
typeof _ [ 1 ] === 'string' ;
7
7
8
+ const allowedOrigins = [
9
+ 'https://www.theguardian.com' ,
10
+ 'https://m.code.dev-theguardian.com' ,
11
+ 'https://m.thegulocal.com' ,
12
+ 'http://localhost:9000' ,
13
+ ] ;
14
+
8
15
/**
9
16
* Get DCR content from a `theguardian.com` URL.
10
17
* Takes in optional `X-Gu-*` headers to send.
@@ -17,6 +24,17 @@ async function getContentFromURL(
17
24
// searchParams will only work for the first set of query params because 'url' is already a query param itself
18
25
const searchparams = url . searchParams . toString ( ) ;
19
26
27
+ // Prevent requests to unknown origins
28
+ if ( ! allowedOrigins . includes ( url . origin ) ) {
29
+ throw new Error (
30
+ `Origin ${
31
+ url . origin
32
+ } is not allowed. Allowed origins are: ${ allowedOrigins . join (
33
+ ', ' ,
34
+ ) } `,
35
+ ) ;
36
+ }
37
+
20
38
// Reconstruct the parsed url adding .json?dcr which we need to force dcr to return json
21
39
const jsonUrl = `${ url . origin } ${ url . pathname } .json?dcr=true&${ searchparams } ` ;
22
40
You can’t perform that action at this time.
0 commit comments