The minimalistic document archiving platform.
refactor(config): remove support for wildcard '*' in trustedOrigins (#210)
Corentin Thomassetb13986e1e353
diff --git a/apps/papra-server/src/modules/app/auth/auth.models.test.ts b/apps/papra-server/src/modules/app/auth/auth.models.test.tsindex cd290353..19672d5d 100644--- a/apps/papra-server/src/modules/app/auth/auth.models.test.ts+++ b/apps/papra-server/src/modules/app/auth/auth.models.test.ts@@ -44,20 +44,5 @@ describe('auth models', () => {'http://localhost:3002',]);});-- test('if the user disables the trusted origins, by setting the trustedOrigins to *, the trustedOrigins are not enabled', () => {- const config = {- client: {- baseUrl: 'http://localhost:3000',- },- server: {- trustedOrigins: '*',- },- } as Config;-- const { trustedOrigins } = getTrustedOrigins({ config });-- expect(trustedOrigins).to.equal(undefined);- });});});diff --git a/apps/papra-server/src/modules/app/auth/auth.models.ts b/apps/papra-server/src/modules/app/auth/auth.models.tsindex 79295561..ab6edb4c 100644--- a/apps/papra-server/src/modules/app/auth/auth.models.ts+++ b/apps/papra-server/src/modules/app/auth/auth.models.ts@@ -32,6 +32,6 @@ export function getTrustedOrigins({ config }: { config: Config }) {const { trustedOrigins } = config.server;return {- trustedOrigins: trustedOrigins === '*' ? undefined : uniq([baseUrl, ...trustedOrigins]),+ trustedOrigins: uniq([baseUrl, ...trustedOrigins]),};}diff --git a/apps/papra-server/src/modules/config/config.schemas.test.ts b/apps/papra-server/src/modules/config/config.schemas.test.tsindex 33361bdf..f9e1d7d6 100644--- a/apps/papra-server/src/modules/config/config.schemas.test.ts+++ b/apps/papra-server/src/modules/config/config.schemas.test.ts@@ -26,8 +26,7 @@ describe('config schemas', () => {});describe('trustedOriginsSchema', () => {- test('this schema validates and coerces a comma separated string to an array of urls or a literal *', () => {- expect(trustedOriginsSchema.parse('*')).toEqual('*');+ test('this schema validates and coerces a comma separated string to an array of urls', () => {expect(trustedOriginsSchema.parse('http://localhost:3000')).toEqual(['http://localhost:3000']);expect(trustedOriginsSchema.parse('http://localhost:3000,http://localhost:3001')).toEqual(['http://localhost:3000',diff --git a/apps/papra-server/src/modules/config/config.schemas.ts b/apps/papra-server/src/modules/config/config.schemas.tsindex 5bd7a859..4aa88825 100644--- a/apps/papra-server/src/modules/config/config.schemas.ts+++ b/apps/papra-server/src/modules/config/config.schemas.ts@@ -9,7 +9,6 @@ export const booleanishSchema = z.pipe(z.boolean());export const trustedOriginsSchema = z.union([- z.literal('*'),z.array(z.string().url()),z.string().transform(value => value.split(',')).pipe(z.array(z.string().url())),]);diff --git a/apps/papra-server/src/modules/config/config.ts b/apps/papra-server/src/modules/config/config.tsindex ff6a9841..9c2ea28e 100644--- a/apps/papra-server/src/modules/config/config.ts+++ b/apps/papra-server/src/modules/config/config.ts@@ -48,7 +48,7 @@ export const configDefinition = {env: 'SERVER_BASE_URL',},trustedOrigins: {- doc: 'A comma separated list of origins that are trusted to make requests to the server, it\'ll include the baseUrl by default. You can set it to "*" to allow all origins (not recommended).',+ doc: 'A comma separated list of origins that are trusted to make requests to the server. The client baseUrl (CLIENT_BASE_URL) is automatically added by default, no need to add it to the list.',schema: trustedOriginsSchema,default: [],env: 'TRUSTED_ORIGINS',