diff --git a/src/core/build/createWebpackConfig.ts b/src/core/build/createWebpackConfig.ts index 3b4cca27e..1db237c9e 100644 --- a/src/core/build/createWebpackConfig.ts +++ b/src/core/build/createWebpackConfig.ts @@ -223,10 +223,10 @@ export default function createWebpackConfig( // Generated JS file names (with nested folders). // There will be one main bundle, and one file per asynchronous chunk. filename: isProduction - ? "assets/js/[name].[chunkhash:8].js" + ? "assets/js/[name].[chunkhash].js" : "assets/js/[name].js", chunkFilename: isProduction - ? "assets/js/[name].[chunkhash:8].chunk.js" + ? "assets/js/[name].[chunkhash].chunk.js" : "assets/js/[name].chunk.js", // We inferred the "public path" (such as / or /my-project) from homepage. publicPath, @@ -357,7 +357,7 @@ export default function createWebpackConfig( options: { limit: 10000, name: isProduction - ? "assets/media/[name].[hash:8].[ext]" + ? "assets/media/[name].[hash].[ext]" : "assets/media/[name].[ext]", }, }, @@ -370,7 +370,7 @@ export default function createWebpackConfig( options: { modules: true, importLoaders: 2, - localIdentName: "[name]-[local]-[hash:base64:5]", + localIdentName: "[name]-[local]-[contenthash]", sourceMap: !disableSourcemaps, }, }, diff --git a/src/core/server/app/helpers/compileTrust.spec.ts b/src/core/server/app/helpers/compileTrust.spec.ts new file mode 100644 index 000000000..38f016466 --- /dev/null +++ b/src/core/server/app/helpers/compileTrust.spec.ts @@ -0,0 +1,30 @@ +import compileTrust from "./compileTrust"; + +it("parses boolean true", () => { + expect(compileTrust("true")).toStrictEqual(true); +}); + +it("parses boolean false", () => { + expect(compileTrust("false")).toStrictEqual(false); +}); + +it("parses a number", () => { + for (let i = 0; i < 100; i++) { + expect(compileTrust(`${i}`)).toStrictEqual(i); + } +}); + +it("parses a list of aliases", () => { + const aliases = "loopback, linklocal, uniquelocal"; + expect(compileTrust(aliases)).toStrictEqual(aliases); +}); + +it("parses an of address", () => { + const address = "10.0.0.1"; + expect(compileTrust(address)).toStrictEqual(address); +}); + +it("parses a list of addresses", () => { + const addresses = "10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7"; + expect(compileTrust(addresses)).toStrictEqual(addresses); +}); diff --git a/src/core/server/app/helpers/compileTrust.ts b/src/core/server/app/helpers/compileTrust.ts new file mode 100644 index 000000000..3593d8111 --- /dev/null +++ b/src/core/server/app/helpers/compileTrust.ts @@ -0,0 +1,19 @@ +function compileTrust(trust: string) { + if (!trust) { + return null; + } + + const lowercase = trust.toLowerCase(); + if (lowercase === "true" || lowercase === "false") { + return lowercase === "true"; + } + + const parsed = Number(trust); + if (!isNaN(parsed)) { + return parsed; + } + + return trust; +} + +export default compileTrust; diff --git a/src/core/server/app/helpers/index.ts b/src/core/server/app/helpers/index.ts new file mode 100644 index 000000000..981cbac94 --- /dev/null +++ b/src/core/server/app/helpers/index.ts @@ -0,0 +1,5 @@ +export { default as compileTrust } from "./compileTrust"; +export { default as Entrypoints } from "./entrypoints"; + +export * from "./hostname"; +export * from "./entrypoints"; diff --git a/src/core/server/app/index.ts b/src/core/server/app/index.ts index a34cf328f..ad83f9b42 100644 --- a/src/core/server/app/index.ts +++ b/src/core/server/app/index.ts @@ -22,6 +22,7 @@ import { PersistedQueryCache } from "coral-server/services/queries"; import { AugmentedRedis } from "coral-server/services/redis"; import TenantCache from "coral-server/services/tenant/cache"; +import { compileTrust } from "./helpers"; import { accessLogger, errorLogger } from "./middleware/logging"; import { metricsRecorder } from "./middleware/metrics"; import serveStatic from "./middleware/serveStatic"; @@ -111,7 +112,7 @@ function configureApplication(options: AppOptions) { // SSL was terminated correctly. const trust = options.config.get("trust_proxy"); if (trust) { - parent.set("trust proxy", trust); + parent.set("trust proxy", compileTrust(trust)); } // Setup the view config.