Skip to content

Test against @casl/ability 7.1.3 and recommend 7.1.3+ for untrusted subjects - #19

Open
ak-itani wants to merge 2 commits into
mainfrom
claude/casl-ability-711-note
Open

ak-itani wants to merge 2 commits into
mainfrom
claude/casl-ability-711-note

Conversation

@ak-itani

Copy link
Copy Markdown
Contributor

Closes #8. Closes #10.

What and why

Upstream @casl/ability closed two ways for a plain object parsed from JSON to name its own subject type:

ability.can('read', JSON.parse(x)) with can('read', 'Invoice') 7.0.1 7.1.2 7.1.3
{"__caslSubjectType__":"Invoice"} true throws "Untrusted subject type" throws
{"constructor":{"name":"Invoice"}} true true false

subject('WorkItem', parsed) blocks both on every version.

As decided in #8, the peer range stays ^6.7.0 || ^7.0.0. Instead:

  • Docs: docs/browser.md and packages/casl-net/README.md recommend 7.1.3 or later whenever the checked objects come from outside the app's code. They explain both forged-type paths and tell apps on 6.7/7.0 to always pass parsed objects through subject(). A second paragraph says to keep one copy of @casl/ability (see below).
  • Test pin: the compatibility test and the browser package's dev dependency go from 7.0.1 to 7.1.3, with lockfiles regenerated by npm.
  • Test install: tests/casl-compat/.npmrc sets install-links=true. From 7.1.1, subject() tags an object for the copy of @casl/ability that ran it. The symlinked casl-net resolved packages/casl-net's own dev copy, while the test's subject() came from the test's copy, so on 7.1.3 every check threw "Untrusted subject type". Installing casl-net as a copy makes it share the test's @casl/ability, as it would in an app (npm ls shows it as deduped). CI's steps are unchanged.
  • CHANGELOG: an ## Unreleased section with Documentation and Tests entries. Move or drop it if you prefer to write entries at release time.

The .NET library isn't affected. Ability.DetectSubjectType never reads a type name from an object's data, and SubjectInstance is only created through Subject.Of.

Checks

Run locally in the same order as ci.yml:

  • dotnet build -c Release: 0 errors.
  • dotnet test -c Release --no-build: 288 passed (net10.0).
  • packages/casl-net: npm ci succeeded.
  • tests/casl-compat: npm ci && npm test reports "24000 decisions matched across 150 rule sets". Before the .npmrc change, the same command on 7.1.3 failed with "Untrusted subject type value "WorkItem"".
  • The version table above comes from running each version locally with Node 22.

Generated by Claude Code

…range

Before @casl/ability 7.1.1, a plain object's own __caslSubjectType__
property chose its subject type, so JSON from outside the app could pose
as any type. The browser guide and the package README now recommend 7.1.1
or later, and say how to stay safe on 6.7/7.0. The peer range stays
^6.7.0 || ^7.0.0.

Refs #8

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CU4qH6uMNWadmwVG9pypJk
…docs

@casl/ability 7.1.3 closes a second way for parsed JSON to name its own
subject type: an own `constructor` property ({"constructor":{"name":
"Invoice"}} was checked as an Invoice on 7.1.2). The browser guide, the
package README and the changelog now recommend 7.1.3 rather than 7.1.1.

The compatibility test and the browser package's dev dependency move from
7.0.1 to 7.1.3. From 7.1.1, subject() tags objects for the copy of
@casl/ability that ran it, and the symlinked casl-net resolved its own dev
copy, so every check threw "Untrusted subject type". The test now installs
casl-net as a copy (install-links), sharing one @casl/ability as an app
does. 24,000 decisions still match.

Refs #8, #10

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CU4qH6uMNWadmwVG9pypJk

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants