LemmyNet / lemmy

🐀 A link aggregator and forum for the fediverse
https://join-lemmy.org
GNU Affero General Public License v3.0
13.21k stars 876 forks source link

[Bug]: JSON-LD expansion/compaction doesn't parse "sensitive" and "expires" properties correctly #5073

Closed MidnightLightning closed 2 weeks ago

MidnightLightning commented 2 weeks ago

Requirements

Summary

The JSON-LD context file hosted at https://join-lemmy.org/context.json defines several custom fields, including sensitive and expires. That context file seems to be trying to add those properties to the ActivityStream vocabulary via the prefix as:. That prefix is commonly used for ActivityStream, but because the context file doesn't actually define the prefix, it's not doing what is expected.

Steps to Reproduce

Take this sample JSON-LD document which is similar to the Actor fragments Lemmy presents via the ActivityPub API endpoints:

{
    "@context": [
        "https://join-lemmy.org/context.json",
        "https://www.w3.org/ns/activitystreams"
    ],
    "type": "Group",
    "id": "https://hexbear.net/c/mutual_aid",
    "preferredUsername": "mutual_aid",
    "inbox": "https://hexbear.net/c/mutual_aid/inbox",
    "followers": "https://hexbear.net/c/mutual_aid/followers",
    "sensitive": false,
    "attributedTo": "https://hexbear.net/c/mutual_aid/moderators",
    "expires": "January 2030",
    "postingRestrictedToMods": false
}

put it into the JSON-LD Playground and pick "Expanded". Note that fields like attributedTo get expanded to https://www.w3.org/ns/activitystreams#attributedTo (correct), but sensitive gets expanded to as:sensitive (incorrect).

This incorrect mapping leads to other issues if the receiving application wishes to do other JSON-LD transformations to the object (e.g. Compact it with different aliases).

Technical Details

The contents of https://join-lemmy.org/context.json is currently:

{
  "@context": [
    "https://w3id.org/security/v1",
    {
      "lemmy": "https://join-lemmy.org/ns#",
      "litepub": "http://litepub.social/ns#",
      "pt": "https://joinpeertube.org/ns#",
      "sc": "http://schema.org/",
      "ChatMessage": "litepub:ChatMessage",
      "commentsEnabled": "pt:commentsEnabled",
      "sensitive": "as:sensitive",
      "matrixUserId": "lemmy:matrixUserId",
      "postingRestrictedToMods": "lemmy:postingRestrictedToMods",
      "removeData": "lemmy:removeData",
      "stickied": "lemmy:stickied",
      "moderators": {
        "@type": "@id",
        "@id": "lemmy:moderators"
      },
      "expires": "as:endTime",
      "distinguished": "lemmy:distinguished",
      "language": "sc:inLanguage",
      "identifier": "sc:identifier"
    }
  ]
}

They need to be updated to be:

{
  "@context": [
    "https://w3id.org/security/v1",
    {
      "lemmy": "https://join-lemmy.org/ns#",
      "litepub": "http://litepub.social/ns#",
      "as": "https://www.w3.org/ns/activitystreams#",
      "pt": "https://joinpeertube.org/ns#",
      "sc": "http://schema.org/",
      "ChatMessage": "litepub:ChatMessage",
      "commentsEnabled": "pt:commentsEnabled",
      "sensitive": "as:sensitive",
      "matrixUserId": "lemmy:matrixUserId",
      "postingRestrictedToMods": "lemmy:postingRestrictedToMods",
      "removeData": "lemmy:removeData",
      "stickied": "lemmy:stickied",
      "moderators": {
        "@type": "@id",
        "@id": "lemmy:moderators"
      },
      "expires": "as:endTime",
      "distinguished": "lemmy:distinguished",
      "language": "sc:inLanguage",
      "identifier": "sc:identifier"
    }
  ]
}

(one additional alias line added after "litepub")

Version

N/A

Lemmy Instance URL

https://join-lemmy.org/context.json

MidnightLightning commented 2 weeks ago

This issue seems to be similar to #2600 , but the file referenced in this comment is no longer at that location, so I cannot submit a patch for it.

Nutomic commented 2 weeks ago

Lemmy doesnt support json-ld, it only uses plain json. The context is now defined in this file so please make a pull request.

Edit: expires is already changed to end_time in the main branch, but it will be a few months before that change gets released.