Skip to content

Commit

Permalink
Trim whitespace when processing dids (#1299)
Browse files Browse the repository at this point in the history
* Trim whitespace when processing dids

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": "<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 <[email protected]>

* 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

* 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.

---------

Signed-off-by: Feroz Salam <[email protected]>
Co-authored-by: bnewbold <[email protected]>
  • Loading branch information
ferozsalam and bnewbold authored Oct 5, 2023
1 parent 88a23d4 commit 326d849
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/identity/src/handle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()).split('\n')[0].trim()
if (typeof did === 'string' && did.startsWith('did:')) {
return did
}
Expand Down

0 comments on commit 326d849

Please sign in to comment.