chadtmiller.com/3n2ourq622gx5
zds refuses rpc?lxm=…&aud=… scopes with invalid_scope
0
0
# zds refuses `rpc?lxm=…&aud=…` scopes with `invalid_scope`
## What happens
When an OAuth client asks for an `rpc` permission with its method written as a parameter, zds refuses the whole sign-in. The scope:
```
rpc?lxm=*&aud=did:web:api.bsky.app%23bsky_appview
```
fails at PAR with:
```json
{"error":"invalid_scope","error_description":"Unsupported scope"}
```
The sign-in fails even when the client metadata declares the scope. We hit this with HUD (https://hud.place): a user on a zds PDS couldn't sign in. HUD asked for `rpc?lxm=*&aud=<service>` for each of five services.
## Why it should be accepted
The atproto permission spec (https://atproto.com/specs/permission) uses this exact string twice: as the example of calling any method of one service, under `rpc`, and in its list of syntactically and semantically valid scope strings:
```
rpc?lxm=*&aud=did:web:api.example.com%23svc_appview
```
`lxm` is `rpc`'s positional parameter, and the spec says a positional parameter can be written as a key/value pair instead (`account:repo?action=manage` is `account?action=manage&attr=repo`). So `rpc?lxm=*&aud=X` and `rpc:*?aud=X` are the same permission.
The reference implementation agrees. `@atproto/oauth-scopes` 0.5.14 parses both to `{"lxm":["*"],"aud":"did:web:api.bsky.app#bsky_appview"}`, and both allow `app.bsky.feed.getFeed` to that audience.
## Where (zds v0.14.21, `c1df24a`)
1. **Validation:** `isGranularScope` in `src/atproto/oauth.zig` accepts the `repo?` and `space?` parameter forms, but not `rpc?`, `blob?`, `account?` or `identity?`. Those fall through to `"Unsupported scope"` in `validateScope`.
2. **Enforcement:** `rpcAllows` in `src/internal/scopes.zig` skips any scope that doesn't start with `rpc:`, and `rpcMethodMatches` reads the method only from after `rpc:`. So even if (1) were fixed, `rpc?lxm=…&aud=…` would grant nothing.
## Suggested fix
- Accept the parameter form of every resource in `isGranularScope`: `rpc?`, `blob?`, `account?` and `identity?`, as `repo?` and `space?` already are.
- Where a permission is matched, read its positional parameter from the query when it isn't given positionally: `lxm` for `rpc`, `accept` for `blob`, `attr` for `account`/`identity`. The query may repeat `lxm` (and `accept`), since these are arrays.
- Test that `rpc?lxm=*&aud=did:web:api.bsky.app%23bsky_appview` passes PAR and allows the same calls as `rpc:*?aud=did:web:api.bsky.app%23bsky_appview`.
## Workaround for clients
Write the method positionally: `rpc:*?aud=<service>`. zds accepts it, and so do the reference PDS and others.