Skip to content

Inconsistent encoding/decoding of identifiers with special characters #416

@mrkvon

Description

@mrkvon

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 of
  • https://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:

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

  1. set up a basic fedify server that accepts identifiers with URI-encoded special characters in URLs, e.g. /users/${encodeURIComponent(':|')}/some-endpoint
  2. set up followers collection endpoint with federation.setFollowersDispatcher
  3. request the followers of the special-character actor, e.g. GET https://base.url/users/%3A%7C/followers
  4. log the identifier in dispatcher callbacks, and see that it's partially decoded: %3A|
  5. see collection id and observe that one of the special characters in the URI is double-encoded: %253A%7C

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions