feat(pola): what you hand out includes what its functions return

Add the rule to pola's description and body, and split three skills
out by situation: facet (what crosses a callback boundary),
capability-based-design (Tribble: one object per authority
distinction; narrowing only intersects), and caretaker.

A/B tested with Claude Haiku 5.5 in isolated runs, graded by an
explorer that plays Mallory. On a discord.js-style bot task, every
failure was `post: text => channel.send(text)`, whose implicit return
hands out the Message and so the client's token. Pooled pass rates:
no skills 35/70; pola's old description 36/48; the rule anywhere
139/144; this set 12/12 vs 5/12 for no skills in the same batch, and
21/21 on seven other tasks. Examples use an email SDK; they fixed the
chat-domain mistake anyway. The rule belongs in the description
because agents opened skill bodies in only some runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dckcandClaude Opus 5.5 committed 2026-11-05 00:42:25 -06:00
1 parent e62f6ac285
commit 384a88899c
5 files changed
+111 -1

No files matched your search

+3
View File
@@ -16,6 +16,9 @@ Code](https://code.claude.com/docs/en/skills) and
- [pola](pola/SKILL.md) — organize all code, tests included, by - [pola](pola/SKILL.md) — organize all code, tests included, by
the flow of authority: each part gets only what its task needs. the flow of authority: each part gets only what its task needs.
- [facet](facet/SKILL.md) — hand other code a fresh, frozen object; what its functions return crosses the boundary too.
- [capability-based-design](capability-based-design/SKILL.md) — one object per authority distinction; narrowing only intersects.
- [caretaker](caretaker/SKILL.md) — revocable access as a forwarder plus a separate revoker.
- [acls-dont](acls-dont/SKILL.md) — don't check who's asking; hand out narrowed capabilities. An anti-pattern, in pattern form. - [acls-dont](acls-dont/SKILL.md) — don't check who's asking; hand out narrowed capabilities. An anti-pattern, in pattern form.
- [no-ambient-authority](no-ambient-authority/SKILL.md) — clocks, - [no-ambient-authority](no-ambient-authority/SKILL.md) — clocks,
RNGs, `fetch`, and the filesystem come in as parameters. RNGs, `fetch`, and the filesystem come in as parameters.
+41
View File
@@ -0,0 +1,41 @@
---
name: capability-based-design
description: >-
Capability-based design (Tribble): every distinction in authority is a different object, and narrowing never widens. Use when designing an API, SDK, service, device, or object model that others will hold pieces of; when writing attenuation or builder methods (readOnly, subdir, narrow, restrict, scoped, forUser); when splitting read from write, or use from administration; when a scoped handle checks paths, URLs, or names. Not for what one callback receives (that's facet).
---
# Capability-based design
Give each distinct authority its own object; holding the object is the permission.
1. **One object per authority distinction.** Reading and writing are different objects; so are using a resource and administering it.
```js
// bad: one object, a mode flag, and a check
file.write(data, { as: user });
// good
const { reader, writer } = openFile(path);
```
2. **Narrowing returns a new object and only intersects.** A narrowed handle's narrowing methods can't escape its own limits: "widening is a security hole".
```js
// bad: the second call replaces the first
onlyTypes: types => make({ ...opts, types }),
// good: keep every constraint; all must hold
onlyTypes: types => make({ ...opts, filters: [...opts.filters, t => types.includes(t)] }),
```
3. **Keep limits and secrets in closures,** never on properties the holder can read or overwrite (`this.root`, `this.token`). Freeze every object you return.
4. **Check the parsed form,** the one the far side will act on, not string prefixes of the raw input.
```js
// bad: 'docs/../../etc/passwd' starts with 'docs/'
if (!rel.startsWith(dir)) throw Error('outside');
// good
const abs = path.resolve(root, rel);
if (!abs.startsWith(root + path.sep)) throw Error('outside');
```
5. **Separate access control from use.** The code that decides who gets which handle is not the code that uses it; the handle's methods take no identity.
6. **Identify the authoritative source.** A file's name belongs to the directory, not the file; give each fact to the object that owns it.
Before finishing, write a test that plays the holder of the narrowest handle: call every method with hostile arguments and narrow it again, and check that nothing reaches outside its limits.
## Sources
- Dean Tribble, *Capability-based Design: Applying Security Techniques to Object-Oriented Design* (slides, Agoric): "All distinctions in authority are represented by different objects"; "'Widening' is a security hole"; "Capability-based design also drives clear abstraction boundaries".
+27
View File
@@ -0,0 +1,27 @@
---
name: caretaker
description: >-
Caretaker: revocable access as a forwarder plus a separate revoker. Use when access must end later: when a contract, session, share, conversation, or trial ends; when someone asks for "revoke", "expire", "cancel access", or "undo sharing".
---
# Caretaker: revoke by cutting the forwarder
**Bad:** a flag on the object you hand out; the holder can read and flip it.
```js
const share = { file, revoked: false, read() { if (!this.revoked) return this.file.read(); } };
```
**Good:** the holder gets the forwarder; only the owner gets the revoker.
```js
const makeCaretaker = target => {
let t = target;
const forwarder = Object.freeze({ read: () => { if (!t) throw Error('revoked'); return t.read(); } });
const revoker = Object.freeze({ revoke: () => { t = null; } });
return { forwarder, revoker };
};
```
Rules: the forwarder exposes no way to reach the target, the revoker, or the revoked state; every method checks; revocation can't be undone by the holder.
## Sources
- [E in a Walnut: Capability Patterns](https://www.skyhunter.com/marcs/ewalnut.html#SEC45): the caretaker as revocable forwarder.
+37
View File
@@ -0,0 +1,37 @@
---
name: facet
description: >-
Facet: hand other code a fresh, frozen object with just the functions it needs, never your SDK objects. Use when passing an argument to, or returning a value from, code you don't control: a vendor SDK's callback, an AI model's tools, a plugin, a webhook handler, a contractor's or user's script. Not for choosing which methods a service offers (that's capability-based-design).
---
# Facet: a new, narrow object for each party
Whatever you hand to another party, plus everything reachable from it (properties, prototype, and the return value of every function), is what they get. Build that object on purpose.
**Bad:** hand over the SDK object. An email SDK's Email reaches `.mailbox.account.password`.
```js
summarize({ email });
```
**Good:** a frozen object of closures and plain data.
```js
const { freeze } = Object;
summarize(freeze({
subject: email.subject,
thread: async () => (await email.thread()).map(e => freeze({ from: e.from.address, body: e.body })),
reply: async text => { await email.reply(String(text)); },
}));
```
Rules:
1. **Return data, not what the underlying call returned.** `text => email.reply(text)` hands out the Email that `reply` returns. Chaining APIs (`db.set()` returning the db, any method returning `this`) leak the same way.
2. **Copy records** into frozen plain objects; SDK records carry back-references.
3. **Keep authority in closures,** not properties: a `this.client` or `this.headers` field is readable and writable by the holder. Freeze what you hand out.
4. **Bind scope when you make the facet.** Don't take a folder name, path, or user from the holder and act on it with your own authority.
Before finishing, walk everything reachable from each facet and add a test that does it: no client, token, raw store, or other party's data.
## Sources
- [E in a Walnut: Capability Patterns](https://www.skyhunter.com/marcs/ewalnut.html#SEC45): facets.
- [awesome-ocap wiki](https://github.com/dckc/awesome-ocap/wiki): a pattern language for ocaps.
+3 -1
View File
@@ -1,7 +1,7 @@
--- ---
name: pola name: pola
description: >- description: >-
Principle of Least Authority as the way to organize all code: trace the flow of authority, give each component only what its task needs, design APIs around attenuation. Use when writing or reviewing any code, tests included: makers and their parameters, module imports and exports, which objects share a scope, what a facet exposes; when designing a service's API (attenuation methods, flower-shaped narrow-then-fire handles, mechanism vs policy, secrets in payloads); when tempted to write an allowlist; when someone says "POLA", "least authority", "who can reach that?", "Bob shouldn't see Alice's purse", or "makeFoo-style actors". The table stakes (no clocks, fetch, or env reached for inside logic) are no-ambient-authority; this is the organizing principle on top. Principle of Least Authority as the way to organize all code: trace the flow of authority, give each component only what its task needs, design APIs around attenuation. Everything reachable from what you hand out is handed out too, including what its functions return: wrappers return plain data, never the SDK's objects. Use when writing or reviewing any code, tests included: makers and their parameters, module imports and exports, which objects share a scope, what a facet exposes; when designing a service's API (attenuation methods, flower-shaped narrow-then-fire handles, mechanism vs policy, secrets in payloads); when tempted to write an allowlist; when someone says "POLA", "least authority", "who can reach that?", "Bob shouldn't see Alice's purse", or "makeFoo-style actors". The table stakes (no clocks, fetch, or env reached for inside logic) are no-ambient-authority; this is the organizing principle on top.
--- ---
# POLA: organize code by the flow of authority # POLA: organize code by the flow of authority
@@ -25,6 +25,7 @@ So at each level, code has two roles:
- **Makers take only what their task needs.** `makeAlice({ usdcPurse, stockDepositFacet })`, not `makeAlice({ ledger })`. - **Makers take only what their task needs.** `makeAlice({ usdcPurse, stockDepositFacet })`, not `makeAlice({ ledger })`.
- **Attenuate at API boundaries.** Hand out the narrowest facet that works: a deposit facet rather than the purse; a seat rather than the escrow's admin; a read-only view rather than the DB. When designing an API, decide which facets it has and who should get each. - **Attenuate at API boundaries.** Hand out the narrowest facet that works: a deposit facet rather than the purse; a seat rather than the escrow's admin; a read-only view rather than the DB. When designing an API, decide which facets it has and who should get each.
- **What you hand out includes everything reachable from it: properties, prototypes, and what its functions return.** A wrapper like `text => email.reply(text)` hands out whatever `reply` returns, often an SDK object that leads back to the client and its token. Return plain data or nothing, and copy SDK records into frozen plain objects.
- **Separate parties get separate scopes.** If two parties' authority shares a scope, a bug or a careless line lets one act as the other. A scope holding both Alice's and Bob's purses is a design error. - **Separate parties get separate scopes.** If two parties' authority shares a scope, a bug or a careless line lets one act as the other. A scope holding both Alice's and Bob's purses is a design error.
- **Tests too.** Tests are where the code's intended authority flow is first written down. Write each party as a `makeFoo`-style actor holding its own authority privately; the test's top level is the wiring layer that creates the parties and introduces them ([sequence-diagram-actor-sim](https://github.com/Agoric/agoric-sdk/blob/master/.agents/skills/sequence-diagram-actor-sim/SKILL.md)). - **Tests too.** Tests are where the code's intended authority flow is first written down. Write each party as a `makeFoo`-style actor holding its own authority privately; the test's top level is the wiring layer that creates the parties and introduces them ([sequence-diagram-actor-sim](https://github.com/Agoric/agoric-sdk/blob/master/.agents/skills/sequence-diagram-actor-sim/SKILL.md)).
- **The test takes the spontaneous step; actors carry out the consequences.** Give an actor what it knows at construction and let it decide how to act: `alice.run()`, or `alice.tradeWith(bob)` to introduce a counterparty. Don't drive it with arguments that decide for it, like `alice.pay(to, amount)`: that is the test acting with Alice's authority, as if it held her purse. What an actor hands others (a deposit facet, a shop) carries no authority to spend for it. - **The test takes the spontaneous step; actors carry out the consequences.** Give an actor what it knows at construction and let it decide how to act: `alice.run()`, or `alice.tradeWith(bob)` to introduce a counterparty. Don't drive it with arguments that decide for it, like `alice.pay(to, amount)`: that is the test acting with Alice's authority, as if it held her purse. What an actor hands others (a deposit facet, a shop) carries no authority to spend for it.
@@ -78,6 +79,7 @@ Before committing, for each new maker, scope, and export:
3. Could a narrower facet replace what's passed? Does any facet let a caller spend for its owner, or does the test decide what an actor does? 3. Could a narrower facet replace what's passed? Does any facet let a caller spend for its owner, or does the test decide what an actor does?
4. Name the wiring layer at this level. Is it small? 4. Name the wiring layer at this level. Is it small?
5. Does any component check an allowlist, or take a policy decision that its creator could make by narrowing what it hands out? 5. Does any component check an allowlist, or take a policy decision that its creator could make by narrowing what it hands out?
6. Walk everything reachable from each object you hand out, including the return value of each of its functions. Does it reach an SDK client, a token, or another party's data?
## Sources ## Sources