digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

@import overrides ResolvedContext LRU cache #537

Open F-Node-Karlsruhe opened 1 year ago

F-Node-Karlsruhe commented 1 year ago

When using two different contexts both with imports the first context sets the cache with the following value as activeCtx, which appears to be a generic value. The other context then uses the (same) cache and fails, as it does not find the properties.

processedContext activeCtx key: {"mappings":{},"inverse":null,"protected":{"id":true,"type":true,"VerifiableCredential":true,"VerifiablePresentation":true,"EcdsaSecp256k1Signature2019":true,"EcdsaSecp256r1Signature2019":true,"Ed25519Signature2018":true,"RsaSignature2018":true,"proof":true,"Ed25519VerificationKey2020":true,"Ed25519Signature2020":true},"processingMode":"json-ld-1.1","@version":1.1}

The code already warns that there can be cache issues with @import contexts https://github.com/digitalbazaar/jsonld.js/blob/main/lib/context.js#L386

If a processedImport is found it completely overrides the value instead of adding it to ctx https://github.com/digitalbazaar/jsonld.js/blob/main/lib/context.js#L364

Example of affected contexts:

  1. https://ssi.eecc.de/api/registry/context/productpassport
  2. https://ssi.eecc.de/api/registry/context/productpassport/powertool

Related issues: