diff --git a/packages/core/src/__tests__/Uri.spec.ts b/packages/core/src/__tests__/Uri.spec.ts index 4e832db94..a02bbae06 100644 --- a/packages/core/src/__tests__/Uri.spec.ts +++ b/packages/core/src/__tests__/Uri.spec.ts @@ -78,4 +78,10 @@ describe("Uri", () => { expect(uri.authority).toEqual("authority"); expect(uri.path).toEqual("something?uri=wrap://something/something2"); }); + + it("Shouldn't accept authorities that don't start with alphanumeric characters", () => { + expect(() => { + new Uri("../invalid/path"); + }).toThrow(/URI authority must start with an alphanumeric character or an underscore\./); + }); }); diff --git a/packages/core/src/types/Uri.ts b/packages/core/src/types/Uri.ts index 73d5ccd13..bd138ba10 100644 --- a/packages/core/src/types/Uri.ts +++ b/packages/core/src/types/Uri.ts @@ -175,6 +175,18 @@ export class Uri { // Extract the authority and path const authority = parts[0]; + + // Authority should begin with a word character (alphanumeric, underscore) + const validAuthorityRegExp = /^\w.*/; + if (!validAuthorityRegExp.test(authority)) { + return ResultErr( + Error( + `URI authority must start with an alphanumeric character or an underscore.\n` + + `Invalid URI Received: ${input}` + ) + ); + } + const path = parts.slice(1).join("/"); if (!path) {