kiosk-redteam 0.6.1 → 0.6.28

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c56649c77866230a9cf50c19996d61c4dc830e8482119f6a8bc572e1089ecf1
4
- data.tar.gz: ace8f750f4f8f5d28b995b2e52f0249f5a57b18eed50a71a61e46e2059746afb
3
+ metadata.gz: 8f1c350b529c0651217fc29e20719585273ce68bf9235287f1a587917c46e9b3
4
+ data.tar.gz: 5d0d5f27ea81574696402ddf454590c71599c37fd8f753e54cb0c68012d90d63
5
5
  SHA512:
6
- metadata.gz: 7c01e1cf090a73e15c30dfa2a47646d3681839c65d1e232ee2e473aee737c4876a91a8e5c6b8428bbc076588f30997aaee38a21c5cf2c7a349bbe08f7584fc90
7
- data.tar.gz: e4b0bdba33d9b7f322bdf0aae993bafbfa0a51b2bab7e025e237dab437d4aef133a8690d446ff236981e393d2e187448d8162f903407c9a8f8915da4de073c2a
6
+ metadata.gz: e09f81b23c9c9e4223b8172f526e37063f71d868b8da20af516f1b3865d9c3ee2ca2f9d70634cd232afb2da1020539276aed48d00887617d93342fd567a0f367
7
+ data.tar.gz: c7aa09739022cafbf8a5f4c163213a3c25f0f39fca4889ffaa2642eaee931905be7af76177ea27f8aff8c5b01d3be267b164c3c2562bdb5ae281ed57e25e6441
data/CHANGELOG.md CHANGED
@@ -12,6 +12,118 @@ already written is edited.
12
12
 
13
13
  ## [Unreleased]
14
14
 
15
+ ## [0.6.28] — 2026-10-26
16
+
17
+ - 2026-10-26: Version 0.6.28, the tree cut that matches skill 0.6.28.
18
+
19
+ ## [0.6.27] — 2026-10-26
20
+
21
+ - 2026-10-26: Version 0.6.27, the tree cut that matches skill 0.6.27.
22
+ ## [0.6.26] — 2026-10-26
23
+
24
+ - 2026-10-26: Version 0.6.26, the tree cut that matches skill 0.6.26.
25
+ ## [0.6.25] — 2026-10-26
26
+
27
+ - 2026-10-26: Version 0.6.25, the tree cut that matches skill 0.6.25.
28
+ - 2026-10-26: The README and gemspec say the harness loads no Rails but installs it, and that the scenarios call the default mount path `/kiosk`.
29
+
30
+ ## [0.6.24] — 2026-10-26
31
+
32
+ - 2026-10-26: Version 0.6.24, the tree cut that matches skill 0.6.24.
33
+
34
+ ## [0.6.23] — 2026-10-26
35
+
36
+ - 2026-10-26: Version 0.6.23, the tree cut that matches skill 0.6.23.
37
+
38
+ ## [0.6.22] — 2026-10-26
39
+
40
+ - 2026-10-26: Version 0.6.22, the tree cut that matches skill 0.6.22.
41
+
42
+ ## [0.6.21] — 2026-10-26
43
+
44
+ - 2026-10-26: Version 0.6.21, the tree cut that matches skill 0.6.21.
45
+ - 2026-10-26: `underpriced_checkout` lowers each priced line of a signed checkout and its total, and keeps the other members.
46
+
47
+ ## [0.6.20] — 2026-10-26
48
+
49
+ - 2026-10-26: Version 0.6.20, the tree cut that matches skill 0.6.20.
50
+
51
+ ## [0.6.19] — 2026-10-26
52
+
53
+ - 2026-10-26: Version 0.6.19, the tree cut that matches skill 0.6.19.
54
+
55
+ ## [0.6.18] — 2026-10-25
56
+
57
+ - 2026-10-25: Version 0.6.18, the tree cut that matches skill 0.6.18.
58
+ - 2026-10-25: The `pow_required` note and the call-toll setup failure say that the harness solves the toll and name the tolled retry.
59
+
60
+ ## [0.6.17] — 2026-10-25
61
+
62
+ - 2026-10-25: Version 0.6.17, the tree cut that matches skill 0.6.17.
63
+
64
+ ## [0.6.16] — 2026-10-25
65
+
66
+ - 2026-10-25: Version 0.6.16, the tree cut that matches skill 0.6.16.
67
+
68
+ ## [0.6.15] — 2026-10-25
69
+
70
+ - 2026-10-25: Version 0.6.15, the tree cut that matches skill 0.6.15.
71
+
72
+ ## [0.6.14] — 2026-10-25
73
+
74
+ - 2026-10-25: Version 0.6.14, the tree cut that matches skill 0.6.14.
75
+
76
+ ## [0.6.13] — 2026-10-25
77
+
78
+ - 2026-10-25: Version 0.6.13, the tree cut that matches skill 0.6.13.
79
+
80
+ ## [0.6.12] — 2026-10-24
81
+
82
+ - 2026-10-24: Version 0.6.12, the tree cut that matches skill 0.6.12.
83
+
84
+ - 2026-10-24: `CallToll` checks that call N of an account pays a proof after known bypasses: a new token or key, a second assistant, concurrent or refused calls, a replayed proof.
85
+
86
+ ## [0.6.11] — 2026-10-24
87
+
88
+ - 2026-10-24: Version 0.6.11, the tree cut that matches skill 0.6.11.
89
+
90
+ ## [0.6.10] — 2026-10-23
91
+
92
+ - 2026-10-23: Version 0.6.10, the tree cut that matches skill 0.6.10.
93
+
94
+ ## [0.6.9] — 2026-10-23
95
+
96
+ - 2026-10-23: Version 0.6.9, the tree cut that matches skill 0.6.9.
97
+
98
+ ## [0.6.8] — 2026-10-22
99
+
100
+ - 2026-10-22: Version 0.6.8, the tree cut that matches skill 0.6.8.
101
+
102
+ ## [0.6.7] — 2026-10-22
103
+
104
+ - 2026-10-22: Version 0.6.7, the tree cut that matches skill 0.6.7.
105
+
106
+ ## [0.6.6] — 2026-10-22
107
+
108
+ - 2026-10-22: Version 0.6.6, the tree cut that matches skill 0.6.6.
109
+
110
+ ## [0.6.5] — 2026-10-22
111
+
112
+ - 2026-10-22: Version 0.6.5, the tree cut that matches skill 0.6.5.
113
+
114
+ ## [0.6.4] — 2026-10-22
115
+
116
+ - 2026-10-22: Version 0.6.4, the tree cut that matches skill 0.6.4.
117
+ - 2026-10-22: `DeviceGrantRoleSelfSelection` probes `role` only: an operator ignores a `scope`. The stylish suite opens a customer's ceremony with `scope=owner` and expects `customer`.
118
+
119
+ ## [0.6.3] — 2026-10-22
120
+
121
+ - 2026-10-22: Version 0.6.3, the tree cut that matches skill 0.6.3.
122
+
123
+ ## [0.6.2] — 2026-10-22
124
+
125
+ - 2026-10-22: Version 0.6.2, the tree cut that matches skill 0.6.2.
126
+
15
127
  ## [0.6.1] — 2026-10-22
16
128
 
17
129
  - 2026-10-22: Version 0.6.1, the tree cut that matches skill 0.6.1.
data/README.md CHANGED
@@ -1,22 +1,25 @@
1
1
  # kiosk-redteam
2
2
 
3
- Adversarial regression harness for [Kiosk](https://kiosk.tech) providers — it
3
+ Adversarial regression harness for [Kiosk](https://kiosk.tech) operators — it
4
4
  drives hostile HTTP scenarios against a running Kiosk origin and asserts each
5
5
  attack is correctly blocked.
6
6
 
7
7
  ## What it does
8
8
 
9
- A scenario registers its own principals over the wire, stages whatever state the
9
+ A scenario registers its own assistants over HTTP, stages whatever state the
10
10
  attack needs, then performs the attack and returns a `Verdict`. A scenario that
11
11
  finds a real breach fails loudly: `Battery#report!` answers 1 and the
12
- caller exits non-zero. Fix the provider, keep the scenario as a permanent
12
+ caller exits non-zero. Fix the origin, keep the scenario as a permanent
13
13
  regression.
14
14
 
15
- **No Rails.** The harness speaks the wire and nothing else, so
16
- it can be pointed at any Kiosk origin — your own app in CI, or a third party's
17
- deployment. Everything provider-specific (which verbs exist, how to create an
18
- owned row, which checkout pays for it) lives in a `Profile` you supply; no provider
19
- name is hard-coded in the gem.
15
+ **Rails is installed, not loaded.** `require "kiosk/redteam"` loads no Rails:
16
+ the harness speaks the protocol and nothing else. The gem depends on
17
+ kiosk-test-support, which depends on kiosk-server, so installing it installs
18
+ Rails. It can be pointed at any Kiosk origin that mounts the engine at the
19
+ default path `/kiosk` — your own app in CI, or a third party's deployment: the
20
+ scenarios call the `/kiosk/...` paths. Everything that differs per operator
21
+ (which operations exist, how to create an owned row, which checkout pays for
22
+ it) lives in a `Profile` you supply; no operator name is hard-coded in the gem.
20
23
 
21
24
  **`http` or `https` is decided by the base URL you pass and by nothing else.**
22
25
  There is no TLS flag and no environment variable: the scenarios attack through
@@ -25,14 +28,14 @@ There is no TLS flag and no environment variable: the scenarios attack through
25
28
  "http://127.0.0.1:3000"` is a local app and `base_url:
26
29
  "https://example.com"` is that deployment, with the same code and the same
27
30
  profile. Point it at a deployment you do not own and remember what a battery
28
- is: scenarios REGISTER principals and STAGE the state their attack needs, so
31
+ is: scenarios REGISTER assistants and STAGE the state their attack needs, so
29
32
  run it against something you are willing to have written to.
30
33
 
31
34
  ### Blocked, breached, untested, skipped — the four states
32
35
 
33
36
  | Verdict | Means | Printed |
34
37
  |---|---|---|
35
- | **blocked** | the provider refused this attack | `BLOCKED ✓ <name> (HTTP <status>)` |
38
+ | **blocked** | the origin refused this attack | `BLOCKED ✓ <name> (HTTP <status>)` |
36
39
  | **breach** | the attack was NOT refused — a real finding | `BREACH ✗ <name> — <detail>` |
37
40
  | **untested** | a setup step or the environment failed, so the attack never reached its gate | `UNTESTED ! <name> — <detail>` |
38
41
  | **skipped** | the profile lacks the surface this scenario needs | `SKIP — <name> (<reason>)` |
@@ -58,22 +61,20 @@ default.
58
61
 
59
62
  ## Install
60
63
 
61
- > **Not on RubyGems yet** — so every `gem` line below carries `github: "kiosk-hq/kiosk"`, which is what makes it copy-pasteable today. Publication status and the canonical install are stated once, in the monorepo README's [Install](https://github.com/kiosk-hq/kiosk#install) section.
62
-
63
64
  ```ruby
64
65
  # Gemfile — a test/CI dependency, not a runtime one
65
- gem "kiosk-redteam", github: "kiosk-hq/kiosk", group: :development
66
+ gem "kiosk-redteam", group: :development
66
67
  ```
67
68
 
68
69
  The registration toll is real Equihash: the assistant client solves the server's
69
70
  402 challenges with the reference solver that ships inside `kiosk-pow-equihash`.
70
71
  The bundle that runs the battery holds that gem, as the origin's bundle does,
71
72
  and the machine needs **`python3` with `numpy`** on `PATH`. Point a battery at an
72
- origin whose PoW is off and nothing is solved and nothing is needed.
73
+ origin whose toll is off and nothing is solved and nothing is needed.
73
74
 
74
75
  ## Usage
75
76
 
76
- Describe the provider once, hand the runner a list of scenarios, exit on the
77
+ Describe the origin once, hand the runner a list of scenarios, exit on the
77
78
  verdict:
78
79
 
79
80
  ```ruby
@@ -92,7 +93,7 @@ profile = Kiosk::Redteam::Profile.new(
92
93
  # response object (they often differ).
93
94
  row_id_key: "id",
94
95
  result_id_key: "order_id",
95
- # Create a row owned by `principal`; must return a Hash with at least :id.
96
+ # Create a row owned by the assistant's customer; must return a Hash with at least :id.
96
97
  create_owned: ->(client, principal) {
97
98
  resp = client.run(principal, name: "create_order", items: [{ sku: "SKU-1", qty: 1 }])
98
99
  raise "create_order failed (#{resp.status}): #{resp.body.inspect}" unless resp.status == 200
@@ -119,7 +120,7 @@ exit battery.report!
119
120
 
120
121
  Every field of `Profile` is optional; a scenario whose field is `nil` skips
121
122
  itself rather than inventing a surface. That is what lets one battery cover a
122
- commerce provider and a non-commerce one. `suites/` holds one battery per
123
+ commerce operator and a non-commerce one. `suites/` holds one battery per
123
124
  operator demo in this repo, built on this API — read one of those for a worked,
124
125
  running profile against a real origin. Each runs in its demo's directory, with
125
126
  that demo's bundle. A demo that takes payments charges a stripe-mock: start the
@@ -137,19 +138,20 @@ scenarios share:
137
138
 
138
139
  | Scenario | Asserts |
139
140
  |---|---|
140
- | `CrossTenantRead` | B's per-user query must not return rows owned by A |
141
+ | `CrossTenantRead` | B's query of its own rows must not return rows owned by A |
141
142
  | `ForgedUserId` | a caller-supplied `user_id` never decides ownership |
142
143
  | `PrivilegeSelfSelection` | a role in the registration body does not reach the client's token — the role is server-pinned |
143
- | `DeviceGrantRoleSelfSelection` | the claim ceremony's opening request, signed by a registered client, refuses `role`/`scope`, at a DECLARED value as well as an invented one |
144
+ | `DeviceGrantRoleSelfSelection` | the claim ceremony's opening request, signed by a registered client, refuses `role`, at a DECLARED value as well as an invented one |
144
145
  | `SpentResourceReuse` | a consumed resource cannot be re-activated |
145
146
  | `PayForOtherUseSelf` | B paying for A's resource does not let B use it |
146
147
  | `TokenTampering` | a JWT with a flipped claim and the original signature is 401 |
147
148
  | `StolenToken` | a real access token without its key is 401: as a bearer token, and with a DPoP proof that another key signs |
148
- | `RegistrationWithoutPow` | a missing or bad proof is rejected when the origin charges a toll |
149
+ | `RegistrationWithoutPow` | a missing or bad proof is rejected when the origin asks a toll |
149
150
  | `MandatePrincipalSwap` | B paying, with its own key, the checkout the operator signed for A is rejected |
150
151
  | `MandateReplay` | A's signed mandates re-submitted under B's token are rejected |
151
152
  | `UnpaidGatedAction` | the gated action without a prior settled payment is denied |
152
153
  | `WrongCurrencyPayment` | a payment mandate in a currency other than its checkout's is refused before any capture |
154
+ | `CallToll` | call N of an account meets `402 pow_required`, after a new access token, a rotated key, a second assistant that a person links to the same account, calls sent at the same time, a refused call, and a proof sent again; a registration with no proof is refused. It needs `tolled_calls_per_proof`, `tolled_query` and `person` |
153
155
  | `MissingKyc` | the gated action after payment but without an attestation is denied |
154
156
  | `ExpiredKyc` | an attestation whose `exp` has passed is rejected |
155
157
  | `ForgedKyc` | an attestation with a wrong issuer or a bad signature is rejected |
@@ -159,20 +161,20 @@ Beside them the gem ships `Profile`, `Scenario`, `Verdict`, `Runner`,
159
161
  own vocabulary, discounting needles the attack itself supplied. A scenario
160
162
  receives a `Kiosk::TestHelpers::Assistant` — register, token, query, run, pay
161
163
  with closed AP2 mandates, kyc, and the device-authorization request — and its
162
- `events(principal)` is the assistant's side of `<endpoint>/events`.
164
+ `events(principal)`, for one registered assistant, is the assistant's side of `/kiosk/events`.
163
165
 
164
166
  ## Your own beats, in the same battery
165
167
 
166
- No provider's battery is all library. The scenarios above are the attacks every
168
+ No operator's battery is all library. The scenarios above are the attacks every
167
169
  Kiosk origin has to survive; the interesting half is always the attacks on
168
- *your* verbs — your enum filters, your price arithmetic, your ownership joins.
170
+ *your* operations — your enum filters, your price arithmetic, your ownership joins.
169
171
  Two classes carry that half, and they are the reason a hand-written beat and a
170
172
  library scenario can sit in one run.
171
173
 
172
- `Kiosk::TestHelpers::Wire` is the raw wire: an arbitrary method at an arbitrary path with arbitrary
173
- headers, which is what an attack on the REQUEST rather than on the principal
174
- needs — a forged or absent `Authorization`, a token without its key, a verb nobody registered, the wrong
175
- method at a real verb's path, an assertion on `Allow:` rather than on a body. A
174
+ `Kiosk::TestHelpers::Wire` is the raw transport: an arbitrary method at an arbitrary path with arbitrary
175
+ headers, which is what an attack on the REQUEST rather than on the assistant
176
+ needs — a forged or absent `Authorization`, a token without its key, an
177
+ operation nobody declared, the wrong method at a real operation's path, an assertion on `Allow:` rather than on a body. A
176
178
  body that is not JSON reads as `{}` and a connection error reads as status `0`,
177
179
  so a hostile answer is asserted on instead of crashing the run; the bytes stay
178
180
  available on `raw_body` for a `LeakScan`.
@@ -185,7 +187,7 @@ wire = Kiosk::TestHelpers::Wire.new(base_url: SERVER)
185
187
  client = Kiosk::TestHelpers::Assistant.new(base_url: SERVER)
186
188
  battery = Kiosk::Redteam::Battery.new
187
189
 
188
- # your own beat, against your own verb
190
+ # your own beat, against your own operation
189
191
  status, rows = wire.get_json("/kiosk/my_listings", {}, wire.dpop(bob.token, bob.key))
190
192
  battery.record("CrossTenantRead", status == 200 && !ids(rows).include?(alice_row),
191
193
  "Bob's rows #{ids(rows).inspect} exclude Alice's #{alice_row}")
@@ -209,7 +211,7 @@ scenario, and that must not pass as a clean run.
209
211
 
210
212
  Pass `on_skip: :breach` for a scenario whose surface this origin definitely
211
213
  has: there, a skip is a defect of the harness rather than a property of the
212
- provider, and a quiet skip is how a beat that stopped running goes unnoticed.
214
+ origin, and a quiet skip is how a beat that stopped running goes unnoticed.
213
215
 
214
216
  Pass `untested: true` to `record` when a setup step of your beat failed. The
215
217
  attack did not reach its gate, so the beat is UNTESTED and the run fails with
@@ -221,23 +223,22 @@ Subclass `Scenario`, name what you are attacking, and return a `Verdict` that
221
223
  says which gate you demanded:
222
224
 
223
225
  ```ruby
224
- class UnknownVerbIs404 < Kiosk::Redteam::Scenario
226
+ class UnknownOperationIs404 < Kiosk::Redteam::Scenario
225
227
  def initialize
226
- super(name: "UnknownVerbIs404")
228
+ super(name: "UnknownOperationIs404")
227
229
  end
228
230
 
229
231
  def call(client, profile)
230
232
  principal = client.register!
231
- verdict_from(client.query(principal, name: "no_such_verb"), expect: 404)
233
+ verdict_from(client.query(principal, name: "no_such_operation"), expect: 404)
232
234
  end
233
235
  end
234
236
  ```
235
237
 
236
238
  ## Status
237
239
 
238
- Pre-v1.0 alpha. The `Scenario` / `Profile` / `Verdict` surface is stable across
239
- pre-v1.0 minor bumps; the scenario library grows as gates are added
240
- (`CHANGELOG.md` tracks).
240
+ Pre-v1.0 alpha: the `Scenario` / `Profile` / `Verdict` surface may change
241
+ between releases (`CHANGELOG.md` tracks each change).
241
242
 
242
243
  ## License
243
244
 
@@ -22,7 +22,7 @@ module Kiosk
22
22
 
23
23
  module_function
24
24
 
25
- # +supplied+ is what the probe put on the wire; nil discounts nothing.
25
+ # +supplied+ is what the probe put in the protocol; nil discounts nothing.
26
26
  def scan(body, needles, supplied: nil)
27
27
  raw = body.is_a?(String) ? body : JSON.generate(body)
28
28
  echoed, leaked = sightings(raw, needles, echo_spans(raw, supplied)).partition(&:last)
@@ -22,6 +22,9 @@ module Kiosk
22
22
  # kyc_valid (user_id) -> a valid attestation JWS
23
23
  # kyc_expired (user_id) -> an expired attestation JWS
24
24
  # kyc_forged (user_id) -> an attestation with a wrong issuer or signature
25
+ # tolled_calls_per_proof the call toll's interval for a new account: call N is tolled (CallToll)
26
+ # tolled_query a query any principal may call with no arguments (CallToll)
27
+ # person () -> a signed-in Kiosk::TestHelpers::Person who links assistants (CallToll)
25
28
  class Profile
26
29
  DEFAULTS = {
27
30
  pow_difficulty: 0,
@@ -40,7 +43,10 @@ module Kiosk
40
43
  pay_for: nil,
41
44
  kyc_valid: nil,
42
45
  kyc_expired: nil,
43
- kyc_forged: nil
46
+ kyc_forged: nil,
47
+ tolled_calls_per_proof: nil,
48
+ tolled_query: nil,
49
+ person: nil
44
50
  }.freeze
45
51
 
46
52
  attr_reader(*DEFAULTS.keys)
@@ -0,0 +1,189 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Kiosk
6
+ module Redteam
7
+ module Scenarios
8
+ # The calls CallToll makes carry no proof, so that each answer shows whether the toll was asked.
9
+ module TollCalls
10
+ # A setup step did not answer as the probe needs, so the probe did not test the toll.
11
+ class SetupFailed < StandardError; end
12
+
13
+ private
14
+
15
+ # A new account, after N-1 calls that pass.
16
+ def primed
17
+ @client.register!.tap { prime(it, @every - 1) }
18
+ end
19
+
20
+ def prime(principal, calls)
21
+ calls.times do |index|
22
+ answer = ask(principal)
23
+ raise SetupFailed, "call #{index + 1} answered HTTP #{answer.status} #{answer.body.inspect}" unless ok?(answer)
24
+ end
25
+ end
26
+
27
+ # The number of the call that met the toll; the toll is solved, so the count is 0 again.
28
+ def calls_to_toll(principal)
29
+ (1..(@every * 20)).each do |number|
30
+ return number.tap { paid_proof(principal, number:) } if tolled?(ask(principal))
31
+ end
32
+ raise SetupFailed, "no call met the toll in #{@every * 20} calls"
33
+ end
34
+
35
+ # Solves the toll of the call that met it and answers the proof that cleared it.
36
+ def paid_proof(principal, number: @every)
37
+ tolled = ask(principal)
38
+ raise SetupFailed, "call #{number} answered HTTP #{tolled.status}, not the toll" unless tolled?(tolled)
39
+
40
+ proof = JSON.generate(TestHelpers::Wire.solve(tolled.body.fetch('challenges')))
41
+ paid = ask(principal, proof:)
42
+ raise SetupFailed, "the tolled retry answered HTTP #{paid.status} #{paid.body.inspect}" unless ok?(paid)
43
+
44
+ proof
45
+ end
46
+
47
+ # `calls` calls of `principal`, each from its own thread, all sent before any answer is read.
48
+ def at_once(principal, calls) = Array.new(calls) { Thread.new { ask(principal) } }.map(&:value)
49
+
50
+ # nil when the call meets the toll; otherwise what it answered.
51
+ def not_tolled(principal, what)
52
+ answer = ask(principal)
53
+ return nil if tolled?(answer)
54
+
55
+ "#{what} answered HTTP #{answer.status} #{answer.body.inspect}, not 402 pow_required"
56
+ end
57
+
58
+ def ask(principal, proof: nil, **params)
59
+ headers = proof ? { 'Kiosk-PoW' => proof } : {}
60
+ @client.query(principal, name: @profile.tolled_query, pay_tolls: false, headers:, **params)
61
+ end
62
+
63
+ def ok?(answer) = answer.status.between?(200, 299)
64
+
65
+ def tolled?(answer) = answer.status == 402 && error_code(answer) == 'pow_required'
66
+
67
+ def error_code(answer) = Kiosk::Redteam.error_code(answer)
68
+ end
69
+
70
+ # The call toll: an account solves a proof of work on every Nth tolled call.
71
+ # The control brings a new account to N-1 calls and meets `402
72
+ # pow_required` on call N. Each probe brings an account to N-1 calls,
73
+ # tries a known way past the toll, and must still meet the toll.
74
+ class CallToll < Scenario
75
+ include TollCalls
76
+
77
+ PROBES = {
78
+ 'control' => :control,
79
+ 'a new access token' => :new_token,
80
+ 'a rotated key' => :rotated_key,
81
+ 'a second assistant on the same account' => :second_assistant,
82
+ 'a new registration' => :new_registration,
83
+ 'calls sent at the same time' => :concurrent_calls,
84
+ 'a refused call' => :refused_call,
85
+ 'a replayed proof' => :replayed_proof
86
+ }.freeze
87
+
88
+ # Calls past N that the concurrent probe sends with the first N.
89
+ EXTRA_CONCURRENT_CALLS = 5
90
+
91
+ def initialize
92
+ super(name: 'CallToll')
93
+ end
94
+
95
+ def call(client, profile)
96
+ skipped = skip_unless(profile, [[:tolled_calls_per_proof, 'the profile declares no call toll'],
97
+ [:tolled_query, 'the profile names no tolled query'],
98
+ [:person, 'the profile names no person to link two assistants']])
99
+ return skipped if skipped
100
+
101
+ @client = client
102
+ @profile = profile
103
+ @every = profile.tolled_calls_per_proof
104
+ probe_all
105
+ end
106
+
107
+ private
108
+
109
+ def probe_all
110
+ failures = []
111
+ unevaluated = []
112
+ PROBES.each do |label, probe|
113
+ detail = send(probe)
114
+ failures << "#{label}: #{detail}" if detail
115
+ rescue SetupFailed => e
116
+ unevaluated << "#{label}: #{e.message}"
117
+ end
118
+ verdict = probes_verdict(402, failures, unevaluated)
119
+ verdict.blocked ? blocked_verdict(402, "call #{@every} met 402 pow_required after #{PROBES.keys.join(', ')}") : verdict
120
+ end
121
+
122
+ # Call N of a new account meets the toll.
123
+ def control
124
+ not_tolled(primed, "call #{@every} of a new account")
125
+ end
126
+
127
+ def new_token
128
+ not_tolled(@client.signed_in(primed), "call #{@every} with a new access token")
129
+ end
130
+
131
+ def rotated_key
132
+ rotated = @client.rotate(primed)
133
+ raise SetupFailed, "the rotation answered HTTP #{rotated.status}" unless rotated.is_a?(TestHelpers::Assistant::Principal)
134
+
135
+ not_tolled(rotated, "call #{@every} with a rotated key")
136
+ end
137
+
138
+ # Two assistants of one person share the count: the second one, linked
139
+ # after the first made N-1 calls, meets the toll on its first call.
140
+ def second_assistant
141
+ person = @profile.person.call
142
+ first = person.links_a_newcomer.principal
143
+ calls_to_toll(first) # sets the count to 0, from whatever the person's account held
144
+ every = calls_to_toll(first) # the interval of this account, which its spend sets
145
+ prime(first, every - 1)
146
+ not_tolled(person.links_a_newcomer.principal, "the first call of a second assistant, after #{every - 1} calls")
147
+ end
148
+
149
+ # A new account costs the registration toll.
150
+ def new_registration
151
+ answer = @client.register_raw(pow: :skip)
152
+ return nil if tolled?(answer)
153
+
154
+ "a registration with no proof answered HTTP #{answer.status} #{answer.body.inspect}"
155
+ end
156
+
157
+ # N + 5 calls of a new account at the same time: exactly N-1 pass.
158
+ def concurrent_calls
159
+ answers = at_once(@client.register!, @every + EXTRA_CONCURRENT_CALLS)
160
+ passed, refused = answers.partition { ok?(it) }
161
+ return nil if passed.size == @every - 1 && refused.all? { tolled?(it) }
162
+
163
+ "#{passed.size} of #{answers.size} calls sent at the same time passed, want #{@every - 1}; " \
164
+ "statuses #{answers.map(&:status).tally}"
165
+ end
166
+
167
+ # A call refused before the toll does not set the count back.
168
+ def refused_call
169
+ principal = primed
170
+ refused = ask(principal, redteam_unknown_argument: 'x')
171
+ return "a call with an unknown argument answered HTTP #{refused.status}" if ok?(refused)
172
+
173
+ not_tolled(principal, "call #{@every}, after a refused call")
174
+ end
175
+
176
+ # A proof clears the toll of one call: sent again on a later tolled call, it is refused.
177
+ def replayed_proof
178
+ principal = primed
179
+ proof = paid_proof(principal)
180
+ prime(principal, @every - 1)
181
+ replay = ask(principal, proof:)
182
+ return nil unless ok?(replay)
183
+
184
+ "call #{@every} with a proof already spent answered HTTP #{replay.status}"
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
@@ -6,10 +6,11 @@ module Kiosk
6
6
  module Redteam
7
7
  module Scenarios
8
8
  # The device_authorization request, which a registered client signs with
9
- # its client assertion, must refuse a client-chosen role or scope. Probed
10
- # with roles the origin actually declares, since a vulnerable origin
11
- # refuses an undeclared one too; the role-less request must still open
12
- # the ceremony.
9
+ # its client assertion, must refuse a client-chosen role. Probed with
10
+ # roles the origin actually declares, since a vulnerable origin refuses
11
+ # an undeclared one too; the role-less request must still open the
12
+ # ceremony. A `scope` is ignored, so only an approval shows what it
13
+ # grants: the stylish suite checks that.
13
14
  class DeviceGrantRoleSelfSelection < Scenario
14
15
  # Refused by a vulnerable origin too; probed only to show both filters in the detail.
15
16
  UNDECLARED_ROLE = 'master'
@@ -42,7 +43,7 @@ module Kiosk
42
43
  detail: summary(probes, control_detail, declared, wire_role))
43
44
  end
44
45
 
45
- # [refused?, detail] for each role or scope the request names.
46
+ # [refused?, detail] for each role the request names.
46
47
  def probe(client, principal, declared)
47
48
  probe_labels(declared).map do |label, param, value|
48
49
  resp = client.device_authorization(principal, param => value)
@@ -55,7 +56,7 @@ module Kiosk
55
56
  "#{probes.map(&:last).join('; ')}; #{control_detail} " \
56
57
  "[declared roles probed: #{declared.inspect} " \
57
58
  "(#{wire_role.inspect} read off this origin's own client_credentials token); " \
58
- 'want every role/scope refused 400 invalid_request AND the role-less ' \
59
+ 'want every role refused 400 invalid_request AND the role-less ' \
59
60
  'ceremony still opening]'
60
61
  end
61
62
 
@@ -64,14 +65,9 @@ module Kiosk
64
65
  end
65
66
 
66
67
  def probe_labels(declared)
67
- declared.flat_map do |role|
68
- %i[role scope].map do |param|
69
- ["#{param}=#{role} (DECLARED by this origin — the escalation itself)", param, role]
70
- end
71
- end + %i[role scope].map do |param|
72
- ["#{param}=#{UNDECLARED_ROLE} (undeclared; refused by the vulnerable code too, " \
73
- 'so it proves nothing alone)', param, UNDECLARED_ROLE]
74
- end
68
+ declared.map { |role| ["role=#{role} (DECLARED by this origin — the escalation itself)", :role, role] } +
69
+ [["role=#{UNDECLARED_ROLE} (undeclared; refused by the vulnerable code too, " \
70
+ 'so it proves nothing alone)', :role, UNDECLARED_ROLE]]
75
71
  end
76
72
 
77
73
  def control(client, principal)
@@ -3,7 +3,7 @@
3
3
  module Kiosk
4
4
  module Redteam
5
5
  module Scenarios
6
- # With a PoW gate, registration with no proof or a wrong one must be refused
6
+ # With a registration toll, registration with no proof or a wrong one must be refused
7
7
  # (not a 201, no client_id, not a crash), while a solved control registration succeeds.
8
8
  class RegistrationWithoutPow < Scenario
9
9
  def initialize
@@ -11,7 +11,7 @@ module Kiosk
11
11
  end
12
12
 
13
13
  def call(client, profile)
14
- return skip_verdict('pow_difficulty is 0 (no PoW gate)') unless profile.pow_difficulty.positive?
14
+ return skip_verdict('pow_difficulty is 0 (no registration toll)') unless profile.pow_difficulty.positive?
15
15
 
16
16
  attack(client)
17
17
  end
@@ -45,7 +45,7 @@ module Kiosk
45
45
  'CONTROL FAILED: a properly solved registration must return 201 with ' \
46
46
  "a client_id — got HTTP #{control.status} #{control.body.inspect}. " \
47
47
  'A server that refuses every registration refuses the two unproven ' \
48
- 'ones too, which says nothing about a PoW gate.'
48
+ 'ones too, which says nothing about a registration toll.'
49
49
  end
50
50
 
51
51
  # Why this attempt is not a PoW refusal, or nil when it is.
@@ -30,6 +30,15 @@ module Kiosk
30
30
  header.slice('kid', 'typ'))
31
31
  end
32
32
 
33
+ # +checkout_jwt+ with each priced line +by+ cents cheaper and the total to match, so the
34
+ # lines still sum to the total. The lines keep every other member the operator signed.
35
+ def underpriced_checkout(checkout_jwt, by:)
36
+ paid, *priced = JWT.decode(checkout_jwt, nil, false).first.fetch('line_items')
37
+ priced = priced.map { |line| line.merge('price_cents' => line.fetch('price_cents') - by) }
38
+ tampered_checkout(checkout_jwt, line_items: [paid, *priced],
39
+ total_amount_cents: priced.sum { |line| line.fetch('qty') * line.fetch('price_cents') })
40
+ end
41
+
33
42
  # The two mandates for +checkout_jwt+, with the payment mandate's fields changed and signed again.
34
43
  def mandates_with_payment(principal, checkout_jwt, **changes)
35
44
  mandates = Kiosk::TestHelpers::Mandate.pay(principal.key, checkout_jwt)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kiosk
4
4
  module Redteam
5
- VERSION = '0.6.1'
5
+ VERSION = '0.6.28'
6
6
  end
7
7
  end
data/lib/kiosk/redteam.rb CHANGED
@@ -25,6 +25,7 @@ require 'kiosk/redteam/scenarios/forged_kyc'
25
25
  require 'kiosk/redteam/scenarios/spent_resource_reuse'
26
26
  require 'kiosk/redteam/scenarios/pay_for_other_use_self'
27
27
  require 'kiosk/redteam/scenarios/wrong_currency_payment'
28
+ require 'kiosk/redteam/scenarios/call_toll'
28
29
 
29
30
  module Kiosk
30
31
  # Adversarial regression harness: drives hostile HTTP scenarios against a
@@ -37,8 +38,8 @@ module Kiosk
37
38
  PAYMENT_REQUIRED_CODES = {
38
39
  'pow_required' =>
39
40
  'a toll was DEMANDED, not a refusal — the request was deferred until a proof is ' \
40
- 'supplied. This harness PAYS that toll on every verb, so seeing this code here ' \
41
- 'means the demand survived a paid retry (or arrived with no challenges to ' \
41
+ 'supplied. This harness SOLVES that toll on every verb, so seeing this code here ' \
42
+ 'means the demand survived a tolled retry (or arrived with no challenges to ' \
42
43
  'solve); either way the attack itself was never evaluated',
43
44
  'payment_setup_required' =>
44
45
  "the principal has no payment instrument on file — a gap in the ATTACKER's setup, " \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiosk-redteam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Pirozhkov
@@ -38,16 +38,17 @@ dependencies:
38
38
  - !ruby/object:Gem::Version
39
39
  version: 0.6.0
40
40
  description: |
41
- kiosk-redteam drives hostile HTTP scenarios against any Kiosk provider
42
- and asserts each attack is correctly blocked — a deliberate refusal, never
41
+ kiosk-redteam drives hostile HTTP scenarios against a Kiosk origin that
42
+ mounts the engine at /kiosk, and asserts each attack is correctly blocked — a deliberate refusal, never
43
43
  a crash and never a toll the harness could not settle. A scenario that
44
44
  finds a real breach fails loudly.
45
45
 
46
46
  Ships a Scenario/Verdict/Runner framework and a library of generic attack
47
- scenarios parameterised by a per-provider Profile. It attacks through the
47
+ scenarios parameterised by a Profile of the origin. It attacks through the
48
48
  assistant client kiosk-test-support ships.
49
49
 
50
- No dependency on Rails.
50
+ `require "kiosk/redteam"` loads no Rails. Through kiosk-test-support,
51
+ installing the gem installs Rails.
51
52
  email:
52
53
  - hello@fili.pp.ru
53
54
  executables: []
@@ -63,6 +64,7 @@ files:
63
64
  - lib/kiosk/redteam/profile.rb
64
65
  - lib/kiosk/redteam/runner.rb
65
66
  - lib/kiosk/redteam/scenario.rb
67
+ - lib/kiosk/redteam/scenarios/call_toll.rb
66
68
  - lib/kiosk/redteam/scenarios/cross_tenant_read.rb
67
69
  - lib/kiosk/redteam/scenarios/device_grant_role_self_selection.rb
68
70
  - lib/kiosk/redteam/scenarios/expired_kyc.rb
@@ -110,5 +112,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  requirements: []
111
113
  rubygems_version: 4.0.3
112
114
  specification_version: 4
113
- summary: Adversarial regression harness for Kiosk providers
115
+ summary: Adversarial regression harness for Kiosk operators
114
116
  test_files: []