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:
1 parent
e62f6ac285
commit
384a88899c
5 files changed
+111
-1
No files matched your search
@@ -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".
|
||||
Reference in new issue
Block a user