Repository navigation
fix(wac): read ACLs by expanded IRI, refuse ACLs that grant nothing (#631) - #632
Conversation
…631) The ACL parser matched authorization properties by their literal compact keys (acl:agent, agent, ...). A valid JSON-LD ACL in expanded form, or one using any prefix other than acl:, was accepted on PUT but parsed as granting nobody anything, locking the owner out of the resource and of the .acl. Parser: build the document's @context (object or array; remote entries are skipped, as in #389), expand every key, @type and @id value through the converter's expandUri (now exported) with @vocab fallback, and read the properties by their full IRI. The acl:-prefixed and bare-key forms remain as fallbacks. Agent classes are now normalised to full IRIs like modes already were; the checker and MCP tools accept both forms. Turtle ACLs that declare a non-acl prefix are fixed by the same path. PUT: an .acl body that parses to zero authorizations is refused with 400 instead of being stored. Tests: expanded form, alternate prefix, @context array, @vocab + term definitions, Turtle with a non-acl prefix, agent-class normalisation, and an integration test for the PUT guard and the owner keeping access.
There was a problem hiding this comment.
🔵 Needs a closer look
The change alters security-critical WAC authorization parsing and ACL write validation, where a subtle regression could grant or deny access incorrectly, so it warrants final human review.
No open issues 🎉
What changed in this PR
This PR fixes a WAC authorization lockout (#631) where src/wac/parser.js read ACL properties by literal compact keys (acl:agent, agent, …). Valid JSON-LD ACLs in expanded form or using a non-acl: prefix were accepted (201) but parsed as granting nobody anything, silently locking the owner out of the resource and its .acl. The fix interprets the document's @context and reads properties by full IRI, reusing the in-house expandUri from src/rdf/turtle.js so no jsonld dependency or remote-context fetching is introduced (preserving the #389 invariant). It also adds a PUT-time guard that rejects ACL bodies that yield zero authorizations or invalid JSON.
Changes:
- Parser now builds/merges the document
@context(object or array; string/remote entries skipped), expands keys,@type, and value IRIs to full IRIs with a@vocabfallback, and normalizes agent classes/modes to full IRIs while keepingacl:/bare forms as fallbacks. handlePutrefuses an.aclbody (after the existing JSON-LD media-type guard) that parses to no authorizations or is not valid JSON, returning400.expandUriis exported fromsrc/rdf/turtle.js(behavior unchanged) and 9 new tests cover expanded/alternate-prefix/@context-array/@vocab/Turtle/agent-class cases plus PUT-guard integration.
| File | Description |
|---|---|
| src/wac/parser.js | Adds context merging and IRI expansion (mergeContext, expandTerm, expandNode, aclProp); reads ACL properties by full IRI; normalizes agent classes/modes to full IRIs. |
| src/handlers/resource.js | Adds a PUT guard that rejects .acl bodies that are invalid JSON or yield zero authorizations, to prevent silent self-lockout. |
| test/wac.test.js | Updates 3 agent-class assertions to full IRIs and adds 9 tests for JSON-LD expansion and the PUT guard. |
Review effort: Balanced
The PUT guard counted authorizations, so an authorization naming an agent but no mode (or a mode but no agent) was still stored and locked the owner out. Add grantsAccess(): at least one authorization must have a mode and an agent, agent class or group. PUT answers 400; PATCH on an .acl whose result would grant nothing answers 409 and leaves the stored ACL untouched. Tests: agent-without-mode, mode-without-agent, and a PATCH that deletes the only agent.
There was a problem hiding this comment.
🔵 Needs a closer look
It rewrites the WAC ACL parsing path and adds write-time access-control guards, a security-critical area where a subtle regression could cause lockout or unintended access, warranting final human review.
No open issues 🎉
Review effort: Balanced
Since 0.0.221: - WAC: ACLs are read as JSON-LD, not by literal acl: keys (#631, #632). Expanded form, any prefix, @context arrays and @vocab now authorize the same requests as the compact form; the Turtle path with a non-acl prefix is fixed too. Agent classes are normalised to full IRIs like modes. Fixes a silent owner lockout seen with SolidOS, whose first ACL PUT retry serialised in expanded form. - WAC write guards: a .acl PUT whose document grants no mode to any agent, agent class or group is refused with 400 (invalid JSON too); a PATCH whose result would grant nothing is refused with 409 and the stored ACL is left untouched. - rdf/turtle: expandUri is exported for reuse; behaviour unchanged.
Since 0.0.221: - WAC: ACLs are read as JSON-LD, not by literal acl: keys (#631, #632). Expanded form, any prefix, @context arrays and @vocab now authorize the same requests as the compact form; the Turtle path with a non-acl prefix is fixed too. Agent classes are normalised to full IRIs like modes. Fixes a silent owner lockout seen with SolidOS, whose first ACL PUT retry serialised in expanded form. - WAC write guards: a .acl PUT whose document grants no mode to any agent, agent class or group is refused with 400 (invalid JSON too); a PATCH whose result would grant nothing is refused with 409 and the stored ACL is left untouched. - rdf/turtle: expandUri is exported for reuse; behaviour unchanged.
Fixes #631.
Problem
src/wac/parser.jsread authorization properties by literal compact key (acl:agent,agent, …). A valid JSON-LD ACL in expanded form, or one using a prefix other thanacl:, was accepted with201but parsed as granting nobody anything. The owner lost access to the resource and to the.aclitself. Turtle ACLs declaring a non-aclprefix had the same problem, since the Turtle converter compacts with the document's own prefixes.Note: JSS has no
jsonlddependency (the issue assumed one). The fix reuses the in-houseexpandUrifromsrc/rdf/turtle.js, which keeps the #389 constraint: remote contexts are never fetched.Changes
@context(object or array; string entries skipped), expand keys,@typeand@idvalues to full IRIs, with@vocabfallback for bare terms, and read properties by full IRI.acl:-prefixed and bare keys remain as fallbacks, so every ACL already on disk parses as before.checker.jsand the MCP tools accept both forms; three test assertions updated to the full IRI.grantsAccess()in the parser requires at least one authorization with a mode and an agent, agent class or group. A.aclPUT that fails it gets400(invalid JSON also400); a PATCH whose result would fail it gets409and the stored ACL is left untouched. Counting authorizations alone was not enough: an authorization naming an agent but no mode still locked the owner out.expandUriis exported fromsrc/rdf/turtle.js; its behaviour is unchanged.Not included: a guard against removing the writer's own Control. That is a policy choice and can be a follow-up.
Tests
12 new cases in
test/wac.test.js: expanded form, alternate prefix,@contextarray with a remote entry,@vocabplus term definitions, Turtle with awac:prefix, agent-class normalisation, an integration test that PUTs an expanded ACL and confirms the owner keeps access and the public does not, and the rejection paths (no authorizations, agent without mode, mode without agent, PATCH deleting the only agent, invalid JSON).npm test: 1083 pass, 0 fail.