graphql-armory 0.1.0.pre9 → 0.1.0.pre11
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -0
- data/README.md +5 -5
- data/docs/authorization.md +45 -3
- data/docs/keyset-connections.md +28 -4
- data/docs/rate-limiting.md +7 -4
- data/lib/graphql/armory/authorization/audit/baseline.rb +3 -3
- data/lib/graphql/armory/authorization/audit/denial_hooks.rb +3 -3
- data/lib/graphql/armory/authorization/audit/edge_rules.rb +1 -1
- data/lib/graphql/armory/authorization/audit/findings.rb +5 -4
- data/lib/graphql/armory/authorization/audit/foreign_policies.rb +2 -2
- data/lib/graphql/armory/authorization/audit/input_loads.rb +1 -1
- data/lib/graphql/armory/authorization/audit/interface_rules.rb +3 -3
- data/lib/graphql/armory/authorization/audit/introspection_fields.rb +1 -1
- data/lib/graphql/armory/authorization/audit/observed_rules.rb +7 -17
- data/lib/graphql/armory/authorization/audit/overrides.rb +3 -3
- data/lib/graphql/armory/authorization/audit/own_checks.rb +6 -6
- data/lib/graphql/armory/authorization/audit/payload_reuse.rb +1 -1
- data/lib/graphql/armory/authorization/audit/plain_resolvers.rb +1 -1
- data/lib/graphql/armory/authorization/audit/report.rb +11 -4
- data/lib/graphql/armory/authorization/audit/type_rules.rb +32 -31
- data/lib/graphql/armory/authorization/audit/visibility_models.rb +5 -5
- data/lib/graphql/armory/authorization/audit.rb +2 -2
- data/lib/graphql/armory/authorization/integration/argument.rb +3 -0
- data/lib/graphql/armory/authorization/integration/field.rb +4 -0
- data/lib/graphql/armory/authorization/integration/object.rb +5 -1
- data/lib/graphql/armory/authorization/integration/resolver.rb +4 -0
- data/lib/graphql/armory/authorization/integration/root_check.rb +35 -0
- data/lib/graphql/armory/authorization/integration.rb +52 -5
- data/lib/graphql/armory/authorization/location.rb +79 -0
- data/lib/graphql/armory/authorization.rb +2 -0
- data/lib/graphql/armory/keyset/encoder_check.rb +113 -0
- data/lib/graphql/armory/keyset.rb +23 -3
- data/lib/graphql/armory/rate_limits/analysis_guard.rb +107 -11
- data/lib/graphql/armory/rate_limits/concurrency.rb +2 -0
- data/lib/graphql/armory/rate_limits/invalid_queries.rb +75 -0
- data/lib/graphql/armory/rate_limits/points.rb +44 -7
- data/lib/graphql/armory/rate_limits/time.rb +36 -6
- data/lib/graphql/armory/rate_limits.rb +1 -0
- data/lib/graphql/armory/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 806e32d543ac297787237c89d5b137e5b0e46a2469ee333e4ac472d98e246ace
|
|
4
|
+
data.tar.gz: 9275c166d94a47a9b5886d0891ab92c7cb302f06a3aaee14d82dc7124b2b5e0a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82702af877de36315a8aadc8cd56d58926dfb03a29fa166ef43500d3171a7da2a4becb1dd28fcb72d4cbc0bada3b9e031e23235c9100dcea921ad9c1bbe4dfff
|
|
7
|
+
data.tar.gz: 8ed7fc17baa6374e8fd05ee22aedbba744d95986ed213d9404620e0cfcf49eab0ba83f716c99fd77c84e682f2f96213a8be1457ef0cec5661f66e5a11e877bde
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.1.0.pre11 (2026-11-03)
|
|
6
|
+
|
|
7
|
+
This release closes the ways an [Authorization](docs/authorization.md) rule under `observe:` could still let a resolver or its arguments run for a user the rule would refuse, and gives every misconfigured observed root the same error on every engine. It also makes [the audit](docs/authorization.md#the-audit) say the file and line of each problem. Anyone using `observe:` or comparing audit problems as whole structs should read Breaking before upgrading.
|
|
8
|
+
|
|
9
|
+
### Breaking
|
|
10
|
+
|
|
11
|
+
- `Audit::Report::Problem` and `Bypass` have one more member, `location`, so `to_a`, `to_h` and `==` against a `Problem.new(kind, path, message)` built by hand change. To upgrade: compare `kind`, `path` and `message` (or `to_s`), not the whole struct. (#55)
|
|
12
|
+
- A type that inherits a resolver or mutation field with `authorize: true` from a class whose rule is under `observe:` now raises `ConfigurationError` when the type is checked, on every query that reaches it, not only when the field is asked for, including a mutation argument that `loads:` that type (the mutation no longer runs). Before, the field's arguments were prepared (`prepare:` ran) for a user the rule would refuse, and only then did the field raise. The audit already reported this shape as "raises on every query". To upgrade: remove `observe:` from that class, or give the field a rule of its own. Limit: with `max_complexity`, graphql-ruby's complexity analysis still coerces a connection's or a `complexity:` lambda's arguments before any check. (#36, #56)
|
|
13
|
+
- An observed root type holding a resolver or a mutation now raises `ConfigurationError` from `execute` before anything runs, on every engine and past any `rescue_from`; in a multiplex, the whole multiplex raises. Before, the interpreter with graphql 2.6 reported a `NoMethodError`, and a `rescue_from(StandardError)` handler turned it into an empty answer. An invalid document keeps its validation errors, and a partial (`run_partials`) is left to its type's check. To upgrade: run the audit, which names the type, and fix it before deploying. (#37, #57)
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- The audit says the file and line of each problem and bypass. `Problem#location` and `Bypass#location` hold it as `"path:line"`, and the printed report and the baseline result add `(at path:line)` to each line. A field or an argument gives the line that declared it (with `Base`), a type, a mutation or a resolver the line of its `authorize`, an own check or a denial hook its method. The baseline ignores it, so moving code does not make an accepted problem new. Limits: `nil` for a schema built from SDL; a field declared by a helper gives the helper's line. [The audit](docs/authorization.md#the-audit). (#55)
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- An observed type no longer lets a parent's resolver run when a subclass overrides that field with one hidden from the user (`visible_when:` or `visible?`): the legacy Warden served the parent's definition, which the check did not read. It now raises `ConfigurationError`, like any type holding a resolver. Under `Schema::Visibility` there was no fallback. Schemas without `observe:` ask no extra policy question. (#38, #57)
|
|
22
|
+
|
|
23
|
+
## 0.1.0.pre10 (2026-11-03)
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
### Breaking
|
|
28
|
+
|
|
29
|
+
- 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)
|
|
30
|
+
- 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)
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- `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)
|
|
35
|
+
|
|
36
|
+
### Docs
|
|
37
|
+
|
|
38
|
+
- 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)
|
|
39
|
+
|
|
5
40
|
## 0.1.0.pre9 (2026-11-02)
|
|
6
41
|
|
|
7
42
|
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.
|
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.
|
|
9
|
+
> **Status: early development.** Prereleases on RubyGems (`0.1.0.pre11`). The API may change before 1.0.
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
13
|
```ruby
|
|
14
|
-
gem "graphql-armory", "~> 0.1.0.
|
|
14
|
+
gem "graphql-armory", "~> 0.1.0.pre11" # a prerelease: `gem install graphql-armory --pre`
|
|
15
15
|
gem "pundit" # or "cancancan", for the authorization module
|
|
16
16
|
```
|
|
17
17
|
|
|
@@ -23,11 +23,11 @@ Status: ✅ released, 🚧 in progress, ⬜ not started. Update this table in th
|
|
|
23
23
|
|
|
24
24
|
| Order | Module | Status | Docs | Current limits |
|
|
25
25
|
|---|---|---|---|---|
|
|
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. |
|
|
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. The audit gives the file and line of each problem from 0.1.0.pre11. |
|
|
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
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. |
|
|
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. |
|
|
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. |
|
data/docs/authorization.md
CHANGED
|
@@ -163,9 +163,9 @@ When the policy answers `false` or `nil`, **the data is served to a user the rul
|
|
|
163
163
|
| A type or field with no rule | Denied: there is no rule to observe |
|
|
164
164
|
| A mutation or a subscription, including a read in its response | Refused: only a query runs |
|
|
165
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 |
|
|
168
|
-
| `authorize: true` with a resolver, where the type's rule is observed | Raises `ConfigurationError
|
|
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, unless the override is hidden from the user and the legacy Warden falls back to it | 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 of the operation | Raises `ConfigurationError` from `execute` before anything runs, on every engine, past any `rescue_from`; in a multiplex, the whole multiplex raises. An invalid document keeps its validation errors. A partial (`run_partials`) and a query whose `context[:trace]` was built without the schema's trace modules skip this and fall back to the type's check, whose error graphql-ruby hands to `rescue_from` (on the interpreter with graphql 2.6, as a `NoMethodError` caused by it). Below the root, a type that cannot be observed is refused in its own check, so a `rescue_from` can turn it into an empty field: run the audit, which names the type |
|
|
168
|
+
| `authorize: true` with a resolver, where the type's rule is observed | Raises `ConfigurationError` when the type that serves it is checked, on every query that reaches that type, before the field's arguments are coerced during execution. A parent's resolver field a subclass overrides counts when the legacy Warden hides the override from this user and falls back to it. Two exceptions run the arguments' `prepare:` first: objects of a scoped list under `reauthorize_scoped_objects(false)` (the type's check does not run for them, and the field's own check then raises); and a schema with `max_complexity` (or graphql-ruby's complexity analysis), which coerces the arguments of a connection field or a field with a `complexity:` lambda during analysis, before any type or field check, for every field rule |
|
|
169
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
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
171
|
| `visible_when:` | Still hides: the rule it builds is not observed |
|
|
@@ -220,6 +220,13 @@ load "tasks/graphql_armory.rake"
|
|
|
220
220
|
|
|
221
221
|
**What it reports.** Each problem has a `kind`, a `path` and a `message`. Every declared bypass is listed apart, with its reason.
|
|
222
222
|
|
|
223
|
+
**Where it is.** Each problem and bypass also has a `location`, the file and line it is about, relative to the directory the app started in when it is inside it, and the printed report adds it: `Invoice (no_rule): has no rule and no default_action, so it is denied (at app/graphql/types/invoice_type.rb:3)`.
|
|
224
|
+
- A field or an argument gives the line that declared it, when its class includes `Base`; otherwise the line of its type.
|
|
225
|
+
- A type, a mutation or a resolver gives the line of its own `authorize`, or else of its class.
|
|
226
|
+
- An own check or a denial hook gives the line of its method.
|
|
227
|
+
|
|
228
|
+
`location` is `nil` when there is no Ruby line to give: a schema built from SDL, or a class with no name and no `authorize` of its own. A field declared by a helper method gives the helper's line, and a class reopened in several files gives the first one. The location is not part of a problem for the [baseline](#adopting-it-on-a-schema-with-many-problems): moving code never turns an accepted problem into a new one.
|
|
229
|
+
|
|
223
230
|
| Kind | What it means | What to do |
|
|
224
231
|
|---|---|---|
|
|
225
232
|
| `:plugin` | The schema never installed the plugin. | Add `use GraphQL::Armory::Authorization, adapter: ...`. |
|
|
@@ -271,6 +278,41 @@ expect(AppSchema).to be_fully_authorized(baseline: "config/graphql_armory_baseli
|
|
|
271
278
|
|
|
272
279
|
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
280
|
|
|
281
|
+
### Measuring before you adopt
|
|
282
|
+
|
|
283
|
+
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:
|
|
284
|
+
|
|
285
|
+
```ruby
|
|
286
|
+
# script/armory_audit.rb. Run it on its own, never in the process of your app or of your other specs.
|
|
287
|
+
require_relative "../config/environment"
|
|
288
|
+
Rails.application.eager_load!
|
|
289
|
+
|
|
290
|
+
z = GraphQL::Armory::Authorization
|
|
291
|
+
[Types::BaseObject, Types::BaseField, Types::BaseArgument, Types::BaseInputObject, Mutations::BaseMutation].each { |base| base.include(z::Base) }
|
|
292
|
+
Types::BaseObject.default_action(:read)
|
|
293
|
+
|
|
294
|
+
simulated = Class.new(AppSchema) do
|
|
295
|
+
use z, adapter: :pundit,
|
|
296
|
+
own_checks: { Types::BaseField => { authorized?: "adds the status check, then calls super" } }
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
path = "config/graphql_armory_baseline.json"
|
|
300
|
+
report = z::Audit.(simulated)
|
|
301
|
+
z::Audit::Baseline.write(report, path) unless File.exist?(path) # once; commit the file
|
|
302
|
+
result = z::Audit::Baseline.load(path).(report)
|
|
303
|
+
puts result.new_problems
|
|
304
|
+
exit(result.passes? ? 0 : 1)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
`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.
|
|
308
|
+
|
|
309
|
+
What to do first with a long list:
|
|
310
|
+
|
|
311
|
+
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.
|
|
312
|
+
2. **`:unscoped_list` and `:unscoped_load`.** These reach data of other users once a rule is in place.
|
|
313
|
+
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`.
|
|
314
|
+
4. **`:model`.** Usually the longest part of the list, and the slowest: each type needs a model and a policy.
|
|
315
|
+
|
|
274
316
|
### Redefined fields and arguments
|
|
275
317
|
|
|
276
318
|
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:
|
data/docs/keyset-connections.md
CHANGED
|
@@ -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
|
|
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 `
|
|
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
|
-
-
|
|
87
|
-
-
|
|
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.
|
data/docs/rate-limiting.md
CHANGED
|
@@ -277,6 +277,8 @@ store.calls # [[:take, "user:1", { cost:
|
|
|
277
277
|
- `window:` positive seconds over which `limit` points refill, continuously.
|
|
278
278
|
- `soft:` `true` (default) charges and records without refusing; `false` refuses.
|
|
279
279
|
- `key:` a callable `(query)` answering the client key; by default `context[:rate_limit_key]`. It must be a non-empty String, or a list of up to 5 different ones for all three limiters: a query runs only if every key allows it. The record, the headers and the extensions show the key that binds, and the record adds `keys:` with each one. The refusals a client sees never name a key. Without one, the query raises `ConfigurationError`, on every query: a key built from something that can be nil (an IP behind a misconfigured balancer) needs a fallback, such as `context[:rate_limit_key] = request.remote_ip.presence || "unknown"`, where all such clients share one bucket.
|
|
280
|
+
- A query with no key raises `RateLimits::ConfigurationError` when it runs, not at boot, so a controller that forgets the key, or a `request.remote_ip` that comes out nil behind a load balancer, breaks every query that reaches the limiter. Cover each controller with a request spec.
|
|
281
|
+
- `invalid_cost:` on `Points`, a positive Integer or nil: the points an invalid query costs. Default 1; nil charges nothing.
|
|
280
282
|
- `on_store_error:` a callable `(error, query)` called when the store raises; the query then runs (fails open). By default it warns.
|
|
281
283
|
- `sinks:` callables that hear `:rate_limit_store_failed` when the store raises; see [Telemetry](telemetry.md#rate-limiting).
|
|
282
284
|
- `extensions:` `true` adds `"rateLimit" => { cost, limit, remaining, resetIn }` to every response of a limited client; `false` (default) leaves responses unchanged.
|
|
@@ -311,11 +313,12 @@ Invalid settings raise `RateLimits::ConfigurationError` at boot.
|
|
|
311
313
|
|
|
312
314
|
## Guarantees and limits
|
|
313
315
|
|
|
314
|
-
- A query this limiter refuses resolves no field and is not charged. A query
|
|
316
|
+
- A query this limiter refuses resolves no field and is not charged. A query refused by another analyzer (`max_depth`, `max_complexity`) is still charged: graphql-ruby runs every analyzer.
|
|
315
317
|
- Each query in a multiplex is charged on its own.
|
|
316
318
|
- With several keys, `Points` reads every balance and then charges, so a refused query leaves the others as they were. Two queries racing between those steps can leave a refused one having charged other keys. `Concurrency` gives back the slots a refused query took at once. `Time` charges every key the whole time; a store failure on one key does not stop the others.
|
|
317
|
-
- An
|
|
318
|
-
-
|
|
319
|
+
- An invalid query (a syntax error, a validation error including a variable of the wrong type or a missing required one, no query string, or a refusal from `PersistedQueries` in strict mode) is charged `invalid_cost:` points after it answers; its answer does not change. This penalises the client's next valid query: it does not stop a flood of invalid ones, which are parsed and validated all the same, and a bucket stops at zero. A query the analyzers refused is not invalid: it is charged as before, also when a multiplex analyzer refuses the whole multiplex. Keys are charged in list order, as if the queries had come one at a time: a key that cannot pay all of it pays what it holds, and the keys after it pay only that much, so sending invalid queries together never costs a client less than sending them apart. Put the narrowest key first: a client with nothing left cannot keep draining a bucket it shares. Keys must not depend on the document or the variables, which an invalid query may not have. Failures here, including a query with no key, go to `on_store_error` and never replace the answer, so a missing key on an invalid query does not raise. A trace does this after the multiplex, also when an exception ends it early: then queries that never reached validation are validated to find the invalid ones. A query run with its own trace (`context[:trace]`, or a class given to `trace_mode`) is not charged.
|
|
320
|
+
- An `ExecutionError` raised during analysis, which graphql-ruby would discard before running the query, does not skip a limiter. A refusal already given stands. A limiter not asked yet is asked on its own, so another analyzer's raise still charges the query. A limiter that cannot answer, because a `complexity:` lambda or its `on_store_error` hook raised, refuses the query in hard mode with the code `RATE_LIMIT_NOT_CHARGED`, and in soft mode lets it run and records `charged: false`. A client with no limit still runs, and a query with no key raises `ConfigurationError`. When a query takes this path it is visited once more per limiter not asked yet and per other analyzer (see below), so a `complexity:` lambda can run several times, `key:` and `limit:` are asked again, and a validation timeout can take longer. An analysis your app runs itself outside an execution charges nothing here. A trace that takes no modules from the schema (`context[:trace]` or a class given to `trace_mode`) is outside this: `Points` is not protected on such a trace.
|
|
321
|
+
- On the same path every query analyzer that is not a limiter is then asked on its own. A refusal it returns stands, such as a `max_depth` or `max_complexity` refusal, and so does an `AnalysisError` it raises from `result`, with its own message. One that raises anything else again cannot answer, and the query is refused with the code `QUERY_LIMIT_UNKNOWN`, in soft mode and for a client with no limit too, because otherwise a client could get past that analyzer by asking for the field that makes it raise. That covers `max_complexity` with a `complexity:` lambda that raises and your own maximums alike. So do not raise `ExecutionError` from a `complexity:` lambda or an analyzer: an authorization check belongs in the field. Multiplex analyzers, including a `max_complexity` for a whole multiplex (which `Schema.multiplex` takes from the schema by default), cannot be asked again. When a raise stopped the visit before its end, a query in a multiplex with any multiplex analyzer is refused the same way. A lambda raises after the visit, when the multiplex analyzers have seen the whole query, so it is not refused for that. Each analyzer is asked once more at most, each with the whole remaining validation timeout, so a query on this path can take one more visit per analyzer, and an analyzer with side effects repeats them. After a validation timeout no other analyzer is asked again, since the query is already refused; a limiter not asked yet still is. Limits: this needs a rate limiter on the schema, since a schema with none keeps graphql-ruby's behaviour and the refusal is lost. An analyzer's refusal stands only if it answers the same way when asked again: one that remembers in the context that it already refused is lost. A refusal an analyzer raises as `AnalysisError` during the visit, followed by an `ExecutionError` from the same analyzer, becomes `QUERY_LIMIT_UNKNOWN` without its message. The multiplex analyzers keep the part of a refused query they saw before its visit raised, though it does not run.
|
|
319
322
|
- On `Execution::Next`, `validate: false` ignores every refusal from analysis, the limiters' included. Never pass it for a client's query.
|
|
320
323
|
- A field with `max_page_size: nil` under a schema with `default_max_page_size` is sized by that default, while at runtime it has no maximum, so it is charged less than it returns. Give such a field a number.
|
|
321
324
|
- An `ExecutionError` from a multiplex analyzer's `result` raises to your app: nothing runs and no slot stays held.
|
|
@@ -340,7 +343,7 @@ Invalid settings raise `RateLimits::ConfigurationError` at boot.
|
|
|
340
343
|
- A multiplex has one measured time, split equally among the queries this limiter charges, rounded up to whole milliseconds: fields of different queries interleave, so their time cannot be told apart. A query refused by `Time`, and one whose key has no limit (`nil`), are not part of the split, so the time of a query with no limit is carried by the limited ones.
|
|
341
344
|
- A schema may `use Time` more than once, with different stores or keys (for example per user and per IP): each limiter charges only its own. `context[:rate_limit_time]`, the response extension and `Time.headers` then hold the record of the last one.
|
|
342
345
|
- The clock must answer a finite number of seconds: one that does not is refused at boot, and one that breaks later raises instead of letting operations run uncharged. A clock that stands still or goes backwards charges 0.
|
|
343
|
-
- Time spent before analysis finishes (parsing, validation) is charged to no one, and
|
|
346
|
+
- Time spent before analysis finishes (parsing, validation) is charged to no one, and it is part of what a multiplex splits. Invalid queries pay time only in a multiplex with no query that ran: there they split it, charged like on `Points` (a key that cannot pay all of its share pays what it holds, and the keys after it pay only that much). Next to a query that ran they pay no time, so padding a multiplex with invalid queries never lowers what that query pays.
|
|
344
347
|
- The time is wall-clock, so it grows when the server is loaded: the same query costs a client more on a busy server. Choose `limit` with that in mind, and start in soft mode.
|
|
345
348
|
- A query run with its own trace (`context: { trace: ... }`) cannot be charged, so it raises `ConfigurationError`, as with `Concurrency`.
|
|
346
349
|
- When the store fails, operations run unlimited and `on_store_error` is called; a failed charge never raises into the query (unless your hook does).
|
|
@@ -42,7 +42,7 @@ module GraphQL
|
|
|
42
42
|
sections = [
|
|
43
43
|
section("#{new_problems.size} new #{plural('problem', new_problems.size)}:", new_problems.map { |problem| new_line(problem) }),
|
|
44
44
|
section("#{gone.size} accepted #{plural('problem', gone.size)} no longer found (remove them from the baseline):", gone.map { |entry| "#{entry.path} (#{entry.kind}): #{entry.message}" }),
|
|
45
|
-
section("#{accepted.size} accepted in the baseline, still open:", accepted),
|
|
45
|
+
section("#{accepted.size} accepted in the baseline, still open:", accepted.map { |problem| Report.line(problem.to_s, problem.location) }),
|
|
46
46
|
bypasses_text
|
|
47
47
|
].compact
|
|
48
48
|
sections.unshift("Passes only because of its baseline.") if passes? && !accepted.empty?
|
|
@@ -54,7 +54,7 @@ module GraphQL
|
|
|
54
54
|
|
|
55
55
|
def new_line(problem)
|
|
56
56
|
extra = grown[problem]
|
|
57
|
-
extra ? "#{problem} (it now also reaches #{extra.join(', ')})" : problem.to_s
|
|
57
|
+
Report.line(extra ? "#{problem} (it now also reaches #{extra.join(', ')})" : problem.to_s, problem.location)
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def section(title, lines)
|
|
@@ -64,7 +64,7 @@ module GraphQL
|
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def bypasses_text
|
|
67
|
-
section("#{report.bypasses.size} declared #{report.bypasses.size == 1 ? 'bypass' : 'bypasses'}:", report.bypasses.map { |bypass| "#{bypass.path}: #{bypass.reason}" })
|
|
67
|
+
section("#{report.bypasses.size} declared #{report.bypasses.size == 1 ? 'bypass' : 'bypasses'}:", report.bypasses.map { |bypass| Report.line("#{bypass.path}: #{bypass.reason}", bypass.location) })
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def plural(word, count)
|
|
@@ -13,12 +13,12 @@ module GraphQL
|
|
|
13
13
|
path = "Schema.#{hook}"
|
|
14
14
|
own = schema.method(hook).owner != Integration::Schema
|
|
15
15
|
if own && declared.key?(hook)
|
|
16
|
-
findings.bypass(path, declared[hook])
|
|
16
|
+
findings.bypass(path, declared[hook], at: schema.method(hook))
|
|
17
17
|
elsif own
|
|
18
18
|
findings.problem(:hook, path, "the schema's own method runs instead of the plugin's, so on_unauthorized: does not apply and a denial " \
|
|
19
|
-
"may reveal what it hides: remove it, or declare it in own_denial_hooks: with a reason")
|
|
19
|
+
"may reveal what it hides: remove it, or declare it in own_denial_hooks: with a reason", at: schema.method(hook))
|
|
20
20
|
elsif declared.key?(hook)
|
|
21
|
-
findings.problem(:hook, path, "named in own_denial_hooks: but the plugin's hook is the one that runs: remove it from the option")
|
|
21
|
+
findings.problem(:hook, path, "named in own_denial_hooks: but the plugin's hook is the one that runs: remove it from the option", at: schema)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -15,7 +15,7 @@ module GraphQL
|
|
|
15
15
|
|
|
16
16
|
findings.problem(:ignored_rule, type.graphql_name, "the connection's nodes field returns the nodes without building an edge, so this rule does not " \
|
|
17
17
|
"cover it: put the rule on the field that returns the connection (on a root field, on a resolver: " \
|
|
18
|
-
"a field rule asks the parent's policy), or remove the nodes field with has_nodes_field(false)")
|
|
18
|
+
"a field rule asks the parent's policy), or remove the nodes field with has_nodes_field(false)", at: type)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -11,16 +11,17 @@ module GraphQL
|
|
|
11
11
|
@bypasses = []
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
# `at:` is what the problem is about (a type, a field, an argument or a method), for its file and line.
|
|
15
|
+
def problem(kind, path, message, at: nil)
|
|
16
|
+
@problems << Report::Problem.new(kind, path, message, Location.of(at))
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def problem?(kind, path = nil)
|
|
19
20
|
@problems.any? { |problem| problem.kind == kind && (path.nil? || problem.path == path) }
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
def bypass(path, reason)
|
|
23
|
-
@bypasses << Report::Bypass.new(path, reason)
|
|
23
|
+
def bypass(path, reason, at: nil)
|
|
24
|
+
@bypasses << Report::Bypass.new(path, reason, Location.of(at))
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
def report(reach = nil)
|
|
@@ -54,7 +54,7 @@ module GraphQL
|
|
|
54
54
|
return if same || !@seen.add?([resolver, path, policy])
|
|
55
55
|
|
|
56
56
|
@findings.problem(:foreign_policy, path, "its resolver's rule asks #{asked || "the policy found from its model"}, not #{policy}, the `policy:` of this type. " \
|
|
57
|
-
"Name the same `policy:` on the resolver")
|
|
57
|
+
"Name the same `policy:` on the resolver", at: resolver)
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def note(member, path, policy, model)
|
|
@@ -63,7 +63,7 @@ module GraphQL
|
|
|
63
63
|
|
|
64
64
|
asked = member.armory_policy || "the policy found from the record"
|
|
65
65
|
@findings.problem(:foreign_policy, path, "its rule asks #{asked}, not #{policy}, the `policy:` of this type: it is defined on a class that does not name that policy. " \
|
|
66
|
-
"Move the rule to the class that names it and remove the original, or name the `policy:` on the class that defines the rule, if it can hold one")
|
|
66
|
+
"Move the rule to the class that names it and remove the original, or name the `policy:` on the class that defines the rule, if it can hold one", at: member)
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
# With no `policy:` of its own, a rule asks what the adapter finds from the model, which may be the same policy.
|
|
@@ -15,7 +15,7 @@ module GraphQL
|
|
|
15
15
|
input.all_argument_definitions.select(&:loads).reject(&:from_resolver?).each do |argument|
|
|
16
16
|
name = GraphQL::Schema::Member::BuildType.underscore(argument.graphql_name)
|
|
17
17
|
findings.problem(:unscoped_load, "#{input.graphql_name}(#{name})",
|
|
18
|
-
"its input object class does not include Base, so it loads through the app's object_from_id, not the user's scope")
|
|
18
|
+
"its input object class does not include Base, so it loads through the app's object_from_id, not the user's scope", at: argument)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -22,15 +22,15 @@ module GraphQL
|
|
|
22
22
|
path = "#{interface.graphql_name}.#{field.original_name}"
|
|
23
23
|
PlainResolvers.report(findings, path, field) if covered && !bypassed && PlainResolvers.open?(field)
|
|
24
24
|
unless field.respond_to?(:armory_declared)
|
|
25
|
-
findings.problem(:unprotected, path, "its field class does not include Base, so it is not checked on a bypassed implementer") if bypassed
|
|
25
|
+
findings.problem(:unprotected, path, "its field class does not include Base, so it is not checked on a bypassed implementer", at: field) if bypassed
|
|
26
26
|
next
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
case field.armory_declared
|
|
30
30
|
when true
|
|
31
|
-
findings.problem(:field_without_rule, path, "uses authorize: true, but an interface has no action of its own, so it is always denied")
|
|
31
|
+
findings.problem(:field_without_rule, path, "uses authorize: true, but an interface has no action of its own, so it is always denied", at: field)
|
|
32
32
|
when nil
|
|
33
|
-
findings.problem(:field_without_rule, path, "declares no rule and an implementing type is bypassed, so it is denied") if bypassed
|
|
33
|
+
findings.problem(:field_without_rule, path, "declares no rule and an implementing type is bypassed, so it is denied", at: field) if bypassed
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
end
|
|
@@ -31,7 +31,7 @@ module GraphQL
|
|
|
31
31
|
name = field.graphql_name
|
|
32
32
|
return if field.owner.superclass.fields[name].equal?(built_in.fields[name])
|
|
33
33
|
|
|
34
|
-
@findings.problem(:unprotected, "#{field.owner.graphql_name}.#{name}", "is a custom introspection field, so no type's rule runs on it: move it to a type with a rule")
|
|
34
|
+
@findings.problem(:unprotected, "#{field.owner.graphql_name}.#{name}", "is a custom introspection field, so no type's rule runs on it: move it to a type with a rule", at: field)
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -9,40 +9,30 @@ module GraphQL
|
|
|
9
9
|
def self.call(schema, definitions, findings)
|
|
10
10
|
definitions.each do |type|
|
|
11
11
|
rule = type.armory_rule if type.respond_to?(:armory_rule)
|
|
12
|
-
report(findings, type.graphql_name, rule.observe, unobservable(type)) if rule&.observed?
|
|
12
|
+
report(findings, type.graphql_name, rule.observe, unobservable(type), at: type) if rule&.observed?
|
|
13
13
|
next unless type.respond_to?(:fields)
|
|
14
14
|
|
|
15
15
|
Definitions.fields_at_every_level(type).each do |field|
|
|
16
|
-
reason = observed_reason(field)
|
|
17
|
-
report(findings, "#{type.graphql_name}.#{field.graphql_name}", reason, field.resolver ? field : nil) if reason
|
|
16
|
+
reason = Integration.observed_reason(field)
|
|
17
|
+
report(findings, "#{type.graphql_name}.#{field.graphql_name}", reason, field.resolver ? field : nil, at: field) if reason
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
|
-
custom_introspection(schema).each { |field| report(findings, "#{field.owner.graphql_name}.#{field.graphql_name}", field.armory_observe) }
|
|
20
|
+
custom_introspection(schema).each { |field| report(findings, "#{field.owner.graphql_name}.#{field.graphql_name}", field.armory_observe, at: field) }
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def self.report(findings, path, reason, resolver_field = nil)
|
|
23
|
+
def self.report(findings, path, reason, resolver_field = nil, at: nil)
|
|
24
24
|
effect = if resolver_field
|
|
25
25
|
"raises on every query, because #{resolver_field.graphql_name} has a resolver or a mutation, which can write (#{reason}): remove observe:"
|
|
26
26
|
else
|
|
27
27
|
"serves what this rule would refuse (#{reason}): remove it to enforce the rule"
|
|
28
28
|
end
|
|
29
|
-
findings.problem(:observed, path, "observe: #{effect}")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Its own observe:, or `authorize: true` on an owner whose rule is observed: if that owner is only a parent, no
|
|
33
|
-
# type reports its rule.
|
|
34
|
-
def self.observed_reason(field)
|
|
35
|
-
return field.armory_observe if field.respond_to?(:armory_observe) && field.armory_observe
|
|
36
|
-
return unless field.respond_to?(:armory_declared) && field.armory_declared == true
|
|
37
|
-
|
|
38
|
-
rule = field.owner.armory_rule if field.owner.respond_to?(:armory_rule)
|
|
39
|
-
rule.observe if rule&.observed?
|
|
29
|
+
findings.problem(:observed, path, "observe: #{effect}", at: at)
|
|
40
30
|
end
|
|
41
31
|
|
|
42
32
|
def self.unobservable(type)
|
|
43
33
|
type.all_field_definitions.find(&:resolver)
|
|
44
34
|
end
|
|
45
|
-
private_class_method :
|
|
35
|
+
private_class_method :unobservable
|
|
46
36
|
|
|
47
37
|
# Definitions holds what these fields return, not the classes that own them.
|
|
48
38
|
def self.custom_introspection(schema)
|
|
@@ -66,12 +66,12 @@ module GraphQL
|
|
|
66
66
|
def note_override(path, member, falls_back)
|
|
67
67
|
reason = member.armory_override_reason if member.respond_to?(:armory_override_reason)
|
|
68
68
|
if falls_back && reason
|
|
69
|
-
@findings.bypass(path, reason)
|
|
69
|
+
@findings.bypass(path, reason, at: member)
|
|
70
70
|
elsif falls_back
|
|
71
71
|
@findings.problem(:ignored_rule, path, "is defined more than once: hidden from a user, it falls back to the other definition, and its own rule, arguments, type and extensions do not apply. " \
|
|
72
|
-
"Remove one or declare override_reason:; for a definition on an ancestor, Schema::Visibility with dynamic: true and no profiles also stops the fallback")
|
|
72
|
+
"Remove one or declare override_reason:; for a definition on an ancestor, Schema::Visibility with dynamic: true and no profiles also stops the fallback", at: member)
|
|
73
73
|
elsif reason
|
|
74
|
-
@findings.problem(:ignored_rule, path, "declares override_reason: but nothing falls back from it: remove it")
|
|
74
|
+
@findings.problem(:ignored_rule, path, "declares override_reason: but nothing falls back from it: remove it", at: member)
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
end
|
|
@@ -71,7 +71,7 @@ module GraphQL
|
|
|
71
71
|
readers.each { |reader| note_class_check(reader, :reauthorize_scoped_objects) }
|
|
72
72
|
|
|
73
73
|
setter = reauthorization_setter(type)
|
|
74
|
-
@found[[setter, :reauthorize_scoped_objects]] = "#{setter.name || setter.inspect}.reauthorize_scoped_objects" if setter&.instance_variable_get(:@reauthorize_scoped_objects) == false
|
|
74
|
+
@found[[setter, :reauthorize_scoped_objects]] = ["#{setter.name || setter.inspect}.reauthorize_scoped_objects", setter] if setter&.instance_variable_get(:@reauthorize_scoped_objects) == false
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
# The nearest that set the value, read from the classes so no method of the app runs: graphql-ruby's reader follows
|
|
@@ -105,23 +105,23 @@ module GraphQL
|
|
|
105
105
|
def note_own_check(klass, method, name, separator)
|
|
106
106
|
while method
|
|
107
107
|
holder = LibraryMethods.holder_of(klass, method)
|
|
108
|
-
@found[[holder, name]] = "#{holder.name || holder.inspect}#{separator}#{name}" unless LibraryMethods.library_method?(method, holder, GRAPHQL_RUBY_PATH, ARMORY_PATH)
|
|
108
|
+
@found[[holder, name]] = ["#{holder.name || holder.inspect}#{separator}#{name}", method] unless LibraryMethods.library_method?(method, holder, GRAPHQL_RUBY_PATH, ARMORY_PATH)
|
|
109
109
|
method = method.super_method
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
def report(declared)
|
|
114
|
-
@found.each do |(holder, name), path|
|
|
114
|
+
@found.each do |(holder, name), (path, method)|
|
|
115
115
|
reason = declared.fetch(holder, {})[name]
|
|
116
|
-
next @findings.bypass(path, reason) if reason
|
|
116
|
+
next @findings.bypass(path, reason, at: method) if reason
|
|
117
117
|
|
|
118
|
-
@findings.problem(:own_check, path, "#{risk(name)}. Remove it, or declare it in own_checks: with a reason")
|
|
118
|
+
@findings.problem(:own_check, path, "#{risk(name)}. Remove it, or declare it in own_checks: with a reason", at: method)
|
|
119
119
|
end
|
|
120
120
|
declared.each do |holder, methods|
|
|
121
121
|
methods.each_key do |name|
|
|
122
122
|
next if @found.key?([holder, name])
|
|
123
123
|
|
|
124
|
-
@findings.problem(:own_check, "#{holder.name || holder.inspect} #{name}", "named in own_checks: but no check of the schema is defined there: remove it from the option")
|
|
124
|
+
@findings.problem(:own_check, "#{holder.name || holder.inspect} #{name}", "named in own_checks: but no check of the schema is defined there: remove it from the option", at: holder)
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
end
|
|
@@ -67,7 +67,7 @@ module GraphQL
|
|
|
67
67
|
|
|
68
68
|
@findings.problem(:payload_outside_mutation, "#{type.graphql_name}.#{field.original_name}",
|
|
69
69
|
"returns #{reused.map(&:graphql_name).sort.join(", ")}, a mutation's payload, whose fields are covered by that mutation's rule: " \
|
|
70
|
-
"here no such rule runs, so they are served with no check. Return a type of its own, or, for a public child of a mutation with a rule, give the parent's field `authorize: :none, reason: \"...\"`")
|
|
70
|
+
"here no such rule runs, so they are served with no check. Return a type of its own, or, for a public child of a mutation with a rule, give the parent's field `authorize: :none, reason: \"...\"`", at: field)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
# A shadowed definition may name a type that never resolved; it cannot serve anything.
|
|
@@ -13,7 +13,7 @@ module GraphQL
|
|
|
13
13
|
"serves it, unless its own code refuses. Include Base in the resolver and declare `authorize`, or use a field class that includes Base and declare `authorize: :none, reason: \"...\"`"
|
|
14
14
|
|
|
15
15
|
def self.report(findings, path, field)
|
|
16
|
-
findings.problem(:unprotected, path, field.respond_to?(:armory_declared) ? PROBLEM : PLAIN_FIELD_PROBLEM)
|
|
16
|
+
findings.problem(:unprotected, path, field.respond_to?(:armory_declared) ? PROBLEM : PLAIN_FIELD_PROBLEM, at: field)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def self.covering?(rule)
|
|
@@ -6,13 +6,20 @@ module GraphQL
|
|
|
6
6
|
class Audit
|
|
7
7
|
# What an audit found: what is not covered, and every bypass someone declared.
|
|
8
8
|
class Report
|
|
9
|
-
|
|
9
|
+
# `location` is "path:line" where the app wrote what the problem is about (see Location), or nil. It is not part of
|
|
10
|
+
# what a problem is: `to_s` and the baseline leave it out, so moving code changes neither.
|
|
11
|
+
Problem = Struct.new(:kind, :path, :message, :location) do
|
|
10
12
|
def to_s
|
|
11
13
|
"#{path} (#{kind}): #{message}"
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
Bypass = Struct.new(:path, :reason)
|
|
17
|
+
Bypass = Struct.new(:path, :reason, :location)
|
|
18
|
+
|
|
19
|
+
# The line the report prints for a problem or a bypass: its text, then where it is.
|
|
20
|
+
def self.line(text, location)
|
|
21
|
+
location ? "#{text} (at #{location})" : text
|
|
22
|
+
end
|
|
16
23
|
|
|
17
24
|
attr_reader :problems, :bypasses
|
|
18
25
|
|
|
@@ -41,14 +48,14 @@ module GraphQL
|
|
|
41
48
|
def problems_text
|
|
42
49
|
return "No problems." if ok?
|
|
43
50
|
|
|
44
|
-
["#{problems.size} #{problems.size == 1 ? 'problem' : 'problems'}:", *problems.map { |problem| " #{problem}" }].join("\n")
|
|
51
|
+
["#{problems.size} #{problems.size == 1 ? 'problem' : 'problems'}:", *problems.map { |problem| " #{Report.line(problem.to_s, problem.location)}" }].join("\n")
|
|
45
52
|
end
|
|
46
53
|
|
|
47
54
|
def bypasses_text
|
|
48
55
|
return if bypasses.empty?
|
|
49
56
|
|
|
50
57
|
["#{bypasses.size} declared #{bypasses.size == 1 ? 'bypass' : 'bypasses'}:",
|
|
51
|
-
*bypasses.map { |bypass| " #{bypass.path}: #{bypass.reason}" }].join("\n")
|
|
58
|
+
*bypasses.map { |bypass| " #{Report.line("#{bypass.path}: #{bypass.reason}", bypass.location)}" }].join("\n")
|
|
52
59
|
end
|
|
53
60
|
end
|
|
54
61
|
end
|