From a4d684a3e8af3a38abd75e83b6060b67e6ed1066 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Wed, 10 Mar 2021 17:01:42 +0530 Subject: [PATCH 1/3] Add allow list for Netlify redirect options --- .../src/create-redirects.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-plugin-netlify/src/create-redirects.js b/packages/gatsby-plugin-netlify/src/create-redirects.js index efaf6f6c75406..3d1637c029e14 100644 --- a/packages/gatsby-plugin-netlify/src/create-redirects.js +++ b/packages/gatsby-plugin-netlify/src/create-redirects.js @@ -12,8 +12,16 @@ export default async function writeRedirectsFile( const FILE_PATH = publicFolder(`_redirects`) - // Map redirect data to the format Netlify expects // https://www.netlify.com/docs/redirects/ + const NETLIFY_REDIRECT_KEYWORDS_ALLOWLIST = [ + `query`, + `conditions`, + `headers`, + `signed`, + `edge_handler`, + ] + + // Map redirect data to the format Netlify expects redirects = redirects.map(redirect => { const { fromPath, @@ -37,13 +45,17 @@ export default async function writeRedirectsFile( for (const key in rest) { const value = rest[key] + console.log(NETLIFY_REDIRECT_KEYWORDS_ALLOWLIST) + if (typeof value === `string` && value.includes(` `)) { console.warn( `Invalid redirect value "${value}" specified for key "${key}". ` + `Values should not contain spaces.` ) } else { - pieces.push(`${key}=${value}`) + if (NETLIFY_REDIRECT_KEYWORDS_ALLOWLIST.includes(key)) { + pieces.push(`${key}=${value}`) + } } } From 5d6adc860cbbfc9b778376a2725c29e2c566a029 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Wed, 10 Mar 2021 17:15:03 +0530 Subject: [PATCH 2/3] Remove console log --- packages/gatsby-plugin-netlify/src/create-redirects.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/gatsby-plugin-netlify/src/create-redirects.js b/packages/gatsby-plugin-netlify/src/create-redirects.js index 3d1637c029e14..c09f369c10f01 100644 --- a/packages/gatsby-plugin-netlify/src/create-redirects.js +++ b/packages/gatsby-plugin-netlify/src/create-redirects.js @@ -45,8 +45,6 @@ export default async function writeRedirectsFile( for (const key in rest) { const value = rest[key] - console.log(NETLIFY_REDIRECT_KEYWORDS_ALLOWLIST) - if (typeof value === `string` && value.includes(` `)) { console.warn( `Invalid redirect value "${value}" specified for key "${key}". ` + From 6f4bb18f033916f7cfff925a442bb719cbfa19d9 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Wed, 10 Mar 2021 19:14:54 +0530 Subject: [PATCH 3/3] Add Language and Country --- packages/gatsby-plugin-netlify/src/create-redirects.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/gatsby-plugin-netlify/src/create-redirects.js b/packages/gatsby-plugin-netlify/src/create-redirects.js index c09f369c10f01..816064bfdbcb8 100644 --- a/packages/gatsby-plugin-netlify/src/create-redirects.js +++ b/packages/gatsby-plugin-netlify/src/create-redirects.js @@ -19,6 +19,8 @@ export default async function writeRedirectsFile( `headers`, `signed`, `edge_handler`, + `Language`, + `Country`, ] // Map redirect data to the format Netlify expects