graphql-armory 0.1.0.pre8 → 0.1.0.pre10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +64 -0
  3. data/README.md +7 -7
  4. data/docs/authorization.md +123 -5
  5. data/docs/encrypted-ids.md +1 -1
  6. data/docs/keyset-connections.md +28 -4
  7. data/docs/persisted-queries.md +111 -19
  8. data/docs/rate-limiting.md +37 -13
  9. data/docs/telemetry.md +31 -8
  10. data/exe/graphql-armory-publish +6 -0
  11. data/lib/graphql/armory/authorization/adapters/cancan.rb +7 -3
  12. data/lib/graphql/armory/authorization/adapters/pundit.rb +8 -1
  13. data/lib/graphql/armory/authorization/audit/baseline.rb +191 -0
  14. data/lib/graphql/armory/authorization/audit/command.rb +57 -8
  15. data/lib/graphql/armory/authorization/audit/findings.rb +3 -2
  16. data/lib/graphql/armory/authorization/audit/interface_rules.rb +4 -1
  17. data/lib/graphql/armory/authorization/audit/observed_rules.rb +58 -0
  18. data/lib/graphql/armory/authorization/audit/payload_reuse.rb +95 -0
  19. data/lib/graphql/armory/authorization/audit/plain_resolvers.rb +85 -0
  20. data/lib/graphql/armory/authorization/audit/reach.rb +75 -0
  21. data/lib/graphql/armory/authorization/audit/report.rb +7 -1
  22. data/lib/graphql/armory/authorization/audit/type_rules.rb +19 -2
  23. data/lib/graphql/armory/authorization/audit.rb +12 -4
  24. data/lib/graphql/armory/authorization/authorize.rb +28 -8
  25. data/lib/graphql/armory/authorization/configuration.rb +4 -3
  26. data/lib/graphql/armory/authorization/definitions.rb +7 -0
  27. data/lib/graphql/armory/authorization/integration/field.rb +26 -4
  28. data/lib/graphql/armory/authorization/integration/object.rb +8 -0
  29. data/lib/graphql/armory/authorization/integration/resolver.rb +2 -0
  30. data/lib/graphql/armory/authorization/integration.rb +14 -3
  31. data/lib/graphql/armory/authorization/rspec.rb +10 -4
  32. data/lib/graphql/armory/authorization/rule.rb +19 -3
  33. data/lib/graphql/armory/authorization/scope.rb +6 -6
  34. data/lib/graphql/armory/authorization.rb +1 -1
  35. data/lib/graphql/armory/ids.rb +11 -11
  36. data/lib/graphql/armory/keyset/encoder_check.rb +113 -0
  37. data/lib/graphql/armory/keyset.rb +23 -3
  38. data/lib/graphql/armory/persisted_queries/manifest.rb +2 -0
  39. data/lib/graphql/armory/persisted_queries/manifests.rb +69 -0
  40. data/lib/graphql/armory/persisted_queries/publisher.rb +127 -0
  41. data/lib/graphql/armory/persisted_queries/redis_store.rb +137 -0
  42. data/lib/graphql/armory/persisted_queries.rb +55 -16
  43. data/lib/graphql/armory/railtie.rb +10 -0
  44. data/lib/graphql/armory/rate_limits/analysis_guard.rb +175 -0
  45. data/lib/graphql/armory/rate_limits/concurrency.rb +93 -14
  46. data/lib/graphql/armory/rate_limits/invalid_queries.rb +75 -0
  47. data/lib/graphql/armory/rate_limits/points.rb +129 -15
  48. data/lib/graphql/armory/rate_limits/time.rb +140 -22
  49. data/lib/graphql/armory/rate_limits.rb +30 -5
  50. data/lib/graphql/armory/telemetry.rb +71 -9
  51. data/lib/graphql/armory/version.rb +1 -1
  52. data/lib/graphql/armory.rb +1 -0
  53. data/lib/tasks/graphql_armory.rake +11 -4
  54. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4d5727b97311ff099b347c1e06cfbf1ec425a03c6018c1385ec557d8a31fef5
4
- data.tar.gz: 78015ec70e63fded090bfbebca21328792a0285f555f11f66e25e4c5b094f675
3
+ metadata.gz: 306b875ce5c7b3b423266aac6acad20df8cff2fcfb2de8bd2fd617f18f06ee0a
4
+ data.tar.gz: 4850e8b8d61f40d0bfe87a25326b5af43a12415c73dc3fcabdfddb1b861cd393
5
5
  SHA512:
6
- metadata.gz: fcfd1948d727ccfd827c9acefdc76e78ee14e64e01d72fea83d3c367674af1cb3e302c2728b170a8561677d1c6b79ecd20723c639dde2ef9d46fa7b96c577927
7
- data.tar.gz: a519a7cf57c9650c7d08965e51a3829fe9860ef31e1ad2bf78f29ca91810a704f7fdb662cfdf390f1efedea1932bd1bafbe1faced26c7deb6323e5eca009640f
6
+ metadata.gz: 197340f48f89963609828eff4da2250a56c49bd7946546fafccb1aae03a8fa0743c4850ae24b5df7e780f89d29633c42b380c0326838ecdd8389b4693efd8f3a
7
+ data.tar.gz: b3343756c445fb47b688afc126181cefd94d448396324ac310392a3bbda5a5d17ce789979560fa6761f28d6491d62ddcb4d94a8c9befe9da11ac0ce557056f48
data/CHANGELOG.md CHANGED
@@ -1,5 +1,69 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.1.0.pre10 (2026-11-03)
6
+
7
+ This release closes the ways a client could make an analysis refusal disappear, and makes clients pay for the invalid queries they send. Anyone using [rate limits](docs/rate-limiting.md) together with `max_depth`, `max_complexity` or their own analyzers should read Breaking before upgrading: a query whose analysis keeps raising is now refused instead of run. [Keyset connections](docs/keyset-connections.md) now check the cursor encoder when the app loads.
8
+
9
+ ### Breaking
10
+
11
+ - On a schema with a rate limiter, an analysis refusal is no longer lost when an analyzer or a `complexity:` lambda raises `ExecutionError`, which a client could choose by asking for that field. A `max_depth` or `max_complexity` refusal, or one another analyzer returned, stands; an `AnalysisError` raised from `result` keeps its message. Any query analyzer that keeps raising when asked again, including `max_complexity` with a raising lambda and your own maximums, refuses the query with `QUERY_LIMIT_UNKNOWN`, in soft mode too. When a raise stops the visit, a query in a multiplex with multiplex analyzers (such as `Schema.multiplex` with `max_complexity`) is refused the same way. To upgrade: if an analyzer or a lambda raises on honest queries, move that check to the field. Limits: a schema with no rate limiter keeps graphql-ruby's behaviour, and an analyzer that remembers in the context that it already refused still loses that refusal. See [Guarantees and limits](docs/rate-limiting.md#guarantees-and-limits). (#49, #53)
12
+ - Invalid queries are now charged. A syntax error, a validation error, no query string or a strict `PersistedQueries` refusal costs `invalid_cost:` points on `Points` (default 1; `nil` turns it off) and, on `Time`, a share of the time of a multiplex where no query ran. Its answer does not change: this penalises the next valid query and does not stop a flood. To upgrade: clients that send many invalid queries spend more, so read `context[:rate_limit_points]` in soft mode first. (#51)
13
+
14
+ ### Added
15
+
16
+ - `use GraphQL::Armory::Keyset` checks the cursor encoder when the schema loads, and any encoder set later on it or on a subclass, each member of an encoder chain included. It refuses an encoder that does not round trip, leaves the text readable, has a fixed key or nonce, or decodes forged text; it cannot prove encryption. `plain_cursors: true` on `use` becomes the default for `build`. Without `use` nothing changes. See [Checking the encoder](docs/keyset-connections.md#checking-the-encoder-when-the-app-loads). (#52)
17
+
18
+ ### Docs
19
+
20
+ - How to audit a schema before adopting the plugin and what to fix first, in [Authorization](docs/authorization.md#measuring-before-you-adopt); a missing rate limit key raises when the query runs, in [Rate limiting](docs/rate-limiting.md). Specs that need Redis skip without `REDIS_URL` outside CI. (#50)
21
+
22
+ ## 0.1.0.pre9 (2026-11-02)
23
+
24
+ This release is about adopting the gem on a real schema, and about limits that hold when a client tries to get around them. An existing app can now [observe a new rule](docs/authorization.md) before enforcing it and keep the audit green on known problems with a baseline; persisted queries can be published without a server deploy and from several manifests ([persisted queries](docs/persisted-queries.md)); and [rate limits](docs/rate-limiting.md) take several keys per query, against clients that rotate one identity. Anyone running the audit or rate limits in hard mode should read Breaking and Security before upgrading.
25
+
26
+ ### Breaking
27
+
28
+ - An audit that passed can fail after upgrading, because it reports more: see the entries under Security and the audit entry under Fixed. Read each new problem instead of declaring it to get the build green; a baseline can hold them while you work through them. (#42, #44)
29
+ - In hard mode, a query whose rate limiter cannot answer, because a `complexity:` lambda or an `on_store_error` hook raised `ExecutionError`, is now refused with `RATE_LIMIT_NOT_CHARGED`. It used to run uncharged. Stop raising from those, or use soft mode while you do. (#46)
30
+ - In strict mode, a `GraphQL::Query` built by your own code, for example in `multiplex`, is now refused unless its context holds `armory_allow_raw_query: true`. It used to run any query, because it skips the plugin's query class. Add the flag where your code builds queries on purpose. Outside strict mode it now records `:raw_query_run`. (#32)
31
+ - A sink that raises no longer takes the request down: the gem's decision stands, the next sink runs, and the new `on_sink_error:` is called, which by default warns with the signal and the error's class. A monitoring failure used to become an API failure. If a record must exist before data is served, raise from `on_sink_error:` to fail closed as before. A sink's `Encoder::InvalidError` is no longer read as a forged ID. (#29)
32
+ - A sink that could never be called, such as `->(a) {}`, now raises `Telemetry::ConfigurationError` at boot. It used to fail on the first request. (#29)
33
+
34
+ ### Added
35
+
36
+ - Several keys per query, against clients that rotate one identity: `rate_limit_key` or `key:` may answer a list of up to 5 different Strings, for example `["user:1", "ip:1.2.3.4"]`, on `Points`, `Concurrency` and `Time`. A query runs only if every key allows it, and each is charged. It costs about two store round trips per key. Two queries racing between the read and the charge can leave a refused one having charged other keys. A key whose store fails is left out and `on_store_error` is called for it; the others still decide. A single String behaves as before. See [Clients that change identity](docs/rate-limiting.md#clients-that-change-identity). (#40)
37
+ - Observation mode, to learn who a new rule would refuse before enforcing it: `authorize :read, observe: "why"` on a type, or `authorize: :manage, observe: "why"` on a field. On a query, what the policy refuses is served and recorded as an `:observed` signal. It refuses as usual with no `sinks:`, with the null adapter, or in a mutation or subscription, and a type holding a field with a resolver or a mutation raises `ConfigurationError` instead of being observed; lists of object types and lookups still go through the scope, but a list with no scope (an interface, a union, `scope: false`, `nodes(ids:)`) serves its rows and records them. The audit reports each one as `:observed`, and a baseline cannot accept it. See [Observing a rule](docs/authorization.md#observing-a-rule-before-enforcing-it). (#35)
38
+ - Audit baseline, for adopting the gem on a schema with many problems: `rake "graphql_armory:audit_baseline[AppSchema,path]"` records them, then `rake "graphql_armory:audit[AppSchema,path]"` and `be_fully_authorized(baseline: path)` fail only on new problems, on an accepted one that grew (a field added to that type, a type added under that base class), or on an accepted one that is gone. The file only ever shrinks unless edited by hand, every accepted problem stays listed, and `report.ok?` never changes because of it. A baseline protects nothing: those problems are still open. (#34)
39
+ - `PersistedQueries::RedisStore` and `Publisher` publish operations without a server deploy, for frontends that deploy on their own: their CI runs `graphql-armory-publish manifest.json` before the deploy, and the server reads each operation when first asked. An operation it read keeps working when Redis fails; an id it cannot find or check is refused. A published operation never changes. There is no endpoint: whoever can write to those keys decides what strict mode allows, so give the CI its own credential. The app adds the `redis` gem. (#33)
40
+ - `PersistedQueries::Manifests` puts several manifests behind one `store:`, for several frontends and mobile versions still in use: `Manifests.build("config/persisted_queries/*.json")`. It raises at boot when a pattern matches nothing or two manifests disagree on an id. They are one allowlist, and a new manifest still needs a deploy. (#31)
41
+ - `PersistedQueries.operation_id` now reads Relay's `doc_id`, so Relay clients need no change to send their id. (#30)
42
+ - The Pundit and CanCanCan adapters take `user_key:`, for an app whose context holds the user under another key: `Adapters::Pundit.new(user_key: :viewer)`. It used to take a subclass. (#30)
43
+ - In Rails, `rake graphql_armory:audit[YourSchema]` now loads by itself, through a Railtie that loads only when Rails is there. The task now runs the app's `:environment` when it runs, not only when it was defined before the task, so clearing the task's prerequisites no longer skips it. An adapter subclass with its own `initialize` must call `super`: without it, nobody has a user and everyone is denied. (#30)
44
+ - A sink that requires three arguments now receives the query's context: `->(signal, data, context) { ... }`. It tells who was refused without a request-global. It reads through a view that cannot write to the context. Sinks of two arguments, `*arguments` or a defaulted third are unchanged and never receive it. (#29)
45
+ - A persisted queries refusal now carries `extensions.code`: `RAW_QUERY_REFUSED`, `UNKNOWN_OPERATION` or `OPERATION_MISMATCH`, so an app can match on it instead of on the message. (#29)
46
+ - Rate limiters take `sinks:` and record `:rate_limit_store_failed`, with the limiter and the error's class, when the store fails. A failing store used to reach only `on_store_error:`, or stderr. The query still runs. (#29)
47
+
48
+ ### Fixed
49
+
50
+ - `Points` and `Time` on one store and one key shared a bucket, as the docs recommend: a query taking 300 ms spent the client's points, and each limiter capped and refilled the balance with its own limit. `Time` now keeps its milliseconds under `time:<key>`, read with `Time.bucket_key(key)`. On upgrading, `Time` balances start full once; `Points` keeps its key, so a balance the mix drained recovers as it refills, within one window. Tools or custom stores that read `Time`'s bucket by the client's key must use the new key. Two limiters of the same class on one store and key still share a bucket: give each its own store or keys. (#43)
51
+ - A payload field declared on a parent mutation with no rule, or on a mutation with `authorize :none` and no `covers_fields`, is denied while the mutation still runs, so the client read null after a write. It stays denied, and the audit now reports it as `:field_without_rule`. (#42)
52
+ - With `Points`, a connection asked for with no `first:` or `last:` on a schema with no page size was a server error any client could cause. It is now refused with `This connection needs first: or last:` (code `PAGE_SIZE_REQUIRED`), and charges nothing. Set `default_max_page_size`. A schema with `max_complexity` still gets graphql-ruby's error. (#41)
53
+ - A schema using `Concurrency` twice kept only the last limiter's slot for a query, so the other leaked until `stale_after`. (#40)
54
+ - When an object's check raised and a `rescue_from` answered true, graphql-ruby served the object. The handler still runs, and the object is denied. (#29)
55
+ - The rate limiters' default warning no longer prints the store error's message, which could hold a password. (#29)
56
+
57
+ ### Security
58
+
59
+ - An `ExecutionError` raised during analysis, by another analyzer or by a `complexity:` lambda, made `Points`, `Time` and `Concurrency` skip the query or lose a refusal already given, and a client could choose that by field order. Each limiter now still decides. **Upgrading:** in hard mode, a query whose limiter cannot answer, because a `complexity:` lambda or an `on_store_error` hook raised, is refused with the code `RATE_LIMIT_NOT_CHARGED` instead of running. Soft mode runs it and records `charged: false` in the limiter's context record. Limit: a trace that takes no modules from the schema (`context[:trace]`, a class given to `trace_mode`) is not covered. (#46) Docs: [rate limiting](docs/rate-limiting.md#guarantees-and-limits).
60
+ - A resolver, mutation or subscription with no `Base`, on a type with `covers_fields`, was served to anyone while the audit said ok, because the declaration read as covering it and no rule ran. The audit now reports it as `:unprotected`. To fix it, include `Base` and declare `authorize`, or declare `authorize: :none, reason: "..."` on the field. A schema that had this shape fails the audit after upgrading; a plain read that answers a type with a rule is not reported, because that type refuses. Limit: a plain method field under `covers_fields` stays served and listed by its type. Runtime does not change. (#44)
61
+ - A field returning a mutation's payload, without being that mutation, served the payload's fields with no rule run while the audit said ok. The audit now reports it as `:payload_outside_mutation`, as well as a public mutation inheriting fields from a parent with a rule, so a schema that passed may now fail. The runtime does not change: return a type of its own, or give the parent's field `authorize: :none, reason: "..."`. (#42)
62
+
63
+ ### Docs
64
+
65
+ - Limits named for rate limits (`max_depth` lost when an analyzer raises, `validate: false` on `Execution::Next`, `max_page_size: nil`, a query `Time` refuses still charged by `Points`, a multiplex analyzer raising), the audit (`authorize: false` with a resolver with no `Base`, another resolver at a path a baseline accepts) and persisted queries (graphql before 2.6 with json 3.1). (#47)
66
+
3
67
  ## 0.1.0.pre8 (2026-10-31)
4
68
 
5
69
  This release is about [authorization](docs/authorization.md): the audit now follows every definition of the types it reaches from the schema's roots, `orphan_types` and what they reference, whether or not `visible?` hides them (the limits are in the module page), and Pundit judges a record by both the declared model's policy and its own class's. Read it if you run the audit in CI or rely on Pundit reading `policy_class` from an instance: rules that were silently skipped now show up, so an audit that passed can fail after upgrading, and each new problem names what to do.
data/README.md CHANGED
@@ -6,12 +6,12 @@
6
6
 
7
7
  Open-source extensions for [graphql-ruby](https://github.com/rmosolgo/graphql-ruby), built on its public extension points: no fork, no monkey patching. One gem, one module at a time; each module has its own page in [`docs/`](docs) with the problem it solves, how to use it, and its limits.
8
8
 
9
- > **Status: early development.** Prereleases on RubyGems (`0.1.0.pre8`). The API may change before 1.0.
9
+ > **Status: early development.** Prereleases on RubyGems (`0.1.0.pre10`). The API may change before 1.0.
10
10
 
11
11
  ## Install
12
12
 
13
13
  ```ruby
14
- gem "graphql-armory", "~> 0.1.0.pre8" # a prerelease: `gem install graphql-armory --pre`
14
+ gem "graphql-armory", "~> 0.1.0.pre10" # a prerelease: `gem install graphql-armory --pre`
15
15
  gem "pundit" # or "cancancan", for the authorization module
16
16
  ```
17
17
 
@@ -25,9 +25,9 @@ Status: ✅ released, 🚧 in progress, ⬜ not started. Update this table in th
25
25
  |---|---|---|---|---|
26
26
  | 1 | Authorization (Pundit, CanCanCan) | ✅ | [docs/authorization.md](docs/authorization.md) | Released in 0.1.0.pre2 (prerelease). Pundit and CanCanCan (the audit checks less with CanCanCan). Global IDs in `loads:` decoded through `object_from_id`; `loads:` inside input objects scoped with `include Base`. `Execution::Next` needs graphql >= 2.6.2. |
27
27
  | 2 | Encrypted, versioned IDs and cursors | ✅ | [docs/encrypted-ids.md](docs/encrypted-ids.md) | Released in 0.1.0.pre4 (prerelease). `Encoder` (AES-256-GCM), versioned chains and `Legacy`, `Encoder.default` (ENV or Rails), `use GraphQL::Armory::IDs`. Composite primary keys not supported. |
28
- | 3 | Persisted queries / operation allowlist | ✅ | [docs/persisted-queries.md](docs/persisted-queries.md) | Released in 0.1.0.pre4 (prerelease). Allowlist from a build manifest (Apollo, Relay), `use GraphQL::Armory::PersistedQueries` with strict mode. A runtime store (database, sync endpoint) is planned for later. |
29
- | 4 | Rate limiting | ✅ | [docs/rate-limiting.md](docs/rate-limiting.md) | Released in 0.1.0.pre5 (prerelease); `RateLimits::Time` in 0.1.0.pre6. Points per client (query complexity) and operations at the same time, `MemoryStore` and `RedisStore`, the budget in response extensions and headers. `RateLimits::Time` charges the wall-clock milliseconds operations take. |
30
- | 5 | Stable (keyset) connections | ✅ | [docs/keyset-connections.md](docs/keyset-connections.md) | Released in 0.1.0.pre7 (prerelease). `Keyset.build(relation)` per resolver, ActiveRecord only, plain non-null columns of the relation's own table. Base64 cursors refused unless `plain_cursors: true`. No total count. |
28
+ | 3 | Persisted queries / operation allowlist | ✅ | [docs/persisted-queries.md](docs/persisted-queries.md) | Released in 0.1.0.pre4 (prerelease). Operations can be published without a server deploy (`RedisStore`, unreleased). Allowlist from a build manifest (Apollo, Relay), `use GraphQL::Armory::PersistedQueries` with strict mode. A runtime store (database, sync endpoint) is planned for later. |
29
+ | 4 | Rate limiting | ✅ | [docs/rate-limiting.md](docs/rate-limiting.md) | Released in 0.1.0.pre5 (prerelease); `RateLimits::Time` in 0.1.0.pre6. Points per client (query complexity) and operations at the same time, `MemoryStore` and `RedisStore`, the budget in response extensions and headers. `RateLimits::Time` charges the wall-clock milliseconds operations take. Invalid queries are charged `invalid_cost:` from 0.1.0.pre10. |
30
+ | 5 | Stable (keyset) connections | ✅ | [docs/keyset-connections.md](docs/keyset-connections.md) | Released in 0.1.0.pre7 (prerelease). `Keyset.build(relation)` per resolver, ActiveRecord only, plain non-null columns of the relation's own table. Base64 cursors refused unless `plain_cursors: true`. No total count. `use` checks the cursor encoder when the schema loads, from 0.1.0.pre10. |
31
31
  | 6 | Subscriptions over Pusher / Ably | ⬜ | | Research not started. |
32
32
  | 7 | Response caching | ⬜ | | Research not started. |
33
33
  | 8 | API versioning (changesets) | ⬜ | | Research not started. |
@@ -55,8 +55,8 @@ GRAPHQL_VERSION="~> 2.4.0" docker compose run --rm test # another graphq
55
55
  Releases are published from GitHub Actions with RubyGems Trusted Publishing (`.github/workflows/release.yml`): no API key is stored and no OTP is asked. Bump `GraphQL::Armory::VERSION` and the CHANGELOG on `main`, then push the matching tag:
56
56
 
57
57
  ```
58
- git tag -a v0.1.0.pre8 -F <message file> main
59
- git push origin v0.1.0.pre8
58
+ git tag -a v0.1.0.pre9 -F <message file> main
59
+ git push origin v0.1.0.pre9
60
60
  ```
61
61
 
62
62
  The workflow checks that the tag matches the version, runs the specs and pushes the gem. It only publishes a tag on a commit of `main`. The `release` environment can require a maintainer's approval first (on a public repository, or a private one on a paid GitHub plan).
@@ -46,7 +46,16 @@ class AppSchema < GraphQL::Schema
46
46
  end
47
47
  ```
48
48
 
49
- The actor is `context[:current_user]`. A complete, tested version lives in [`examples/invoices.rb`](../examples/invoices.rb).
49
+ With graphql-ruby's install template, which includes `ConnectionBehaviors` and `EdgeBehaviors` in classes that inherit from your base object, also declare this in `BaseConnection` and `BaseEdge`, or the audit reports them as `:ignored_rule` ([why](#lists-connections-and-lookups)):
50
+
51
+ ```ruby
52
+ class Types::BaseConnection < Types::BaseObject
53
+ authorize :none, reason: "the field that returns it holds the rule; each node has its own", covers_fields: true
54
+ include GraphQL::Types::Relay::ConnectionBehaviors
55
+ end
56
+ ```
57
+
58
+ The actor is `context[:current_user]`; for another key, pass `adapter: GraphQL::Armory::Authorization::Adapters::Pundit.new(user_key: :viewer)`. A complete, tested version lives in [`examples/invoices.rb`](../examples/invoices.rb).
50
59
 
51
60
  ## Rules
52
61
 
@@ -115,8 +124,11 @@ A declared check is listed as a bypass. Each method is declared on its own, and
115
124
 
116
125
  **What the audit does not see.**
117
126
 
127
+ - `authorize: false` on a field with a resolver that has no `Base`: the audit says ok, and at runtime the field raises `NoMethodError` and serves nothing. Use `authorize: :none, reason: "..."`.
118
128
  - It looks at the classes when it runs, so a method defined later is seen by the next audit.
119
129
  - A type no definition leads to. The audit follows the schema's roots, `orphan_types` and what each definition references (fields, arguments, interfaces, union members, a connection's node), not filtering by `visible?`, so types hidden with no request and every definition of a duplicated name are audited. A type that only your own `resolve_type` returns, listed nowhere, is not seen.
130
+ - A resolver with no `Base` in a shared payload type is reported even when every mutation returning it has a rule that refuses first. The audit reads the type and not who returns it. Declare `authorize: :none, reason: "..."` on the field. A resolver with its own refusing `authorized?` is reported too: the audit cannot read that method.
131
+ - A plain field under a type with `covers_fields`, with a method or a `resolver_method:`. The declaration says its fields are public, so the field is served and only the type is listed. A resolver or mutation with no `Base` under that type is reported. A read one that answers a type with a rule, a list or a connection of one, or a union of them, is not, because that type refuses; on a write root it is reported, since it has already run.
120
132
  - A missing action on an argument of an input object, when a plain field takes that input object. It raises at runtime instead of serving.
121
133
  - A Base resolver on a field class with no `Base`, under a type with a rule: its rule's actions and its arguments are not read. It raises at runtime instead of serving.
122
134
  - A missing policy action on a field of a bypassed type. The audit does not ask the policy there, so a misspelled action passes it and raises at runtime instead of serving.
@@ -125,6 +137,42 @@ A declared check is listed as a bypass. Each method is declared on its own, and
125
137
  - Code written to get past it. The audit reads the classes, it does not run your methods: a declared alias of a library method, a class of yours named under `GraphQL::`, or a forged `__FILE__` are not caught. The audit protects against mistakes, not against the app's own code.
126
138
  - `rescue_from(NotAuthorizedError)`: with `on_unauthorized: :raise`, rescuing is what you are meant to do, so keep that handler's message generic. The interpreter catches field denials there and not object denials, which then raise out of the query; `Execution::Next` catches both.
127
139
 
140
+ ## Observing a rule before enforcing it
141
+
142
+ To learn who a new rule would refuse on a schema already in production, name the rule and say why:
143
+
144
+ ```ruby
145
+ class Types::Invoice < Types::BaseObject
146
+ authorize :read, observe: "rollout of invoices, ticket 123"
147
+ end
148
+
149
+ field :notes, String, authorize: :manage, observe: "rollout of notes, ticket 124"
150
+
151
+ use GraphQL::Armory::Authorization, adapter: :pundit,
152
+ sinks: [->(signal, data) { Rails.logger.info("armory #{signal} #{data}") if signal == :observed }]
153
+ ```
154
+
155
+ When the policy answers `false` or `nil`, **the data is served to a user the rule would refuse**, and an `:observed` signal is recorded in place of `:denied`. Remove `observe:` to enforce the rule. There is no switch for a whole schema: each rule says it, with its reason, and the audit reports each one as `:observed` until it is gone, so `report.ok?` is false and a baseline cannot accept it.
156
+
157
+ | Case | What happens under `observe:` |
158
+ |---|---|
159
+ | A query, and the policy answers `false` or `nil` | Served, `:observed` recorded |
160
+ | No `sinks:` | Refused: observing with nobody listening is only an open door |
161
+ | `Adapters::Null` | Refused |
162
+ | A policy that raises, is missing, or answers anything else | Raises or refuses, as without `observe:` |
163
+ | A type or field with no rule | Denied: there is no rule to observe |
164
+ | A mutation or a subscription, including a read in its response | Refused: only a query runs |
165
+ | A mutation whose response returns a type that cannot be observed | The mutation's own body has already run when that type raises: its write stands |
166
+ | A type under `observe:` with a field that has a `resolver:` or a `mutation:`, its own, inherited or from an interface; a definition shadowed in a subclass does not count | Raises `ConfigurationError` on every query that reaches the type, and its resolvers do not run: observing the type would open the only check before them, and they can write. Remove `observe:`, or put it on the type's plain fields |
167
+ | The same, on the root type | Runs nothing, but the error depends on the engine: on the interpreter with graphql 2.6, graphql-ruby's own rescue reports a `NoMethodError` caused by the `ConfigurationError`. A `rescue_from` handler can turn it into an empty result, so run the audit, which names the type |
168
+ | `authorize: true` with a resolver, where the type's rule is observed | Raises `ConfigurationError`, after graphql-ruby has coerced the arguments: their `prepare:` has run, as it does before any field's rule |
169
+ | A list of an object type, a `loads:` or a `find_by:` | Still goes through the user's scope, and an in-memory lookup still asks the policy: rows are lost, and nothing is recorded about them |
170
+ | A list with no scope: of an interface or a union, `scope: false`, Relay `nodes(ids:)` | **Served row by row and recorded**: the check on each object is all that protects these lists, and it cannot tell it is inside one. A foreign row reaches the user |
171
+ | `visible_when:` | Still hides: the rule it builds is not observed |
172
+ | `observe:` on a mutation, a resolver, a field that holds either, an argument, a bypass, or a field with no action of its own | Raises `ArgumentError` when declared |
173
+
174
+ **Limits.** Only a `resolver:` or a `mutation:` counts as something that can write: a plain field's method that writes, or a `prepare:` on its arguments, runs for a refused user, so keep writes in mutations. A sink that raises loses that signal, reported to `on_sink_error:`, and the data is still served. `Telemetry::Notifications` counts as listening even when nothing subscribes to it. A rule on a type with lists can already lose rows while observed: declare its `scope` only when you trust it, because observing it would mean a second query per list and serving other users' rows. Any clear "no" counts: with CanCanCan that includes the guard that refuses a Symbol a type returns, and an adapter you wrap around `Adapters::Null` is not recognised as null. `load_through_scope: false` opts out of the scope, so a foreign record is served and recorded. While a rule is observed, `audit_baseline` refuses to write: remove `observe:` first.
175
+
128
176
  ## Lists, connections and lookups
129
177
 
130
178
  Lists of a type are narrowed through `InvoicePolicy::Scope` (relations) or by calling the policy per item (arrays). Return a relation when you can: SQL filters before Ruby sees anything.
@@ -160,7 +208,8 @@ expect(AppSchema).to be_fully_authorized
160
208
  ```
161
209
 
162
210
  ```ruby
163
- # Rakefile (or a Rails task file): exits 1 when anything is uncovered
211
+ # Exits 1 when anything is uncovered. In Rails the task loads by itself when the gem is required after Rails, as Bundler does.
212
+ # Elsewhere, in the Rakefile:
164
213
  load "tasks/graphql_armory.rake"
165
214
  # bundle exec rake "graphql_armory:audit[AppSchema]"
166
215
  ```
@@ -174,23 +223,89 @@ load "tasks/graphql_armory.rake"
174
223
  | Kind | What it means | What to do |
175
224
  |---|---|---|
176
225
  | `:plugin` | The schema never installed the plugin. | Add `use GraphQL::Armory::Authorization, adapter: ...`. |
177
- | `:unprotected` | A base class, or the field class of an interface's field on a bypassed implementer, does not include `Base`, so nothing checks it. | Include `Base`. |
226
+ | `:unprotected` | A base class, or the field class of an interface's field on a bypassed implementer, does not include `Base`, so nothing checks it. Also a resolver, mutation or subscription with no `Base` under a type with `covers_fields`: the declaration says a rule runs elsewhere, and none does. | Include `Base` and declare `authorize`, or declare `authorize: :none, reason: "..."` on the field, which lists it by its own path. |
178
227
  | `:no_rule` | A type, mutation or resolver has no rule, so it is denied to everyone. | Add `authorize` or `default_action`. |
179
228
  | `:field_without_rule` | A field of a bypassed type has no rule. The message says what really happens: denied, or served with no check (see [Rules](#rules)). | Give the field `authorize:` where it is defined (on the parent, if inherited), or remove it. A field class without `Base` needs one that includes it. |
180
229
  | `:adapter` | The policy a rule needs does not exist, or lacks the method or the `Scope`. | Add what is missing. |
181
230
  | `:model` | The model a rule needs cannot be worked out. | Pass `model:`. |
182
231
  | `:unscoped_load` | A `loads:` goes through `object_from_id` instead of the user's scope. | Let the load use the scope. |
183
232
  | `:unscoped_list` | A list or connection of records skips the user's scope, with `scope: false`, `connection: false` on a connection type, or a list type graphql-ruby does not detect such as `X.to_list_type`. A rule on each record hides its fields, not how many there are. | Remove the option, or write the type as `[Type]`. |
233
+ | `:payload_outside_mutation` | A field returns a mutation's payload without being a mutation with a rule, including a shared `payload_type` with no rule of its own. Its fields are covered by the mutation's rule, so here they are served with no check. | Return a type of its own. A public mutation that inherits fields from a parent with a rule serves them with no check, so give those fields `authorize: :none, reason: "..."` on the parent. |
184
234
  | `:hook` | The schema's own `unauthorized_field` or `unauthorized_object` wins over the plugin's. | Remove it, or declare it in `own_denial_hooks:`. |
185
235
  | `:own_check` | Your own method can skip the rule: `authorized?`, `wrap`, `visible?` and others, or `reauthorize_scoped_objects` turned off. | Remove it, or declare it in `own_checks:`. |
186
236
  | `:ignored_rule` | A rule that does not run, or a field or argument defined more than once. | See [Redefined fields and arguments](#redefined-fields-and-arguments) and [Lists, connections and lookups](#lists-connections-and-lookups). |
187
237
  | `:foreign_model` | A field rule is defined on an interface or a parent whose model is not this type's, so the policy of this type's model is never asked for that field. A record of another class or a laxer subclass gets past it. Redefine the field on this type with its `authorize:` and an `override_reason:`, or name the same model on the parent. |
188
238
  | `:foreign_policy` | A type or a Base resolver names a `policy:`, but a rule it uses is defined on an interface, a parent, an input object or a resolver, so that rule asks another policy. A user this type's policy refuses can get the data. A field never sees its resolved type, so this cannot be fixed at runtime. | Move the rule to the class that names the policy and remove the original, or name the `policy:` on the class that defines the rule, if it can hold one: an interface or an input object cannot. There is no declaration for it. |
239
+ | `:observed` | A rule under `observe:` serves what it would refuse. A baseline cannot accept it. | Remove `observe:` to enforce the rule. |
189
240
 
190
241
  A declaration (`own_checks:`, `own_denial_hooks:`, `override_reason:`, `authorize :none, reason:`) is your word: the audit stops reporting that problem and lists the reason, so a reviewer can read it. It does not read what your code does. A declaration that names nothing in use is itself a problem.
191
242
 
192
243
  Upgrading can make an audit that used to pass fail, because the audit reports more: read each new problem instead of declaring it to get the build green.
193
244
 
245
+ ### Adopting it on a schema with many problems
246
+
247
+ A first audit of an existing schema can report hundreds of problems. A baseline records them so the build fails only on new ones, while the team works through the list:
248
+
249
+ ```sh
250
+ bundle exec rake "graphql_armory:audit_baseline[AppSchema,config/graphql_armory_baseline.json]" # once; commit the file
251
+ bundle exec rake "graphql_armory:audit[AppSchema,config/graphql_armory_baseline.json]" # in CI
252
+ ```
253
+
254
+ ```ruby
255
+ expect(AppSchema).to be_fully_authorized(baseline: "config/graphql_armory_baseline.json")
256
+ ```
257
+
258
+ **A baseline does not protect anything.** The accepted problems are still open, and a refused user may still get that data. `report.ok?` stays false and the output lists every accepted problem under "still open".
259
+
260
+ | What happens | Result |
261
+ |---|---|
262
+ | A problem not in the file | Fails, named under "new" |
263
+ | An accepted problem whose message changed, for example after an upgrade | Fails as new: read it, then edit the file |
264
+ | An accepted problem that grew: a field or a `loads:` added to that type, or a type added under that base class or interface | Fails as new, naming what it now reaches |
265
+ | An accepted problem that now appears more times | The extra ones fail as new |
266
+ | An accepted problem that is gone | Fails until it leaves the file, so it cannot come back unseen |
267
+ | Another resolver put at a path whose problem is accepted | Passes: an entry names the path and the problem, not the code behind them. Review what changes at an accepted path |
268
+ | A file that is missing or invalid | Fails: it never runs as if there were no baseline |
269
+ | A schema without the plugin | Cannot be accepted: install the plugin first |
270
+ | An `:own_check` or a `:hook` problem | Cannot be accepted: whatever uses that method later would pass unseen. Remove it, or declare it in `own_checks:` or `own_denial_hooks:` with a reason, which the audit lists |
271
+
272
+ Run `audit_baseline` again after fixing problems: on a file that exists it only removes what is gone, and it never adds. To accept a new problem, edit the file by hand, so it shows in the pull request: add its kind, path and message as the output prints them; `count` and `covers` may be left out, and then the entry accepts one problem that reaches nothing, so run `audit_baseline` afterwards to fill them in. The file holds each problem's kind, path, message and count, and the names it reaches (`covers`), and no data of the app. Removing what a problem reaches is fine: running `audit_baseline` narrows the entry.
273
+
274
+ ### Measuring before you adopt
275
+
276
+ With no plugin, the audit reports little more than `:plugin` and each base class without `Base`. To see the real list, audit the schema as if it had adopted the plugin, without touching what runs in production:
277
+
278
+ ```ruby
279
+ # script/armory_audit.rb. Run it on its own, never in the process of your app or of your other specs.
280
+ require_relative "../config/environment"
281
+ Rails.application.eager_load!
282
+
283
+ z = GraphQL::Armory::Authorization
284
+ [Types::BaseObject, Types::BaseField, Types::BaseArgument, Types::BaseInputObject, Mutations::BaseMutation].each { |base| base.include(z::Base) }
285
+ Types::BaseObject.default_action(:read)
286
+
287
+ simulated = Class.new(AppSchema) do
288
+ use z, adapter: :pundit,
289
+ own_checks: { Types::BaseField => { authorized?: "adds the status check, then calls super" } }
290
+ end
291
+
292
+ path = "config/graphql_armory_baseline.json"
293
+ report = z::Audit.(simulated)
294
+ z::Audit::Baseline.write(report, path) unless File.exist?(path) # once; commit the file
295
+ result = z::Audit::Baseline.load(path).(report)
296
+ puts result.new_problems
297
+ exit(result.passes? ? 0 : 1)
298
+ ```
299
+
300
+ `Class.new(AppSchema)` leaves `AppSchema` without the plugin, but `include(z::Base)` changes your base classes for the whole process, so its queries no longer behave as in production. That is why the script runs alone. Name your own classes and your user key (`z::Adapters::Pundit.new(user_key: :viewer)` if it is not `current_user`). The first run stops with an error if an undeclared own check or hook remains: declare it or remove it, then run it again. A simulation measures; it protects nothing until the plugin is really installed.
301
+
302
+ What to do first with a long list:
303
+
304
+ 1. **`:hook` and `:own_check`.** A baseline refuses them. Remove the method, or declare it with its reason. A declaration is your word: the audit does not read whether your check runs.
305
+ 2. **`:unscoped_list` and `:unscoped_load`.** These reach data of other users once a rule is in place.
306
+ 3. **`:no_rule` on mutations, with `:field_without_rule` on their payloads.** Without a rule, the field of a payload is denied: when the mutation is public and writes, the client gets `null` and cannot tell whether it worked. A rule on the mutation covers its payload, and a public one declares `authorize :none, reason: "...", covers_fields: true`.
307
+ 4. **`:model`.** Usually the longest part of the list, and the slowest: each type needs a model and a policy.
308
+
194
309
  ### Redefined fields and arguments
195
310
 
196
311
  When a field is hidden from a user, by `visible?` or anything else, and the request carries no visibility profile, graphql-ruby does not answer "no such field": it looks for another definition of that name and serves it. So this rule does not run for a user the child's field is hidden from:
@@ -227,7 +342,7 @@ Same schema, different adapter. Your types and fields do not change:
227
342
  use GraphQL::Armory::Authorization, adapter: :cancan
228
343
  ```
229
344
 
230
- The actor is `context[:current_ability]` (it wins over `current_user`), or `Ability.new(context[:current_user])` (pass `Adapters::CanCan.new(ability_class: MyAbility)` for another class). It is built once per query.
345
+ The actor is `context[:current_ability]` (it wins over `current_user`), or `Ability.new(context[:current_user])` (`user_key:` names another key; pass `Adapters::CanCan.new(ability_class: MyAbility)` for another class). It is built once per query.
231
346
 
232
347
  | Question | CanCanCan call |
233
348
  |---|---|
@@ -326,6 +441,7 @@ end
326
441
  - **`ready?` runs before authorization** (and, on the interpreter, before a failing `loads:`). Keep it free of side effects.
327
442
  - **`loads:` inside an input object** goes through the scope only when your base input object includes `Base` (`class Types::BaseInputObject < GraphQL::Schema::InputObject; include GraphQL::Armory::Authorization::Base; end`); otherwise the audit reports it as `:unscoped_load`.
328
443
  - **Do not put `authorize:` on a mutation field or on payload fields**; the mutation's own rule is the one that counts. A subclass that redeclares `authorize :none` is open to everyone, on purpose.
444
+ - **Fields on a parent mutation.** A payload field asks the class that defined it, so a field on a parent with no rule, or on a mutation with `authorize :none` and no `covers_fields`, is denied: the mutation runs and the field answers null. The audit reports it as `:field_without_rule`. Give that field `authorize: :none, reason: "..."`, or use a shared `payload_type`. Moving `authorize` to the parent also works, but every new child then inherits that rule instead of being denied, and the audit does not report it.
329
445
 
330
446
  ## Interfaces and unions
331
447
 
@@ -341,6 +457,8 @@ What an interface adds is its fields, declared once and resolved on many types:
341
457
 
342
458
  ## Telemetry
343
459
 
460
+ **When something raises during an object's check.** If a policy raises and a `rescue_from` handles the error, the handler runs and the object is denied, whatever the handler answers. Without a handler the error reaches the request. This includes a `GraphQL::ExecutionError`: when a `rescue_from` catches it, its message does not reach the client, who gets the ordinary denial.
461
+
344
462
  The decisions are visible to you and not to the client. Pass `sinks:` to hear each one:
345
463
 
346
464
  ```ruby
@@ -349,7 +467,7 @@ use GraphQL::Armory::Authorization, adapter: :pundit,
349
467
  # armory denied {:type=>"Invoice", :action=>:read}
350
468
  ```
351
469
 
352
- Signals are `:allowed`, `:denied`, `:bypassed` (an `authorize :none` rule ran) and `:scoped` (a list went through the user's scope). Data holds only `type`, `action` and `reason`, never record attributes. `GraphQL::Armory::Telemetry::Notifications` reports them to `ActiveSupport::Notifications`. Every signal, what to watch for and how to test it: [Telemetry](telemetry.md). A `sinks:` that is not an Array of callables raises `Telemetry::ConfigurationError` at boot.
470
+ Signals are `:allowed`, `:denied`, `:observed` (a rule under `observe:` would have refused; its data also holds the `reason`), `:bypassed` (an `authorize :none` rule ran) and `:scoped` (a list went through the user's scope). Data holds only `type`, `action` and `reason`, never record attributes. `GraphQL::Armory::Telemetry::Notifications` reports them to `ActiveSupport::Notifications`. Every signal, what to watch for and how to test it: [Telemetry](telemetry.md). A `sinks:` that is not an Array of callables raises `Telemetry::ConfigurationError` at boot.
353
471
 
354
472
  ## Guarantees and limits
355
473
 
@@ -137,7 +137,7 @@ The signal never holds the ID, the key or the record. A rising `:invalid` is som
137
137
  | `decode(id)` / `decode(cursor, nonce: true)` | The text, or raises `GraphQL::Armory::Encoder::InvalidError` (a `GraphQL::ExecutionError`, so clients see `Invalid ID or cursor`). |
138
138
  | `Encoder.versioned(newest, ..., oldest)` | A chain with the same `encode` and `decode`; encodes with `newest`. |
139
139
  | `chain.decode_versioned(text, nonce: false)` | `[data, encoder]`, or `[nil, nil]` when no encoder accepts it. |
140
- | `use GraphQL::Armory::IDs, encoder: nil, find: nil, sinks: []` | Defines `id_from_object` and `object_from_id`; `encoder` defaults to `Encoder.default`; `find:` loads types without `Base`; `sinks:` hears `:id_resolved` and `:id_refused` ([Telemetry](telemetry.md)). |
140
+ | `use GraphQL::Armory::IDs, encoder: nil, find: nil, sinks: [], on_sink_error: nil` | Defines `id_from_object` and `object_from_id`; `encoder` defaults to `Encoder.default`; `find:` loads types without `Base`; `sinks:` hears `:id_resolved` and `:id_refused` ([Telemetry](telemetry.md)). |
141
141
  | `Encoder.default` | An encoder keyed by `GRAPHQL_ARMORY_KEY`, else by a key derived with HKDF from Rails' `secret_key_base`; raises `ConfigurationError` without either. |
142
142
 
143
143
  A subclass inherits `key`, `tag` and `codec`, and can override any of them. Passing `nil` to any of them raises `ConfigurationError`, so an unset environment variable fails at boot instead of being ignored.
@@ -38,6 +38,21 @@ If the ordering values are not secret (a public list ordered by id), you can kee
38
38
  GraphQL::Armory::Keyset.build(Article.order(:id), plain_cursors: true)
39
39
  ```
40
40
 
41
+ ### Checking the encoder when the app loads
42
+
43
+ Without more, a schema that cannot keep cursors private is refused on the first keyset page, in a request. `use` moves that to when the schema class loads, and looks further than the default encoder:
44
+
45
+ ```ruby
46
+ class AppSchema < GraphQL::Schema
47
+ cursor_encoder AppEncoder
48
+ use GraphQL::Armory::Keyset # below cursor_encoder
49
+ end
50
+ ```
51
+
52
+ It probes the encoder, and refuses one that does not give back what it encoded, leaves the text readable (plain, Base64 or hex, also behind a prefix, ROT13, reversed), changes only part of its output when the input changes (a fixed key, or a real cipher with a fixed nonce or IV), or decodes forged text. Any encoder set later on that schema or on a subclass goes through the same check.
53
+
54
+ `use GraphQL::Armory::Keyset, plain_cursors: true` turns the check off and makes readable cursors the schema's default. Then `Keyset.build(relation)` needs no option of its own, and an explicit `plain_cursors:` on `build` still wins.
55
+
41
56
  ### What it can order by
42
57
 
43
58
  The relation must be ordered by plain, non-null columns of its own table. The primary key is added as the last column, to break ties, so a relation with no order pages by primary key. `build` raises `Keyset::ConfigurationError` for:
@@ -64,10 +79,14 @@ If your own type defines `scope_items`, it receives the `Keyset` object and not
64
79
 
65
80
  ## Reference
66
81
 
67
- `GraphQL::Armory::Keyset.build(relation, plain_cursors: false)`
82
+ `use GraphQL::Armory::Keyset, plain_cursors: false`, optional, on a schema.
83
+
84
+ - `plain_cursors:` is `true` or `false`. `true` skips the check and is what `build` follows when it is given none. A subclass inherits it, and its own `use` replaces it.
85
+
86
+ `GraphQL::Armory::Keyset.build(relation, plain_cursors: nil)`
68
87
 
69
88
  - `relation`: an ActiveRecord relation, checked as above.
70
- - `plain_cursors:` is `true` or `false`. `true` allows the schema's default Base64 encoder.
89
+ - `plain_cursors:` is `true`, `false` or `nil`. `true` allows the schema's default Base64 encoder. `nil` follows the schema's `use`, or `false` with no `use`.
71
90
 
72
91
  Errors:
73
92
 
@@ -75,6 +94,7 @@ Errors:
75
94
  |---|---|
76
95
  | Boot or resolver, a relation it cannot page | `Keyset::ConfigurationError` |
77
96
  | First page, the schema has the default encoder and no `plain_cursors: true` | `Keyset::ConfigurationError` |
97
+ | `use` or a later `cursor_encoder`, an encoder that fails the check | `Keyset::ConfigurationError`, naming an error's class and never its message |
78
98
  | A cursor that is tampered, malformed, or made for another ordering | `Invalid ID or cursor`, the same for all |
79
99
  | `first` and `last` together | `first and last cannot be used together` |
80
100
 
@@ -83,8 +103,12 @@ Errors:
83
103
  - Every row present for the whole walk is seen exactly once, whatever is inserted or deleted meanwhile.
84
104
  - A row whose ordering value **changes** between pages can be skipped or seen twice: it really moved. Order by columns that do not change (a creation time, an id) when this matters.
85
105
  - A row inserted behind the cursor is not seen on the way forward, as in any pagination.
86
- - The encoder check runs on the first page, not at boot, because the connection reads the encoder from the schema of the query.
87
- - The check only knows the default Base64 encoder. A custom encoder that does not encrypt passes unnoticed: a keyset cursor is only as private as your `cursor_encoder`.
106
+ - With no `use`, the encoder check runs on the first page and only knows the default Base64 encoder: a custom encoder that does not encrypt passes unnoticed.
107
+ - With `use`, the check runs when the schema class loads, which is not boot if your app autoloads it lazily, and it cannot prove encryption: a keyed cipher that fails none of the probes passes, sound or not. A keyset cursor is only as private as your `cursor_encoder`.
108
+ - The check calls your encoder when the schema loads, so an encoder whose key is not there yet (during `assets:precompile`, or set in a later initializer) is refused. Fix the load order, or leave out `use` for that step: the check on the first page stays.
109
+ - Every member of an `Encoder.versioned` chain is checked on its own, because each one decodes what a client sends. `Encoder.versioned(New, Encoder::Legacy)` is refused: during such a migration a client can read and make its own cursors, so state it with `plain_cursors: true`.
110
+ - `use` checks the encoders set after it. A subclass that already set its own encoder before `use` ran on its parent is not checked: put `use` in the base schema, before any subclass is defined.
111
+ - A `Keyset` subclass that overrides `encode` or `decode` is not checked. Setting the encoder through `instance_variable_set` is not checked.
88
112
  - With `plain_cursors: true` a client can read the ordering values and forge a cursor. It stays inside the scope and its values are bound, never interpolated, but it can probe those columns.
89
113
  - A forged value on a plain cursor must have the form the column's own cursors have (an Integer, a plain decimal, an ISO 8601 date or time) or it is an invalid cursor. A forged value of the right form is honoured: it pages from there.
90
114
  - Encryption keeps length, so the length of an encrypted cursor reveals roughly the length of a string ordering value.