Skip to content

fix(didmailto): escape an email address the way a DID requires - #96

Merged
alanshaw merged 1 commit into
mainfrom
ash/fix/did-mailto-escaping
Nov 23, 2026
Merged

alanshaw merged 1 commit into
mainfrom
ash/fix/did-mailto-escaping

Conversation

@alanshaw

Copy link
Copy Markdown
Member

A did:mailto is built from an email address, and some characters that are legal in an address are not legal in a DID. The constructor left ~ unescaped and wrote a space as +, so an address containing either produced an invalid DID. fil-forge/ucantone#83 makes DID parsing enforce the DID syntax, after which such a DID would no longer decode from a token.

  • Every character a DID cannot carry is now percent-encoded. user~name@example.com becomes did:mailto:example.com:user%7Ename.
  • Existing DIDs are unchanged unless the address contains ~ or a space. Other characters, such as +, were already encoded the same way.
  • Reading the email back out of a malformed did:mailto returns an error. A DID with only a domain, or with extra segments, used to cause a panic.

This passes on the current ucantone version and against #83, so it can merge first.

🤖 Generated with Claude Code

New escaped the parts of the address with query escaping, which leaves "~"
as it is and writes a space as "+". Neither character is allowed in a DID.
Every character outside letters, digits, ".", "-" and "_" is now
percent-encoded, and the result is checked by did.Parse.

Email returns an error, where it used to panic, for a mailto DID that does
not have exactly a domain and a local part.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 12:47
@alanshaw alanshaw self-assigned this Nov 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@alanshaw

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T13:00:33.919300Z 09d3b6c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

alanshaw added a commit to fil-forge/ucantone that referenced this pull request Nov 23, 2026
Parsing a DID accepted any string that started with `did:`, so
`did:web:` with nothing after it, or a DID with a space in it, counted
as valid. Parsing now checks the string against the [DID
syntax](https://www.w3.org/TR/did-core/#did-syntax):

- **Method:** lower-case letters and digits.
- **Identifier:** letters, digits, `.`, `-`, `_` and percent-escapes, in
segments separated by colons, and not ending with a colon.

A string with a path, query or fragment is a DID URL and is refused.

Building a DID from a method and an identifier applies the same check
and now returns an error.

**This is a breaking change,** in two ways:

- DIDs are decoded from tokens and DID documents through the same check,
so a token or document carrying a malformed DID no longer decodes.
- Code that builds a DID from a method and an identifier has to handle
the new error. Outside this repo that is one place in hilt and one in
libforge, which fil-forge/libforge#96 removes.

The hard-coded DIDs in the other Forge repos all conform. The one place
that could produce a DID that does not is the `did:mailto` constructor
in libforge, fixed in fil-forge/libforge#96.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 09d3b6cbf4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@alanshaw
alanshaw merged commit 8dd0cb7 into main Nov 23, 2026
8 checks passed
alanshaw added a commit to fil-forge/piri that referenced this pull request Nov 23, 2026
Updates ucantone and libforge to their current versions. No code here
needed to change.

What the new versions bring:

- **Stricter DID parsing.** A DID is checked against the DID syntax when
it is parsed or decoded, so a token or DID document carrying a malformed
DID no longer decodes (fil-forge/ucantone#83).
- **Stricter `did:web` resolution.** A `did:web` whose host is an IP
address, or is not a well-formed host name, no longer resolves
(fil-forge/ucantone#82).
- **`did:mailto` escaping.** An email address with `~` or a space now
produces a valid DID (fil-forge/libforge#96).

This goes in ahead of #244, which moves the node to a `did:web` identity
and needs the same versions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
alanshaw added a commit to fil-forge/hilt that referenced this pull request Nov 23, 2026
Updates ucantone and libforge to their current versions, with the two
changes hilt needs to build and pass on them.

What the new versions bring:

- **Stricter DID parsing.** A DID is checked against the DID syntax when
it is parsed or decoded, so a token or DID document carrying a malformed
DID no longer decodes (fil-forge/ucantone#83).
- **Stricter `did:web` resolution.** A `did:web` whose host is an IP
address, or is not a well-formed host name, no longer resolves
(fil-forge/ucantone#82).
- **`did:mailto` escaping.** An email address with `~` or a space now
produces a valid DID (fil-forge/libforge#96).

What changed here:

- **The DID resolution test addresses its test server as `localhost`.**
It used the server's `127.0.0.1` address, which no longer resolves.
- **Building the DID of a tenant's wrapping key handles a new error.**
Building a DID can now fail on a malformed identifier. This one is
always the encoding of a key, so the error cannot occur.

Not run: the integration tests, which need the local stack.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants