From a59fa417439ec2f9b6b413e42997c249a13546e1 Mon Sep 17 00:00:00 2001 From: Deepjyoti Date: Tue, 1 Oct 2024 13:44:44 +0530 Subject: [PATCH] fix: failing tests for domain parse util function (#931) * fix: failing tests for domain parse util function This commit fixes the updated domain parse util function (that uses tldts) to make sure all tests pass. * Revert "fix: failing tests for domain parse util function" This reverts commit b7e0f8e6cf888b97ddcb73122c2f06484b1b49ce. * Fix issues with tldts not parsing private domains like ec2 --- lib/build/utils.js | 12 +++++++++++- lib/ts/utils.ts | 12 +++++++++++- package-lock.json | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/build/utils.js b/lib/build/utils.js index f24fba2d7..1363e2355 100644 --- a/lib/build/utils.js +++ b/lib/build/utils.js @@ -319,8 +319,18 @@ function getTopLevelDomainForSameSiteResolution(url) { // we treat these as the same TLDs since we can use sameSite lax for all of them. return "localhost"; } - let parsedURL = tldts_1.parse(hostname); + // Before `tldts`, `psl` was being used and that library automatically + // handled parsing private domains. With `tldts`, `allowPrivateDomains` is + // required to be passed to handle that. + // + // This is important for parsing ec2 public URL's that were initially + // reported to be breaking in the following issue: + // https://github.com/supertokens/supertokens-python/issues/394 + let parsedURL = tldts_1.parse(hostname, { allowPrivateDomains: true }); if (!parsedURL.domain) { + // If the URL is an AWS public URL, return the entire URL since it is + // considered a suffix entirely (instead of just amazonaws.com). This + // was initially reported in https://github.com/supertokens/supertokens-python/issues/394 if (hostname.endsWith(".amazonaws.com") && parsedURL.publicSuffix === hostname) { return hostname; } diff --git a/lib/ts/utils.ts b/lib/ts/utils.ts index 694b8bfd7..a19cba132 100644 --- a/lib/ts/utils.ts +++ b/lib/ts/utils.ts @@ -345,8 +345,18 @@ export function getTopLevelDomainForSameSiteResolution(url: string): string { return "localhost"; } - let parsedURL = parse(hostname); + // Before `tldts`, `psl` was being used and that library automatically + // handled parsing private domains. With `tldts`, `allowPrivateDomains` is + // required to be passed to handle that. + // + // This is important for parsing ec2 public URL's that were initially + // reported to be breaking in the following issue: + // https://github.com/supertokens/supertokens-python/issues/394 + let parsedURL = parse(hostname, { allowPrivateDomains: true }); if (!parsedURL.domain) { + // If the URL is an AWS public URL, return the entire URL since it is + // considered a suffix entirely (instead of just amazonaws.com). This + // was initially reported in https://github.com/supertokens/supertokens-python/issues/394 if (hostname.endsWith(".amazonaws.com") && parsedURL.publicSuffix === hostname) { return hostname; } diff --git a/package-lock.json b/package-lock.json index b8fec03d5..2b3538590 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "supertokens-node", - "version": "20.1.2", + "version": "20.1.3", "license": "Apache-2.0", "dependencies": { "buffer": "^6.0.3",