-
-
Notifications
You must be signed in to change notification settings - Fork 82
Description
Summary
Special characters in {identifier}
don't get decoded, leading to inconsistent behaviour, including not being decoded in callbacks, and being double URI-encoded in collections.
Background
I use fedify to add a layer of ActivityPub on top of Solid Pod. This is achieved by hosting actor and its webfinger on a Solid Pod, and providing ActivityPub endpoints by the agent layer, on a different domain; with {identifier}
being the URI of the actor. (and yes, it works)
Expected Behavior
Special characters in {identifier}
get decoded in callbacks, and then encoded only once in collection id.
Actual Behavior
When my identifiers have URI-encoded special characters, they don't get decoded. Initially I assumed it was not an issue, as I decodeURIComponent
'd the identifier manually.
e.g. template /users/{identifier}/inbox
, together with URI https://agent.example/users/https%3A%2F%2Fsolid.example%2Factivitypub%2Factor/inbox
yield identifier https%3A%2F%2Fsolid.example%2Factivitypub%2Factor
instead of https://solid.example/activitypub/actor
However, when trying to produce a collection (e.g. followers), its {identifier}
becomes double-URI-encoded, instead of being just encoded once, e.g.
federation
.setFollowersDispatcher(
`/users/{identifier}/followers`,
async (ctx, identifier, cursor) => {
// implementation
},
)
result collection id
is
https://agent.example/users/https%253A%252F%252Fsolid.example%252Factivitypub%252Factor/followers
instead ofhttps://agent.example/users/https%3A%2F%2Fsolid.example%2Factivitypub%2Factor/followers
Please note the double encoding.
Environment
OS: Arch Linux
Runtime: Node.js
Runtime version: 22.17.1
Logs / Screenshots
I have already narrowed the issue down to the two libraries that are being used for parsing and generating URIs:
uri-template-router
does not decode special characters, which I have reported in Inconsistent handling of URI-encoded special characters awwright/uri-template-router#11.url-template
encodes URI components correctly, leading to double encoding of some special characters (additional encoding of %) in case of collections.
If this observation is not sufficient to identify the issue, or is misguided, I will provide logs or screenshots.
Until the above issue is addressed, a possible mitigation could be to swap {identifier}
in templates to {+identifier}
and decode the results with decodeURIComponent
. It is not sufficient to just do the decoding, because the uri-template-router
library with {identifier}
decodes the URIs inconsistently (see the linked issue for details).
Steps to Reproduce
- set up a basic fedify server that accepts identifiers with URI-encoded special characters in URLs, e.g.
/users/${encodeURIComponent(':|')}/some-endpoint
- set up followers collection endpoint with
federation.setFollowersDispatcher
- request the followers of the special-character actor, e.g.
GET https://base.url/users/%3A%7C/followers
- log the identifier in dispatcher callbacks, and see that it's partially decoded:
%3A|
- see collection id and observe that one of the special characters in the URI is double-encoded:
%253A%7C