Skip to content

Fedify fails to handle URL strings for icon property #420

@allouis

Description

@allouis

Summary

Fedify throws a JSON parsing error when processing ActivityPub objects where the icon property is a URL string instead of an Image object. This is valid according to ActivityStreams 2.0 specification but causes getIcon() to fail.

Expected Behavior

Fedify should handle the string and convert it into either an Image or a Link object

Both are valid per the ActivityStreams 2.0 specification.

Actual Behavior

When calling getIcon() on a Person object that has a direct URL string for icon, Fedify attempts to parse the PNG file content as JSON, resulting in a syntax error.

Reproducing

Here's an example Actor object that causes the issue:

  • https://links.bouncepaw.com/@bouncepaw
Full JSON-LD

{
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    "https://w3id.org/security/v1"
  ],
  "followers": "https://links.bouncepaw.com/followers",
  "following": "https://links.bouncepaw.com/following",
  "icon": "https://links.bouncepaw.com/static/pix/favicon.png",
  "id": "https://links.bouncepaw.com/@bouncepaw",
  "inbox": "https://links.bouncepaw.com/inbox",
  "name": "bouncepaw's links",
  "outbox": "https://links.bouncepaw.com/outbox",
  "preferredUsername": "bouncepaw",
  "publicKey": {
    "id": "https://links.bouncepaw.com/@bouncepaw#main-key",
    "owner": "https://links.bouncepaw.com/@bouncepaw",
    "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoID5jG9sKf6Dq0jHmxK4\ndHnDR+mTYEojzpW0WjSRLsbqQ3w1jxNXkvHeiSvNFFZy7AJ1X04k8yUsm3iWAMNS\n+2obgK2ZegsYx85Q2DGLJxv3H2MCAtKUeN6MMEVOPaSqFuEgAph7wsFMvoCHqVVV\nw/Kxp0zl2/YBOCRVZqdzwvgYJAm2MTKB/58tIkuSLV487/LTs/qShRyZATKVhtQf\n4goLVtI4SjcULlV6yUYC4wDMiJAXOLxX0WPxF6yupMuMKNRJcamHKSGgzkZiBHxZ\nsla2GOBdUZ1NYIv2RuIeWKmFK4hhYzJhAvgvGogiOTSR77b7Aa/ngdkYczKf5w7S\nxwIDAQAB\n-----END PUBLIC KEY-----\n"
  },
  "summary": "Bookmarks and whatnot. Закладки и всякое.",
  "type": "Person",
  "url": "https://links.bouncepaw.com/@bouncepaw"
}

You can reproduce the error by running:

const fedify = require('@fedify/fedify');
const person = await fedify.lookupObject('https://links.bouncepaw.com/@bouncepaw');
const icon = await person.getIcon(); // This errors

Error Details

Uncaught SyntaxError: Unexpected token '�', "�PNG
"... is not valid JSON

The error occurs because Fedify is trying to parse the PNG file content (which starts with the PNG magic bytes) as JSON.

Thoughts

The ActivityStreams vocabulary defines the "Range" icon as being Link or Image here https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon

The icon property in Fedify is only defined as Image - so the URL is being resolved and tried to turn into an Image. I wonder if expanding the range in Fedify to include Link would fix this? I'm not sure because I don't have a lot of context on how the codegen works

Environment

  • Fedify version: 1.8.8
  • Node.js version: v22.14.0
  • OS: Alpine Linux (Docker)

Metadata

Metadata

Assignees

No one assigned

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions