From 088b1420f29f0e480a54d4818a3f0b8511cb075a Mon Sep 17 00:00:00 2001 From: Feroz Salam Date: Fri, 7 Jul 2023 15:46:23 +0100 Subject: [PATCH 1/3] Trim whitespace when processing dids MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I had some issues when enabling a custom domain using the .well-known file method because of the EOL character – as the code currently stands, any `did` followed by an EOL character is passed for verification as: ``` "responseBody": { "did": "\n" } ``` The presence of the trailing newline character leads to the user receiving the error "The server gave an invalid response and may be out of date". I solved the issue by removing the EOL character from my `did` file, but it would be neater if this was done for the user. Signed-off-by: Feroz Salam --- packages/identity/src/handle/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/identity/src/handle/index.ts b/packages/identity/src/handle/index.ts index 8780437efa7..91f5561aa11 100644 --- a/packages/identity/src/handle/index.ts +++ b/packages/identity/src/handle/index.ts @@ -50,7 +50,7 @@ export class HandleResolver { const url = new URL('/.well-known/atproto-did', `https://${handle}`) try { const res = await fetch(url, { signal }) - const did = await res.text() + const did = (await res.text()).trim() if (typeof did === 'string' && did.startsWith('did:')) { return did } From 1c807a73b82022d53238ccefdca403a2dcdd04b8 Mon Sep 17 00:00:00 2001 From: Feroz Salam Date: Wed, 12 Jul 2023 11:25:06 +0100 Subject: [PATCH 2/3] Update did handling based on PR feedback - Read the file in text, strip out non-ASCII chars - Read in the first line of the file and strip any remaining newline characters --- packages/identity/src/handle/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/identity/src/handle/index.ts b/packages/identity/src/handle/index.ts index 91f5561aa11..f4aafde4404 100644 --- a/packages/identity/src/handle/index.ts +++ b/packages/identity/src/handle/index.ts @@ -50,7 +50,8 @@ export class HandleResolver { const url = new URL('/.well-known/atproto-did', `https://${handle}`) try { const res = await fetch(url, { signal }) - const did = (await res.text()).trim() + const asciiText = (await res.text()).replace(/[^\x00-\x7F]/g, "") + const did = asciiText.split('\n')[0].trim() if (typeof did === 'string' && did.startsWith('did:')) { return did } From 27bf7445da2468328b6ad2ace6bb7e6fa24b48e2 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 12 Sep 2023 14:04:55 -0700 Subject: [PATCH 3/3] identity: don't remove non-ASCII characters simplifies what we are normalizing: just take the first line and strip whitespace, don't try to remove any non-ASCII characters as well. --- packages/identity/src/handle/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/identity/src/handle/index.ts b/packages/identity/src/handle/index.ts index f4aafde4404..4048f963cd5 100644 --- a/packages/identity/src/handle/index.ts +++ b/packages/identity/src/handle/index.ts @@ -50,8 +50,7 @@ export class HandleResolver { const url = new URL('/.well-known/atproto-did', `https://${handle}`) try { const res = await fetch(url, { signal }) - const asciiText = (await res.text()).replace(/[^\x00-\x7F]/g, "") - const did = asciiText.split('\n')[0].trim() + const did = (await res.text()).split('\n')[0].trim() if (typeof did === 'string' && did.startsWith('did:')) { return did }