Skip to content

fix(wac): read ACLs by expanded IRI, refuse ACLs that grant nothing (#631) - #632

Merged
melvincarvalho merged 2 commits into
gh-pagesfrom
wac-acl-jsonld-expansion
Oct 21, 2026
Merged

melvincarvalho merged 2 commits into
gh-pagesfrom
wac-acl-jsonld-expansion

Conversation

@melvincarvalho

@melvincarvalho melvincarvalho commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #631.

Problem

src/wac/parser.js read authorization properties by literal compact key (acl:agent, agent, …). A valid JSON-LD ACL in expanded form, or one using a prefix other than acl:, was accepted with 201 but parsed as granting nobody anything. The owner lost access to the resource and to the .acl itself. Turtle ACLs declaring a non-acl prefix had the same problem, since the Turtle converter compacts with the document's own prefixes.

Note: JSS has no jsonld dependency (the issue assumed one). The fix reuses the in-house expandUri from src/rdf/turtle.js, which keeps the #389 constraint: remote contexts are never fetched.

Changes

  • Parser: build the document's @context (object or array; string entries skipped), expand keys, @type and @id values to full IRIs, with @vocab fallback 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.
  • Agent classes are now normalised to full IRIs, as modes already were. checker.js and the MCP tools accept both forms; three test assertions updated to the full IRI.
  • Write guards: new grantsAccess() in the parser requires at least one authorization with a mode and an agent, agent class or group. A .acl PUT that fails it gets 400 (invalid JSON also 400); a PATCH whose result would fail it gets 409 and 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.
  • expandUri is exported from src/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, @context array with a remote entry, @vocab plus term definitions, Turtle with a wac: 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.

…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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 @vocab fallback, and normalizes agent classes/modes to full IRIs while keeping acl:/bare forms as fallbacks.
  • handlePut refuses an .acl body (after the existing JSON-LD media-type guard) that parses to no authorizations or is not valid JSON, returning 400.
  • expandUri is exported from src/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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

@melvincarvalho
melvincarvalho merged commit 59a8598 into gh-pages Oct 21, 2026
1 check passed
@melvincarvalho
melvincarvalho deleted the wac-acl-jsonld-expansion branch October 21, 2026 15:50
melvincarvalho added a commit that referenced this pull request Oct 21, 2026
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.
melvincarvalho added a commit that referenced this pull request Oct 21, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WAC: ACL parser reads literal acl: keys, so valid expanded JSON-LD ACLs grant nothing and lock the owner out

2 participants