kiosk-redteam 0.5.20 → 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: f685eaaad2b4f5c00e9a30b853c7b955944b5ebfe3cc2232da9595a5deb5325b
4
- data.tar.gz: 5e7361227cfe0ac60f95085a875af20451992d0ed0a0514ca1ef3d7f50101efa
3
+ metadata.gz: 8f1c350b529c0651217fc29e20719585273ce68bf9235287f1a587917c46e9b3
4
+ data.tar.gz: 5d0d5f27ea81574696402ddf454590c71599c37fd8f753e54cb0c68012d90d63
5
5
  SHA512:
6
- metadata.gz: c59a347eb3eb6261fd991cb85047c3698bac43d6d29d3dbbfcb1bbcc6cec4a86d1957dbc47a5853cd9be412b55219cfc45ac5821b8ac4d2b4ef659000adf7a54
7
- data.tar.gz: 043e887db0d72927446207bf3e0c3dff8aee07d44f976890c74c40f72660ee0e4d2f74d6ff12d93f47809884a6c067db5e8b89b044b931b0a4e05fbe0d030625
6
+ metadata.gz: e09f81b23c9c9e4223b8172f526e37063f71d868b8da20af516f1b3865d9c3ee2ca2f9d70634cd232afb2da1020539276aed48d00887617d93342fd567a0f367
7
+ data.tar.gz: c7aa09739022cafbf8a5f4c163213a3c25f0f39fca4889ffaa2642eaee931905be7af76177ea27f8aff8c5b01d3be267b164c3c2562bdb5ae281ed57e25e6441
data/CHANGELOG.md CHANGED
@@ -12,6 +12,159 @@ 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
+
127
+ ## [0.6.1] — 2026-10-22
128
+
129
+ - 2026-10-22: Version 0.6.1, the tree cut that matches skill 0.6.1.
130
+ - 2026-10-21: The bundle that runs a battery against an Equihash origin holds `kiosk-pow-equihash`; kiosk-test-support does not bring it.
131
+
132
+ ## [0.6.0] — 2026-10-21
133
+
134
+ - 2026-10-21: Scenarios and batteries sign with Ed25519 keys, and the KYC test issuer signs EdDSA.
135
+ - 2026-10-21: Version 0.6.0, the tree cut that matches skill 0.6.0.
136
+
137
+ ## [0.5.27] — 2026-10-21
138
+
139
+ - 2026-10-21: Scenarios and batteries register at `oauth/register` and get tokens by client assertion and DPoP; the device-grant probes sign with a registered client.
140
+ - 2026-10-21: Version 0.5.27, the tree cut that matches skill 0.5.27.
141
+
142
+ ## [0.5.26] — 2026-10-21
143
+
144
+ - 2026-10-21: Version 0.5.26, the tree cut that matches skill 0.5.26.
145
+
146
+ ## [0.5.25] — 2026-10-21
147
+
148
+ - 2026-10-21: Version 0.5.25, the tree cut that matches skill 0.5.25.
149
+
150
+ ## [0.5.24] — 2026-10-21
151
+
152
+ - 2026-10-21: Version 0.5.24, the tree cut that matches skill 0.5.24.
153
+
154
+ ## [0.5.23] — 2026-10-21
155
+
156
+ - 2026-10-21: `Scenarios::StolenToken` asserts that a real access token without its key is refused 401. Every suite and scenario sends tokens with a DPoP proof.
157
+ - 2026-10-21: Version 0.5.23, the tree cut that matches skill 0.5.23.
158
+
159
+ ## [0.5.22] — 2026-10-21
160
+
161
+ - 2026-10-21: The payment scenarios attack the signed checkout and the two AP2 v0.2 mandates; `WrongCurrencyCart` is `WrongCurrencyPayment`.
162
+ - 2026-10-21: Version 0.5.22, the tree cut that matches skill 0.5.22.
163
+
164
+ ## [0.5.21] — 2026-10-21
165
+
166
+ - 2026-10-21: Version 0.5.21, the tree cut that matches skill 0.5.21.
167
+
15
168
  ## [0.5.20] — 2026-10-20
16
169
 
17
170
  - 2026-10-20: Version 0.5.20, the tree cut that matches skill 0.5.20.
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, how to build a mandate) 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,21 +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
- 402 challenges with the reference solver that ships inside `kiosk-pow-equihash`,
70
- so the machine running the battery needs **`python3` with `numpy`** on `PATH`. Point a battery at an
71
- origin whose PoW is off and nothing is solved and nothing is needed.
70
+ 402 challenges with the reference solver that ships inside `kiosk-pow-equihash`.
71
+ The bundle that runs the battery holds that gem, as the origin's bundle does,
72
+ and the machine needs **`python3` with `numpy`** on `PATH`. Point a battery at an
73
+ origin whose toll is off and nothing is solved and nothing is needed.
72
74
 
73
75
  ## Usage
74
76
 
75
- 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
76
78
  verdict:
77
79
 
78
80
  ```ruby
@@ -81,7 +83,7 @@ require "kiosk/redteam"
81
83
  SERVER = ENV.fetch("SERVER_URL", "http://127.0.0.1:3000")
82
84
 
83
85
  profile = Kiosk::Redteam::Profile.new(
84
- # >0 means this origin is expected to gate /auth/register with a toll.
86
+ # >0 means this origin is expected to gate oauth/register with a toll.
85
87
  pow_difficulty: 1,
86
88
  # The roles this origin declares (Kiosk.configuration.roles), as strings.
87
89
  declared_roles: %w[customer],
@@ -91,7 +93,7 @@ profile = Kiosk::Redteam::Profile.new(
91
93
  # response object (they often differ).
92
94
  row_id_key: "id",
93
95
  result_id_key: "order_id",
94
- # 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.
95
97
  create_owned: ->(client, principal) {
96
98
  resp = client.run(principal, name: "create_order", items: [{ sku: "SKU-1", qty: 1 }])
97
99
  raise "create_order failed (#{resp.status}): #{resp.body.inspect}" unless resp.status == 200
@@ -108,6 +110,7 @@ battery.absorb(runner.run([
108
110
  Kiosk::Redteam::Scenarios::CrossTenantRead.new,
109
111
  Kiosk::Redteam::Scenarios::ForgedUserId.new,
110
112
  Kiosk::Redteam::Scenarios::TokenTampering.new,
113
+ Kiosk::Redteam::Scenarios::StolenToken.new,
111
114
  Kiosk::Redteam::Scenarios::RegistrationWithoutPow.new,
112
115
  Kiosk::Redteam::Scenarios::DeviceGrantRoleSelfSelection.new,
113
116
  ]))
@@ -117,7 +120,7 @@ exit battery.report!
117
120
 
118
121
  Every field of `Profile` is optional; a scenario whose field is `nil` skips
119
122
  itself rather than inventing a surface. That is what lets one battery cover a
120
- 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
121
124
  operator demo in this repo, built on this API — read one of those for a worked,
122
125
  running profile against a real origin. Each runs in its demo's directory, with
123
126
  that demo's bundle. A demo that takes payments charges a stripe-mock: start the
@@ -135,18 +138,20 @@ scenarios share:
135
138
 
136
139
  | Scenario | Asserts |
137
140
  |---|---|
138
- | `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 |
139
142
  | `ForgedUserId` | a caller-supplied `user_id` never decides ownership |
140
- | `PrivilegeSelfSelection` | a client-chosen registration role is ignored — the role is server-pinned |
141
- | `DeviceGrantRoleSelfSelection` | the claim ceremony's unauthenticated opening request refuses `role`/`scope`, at a DECLARED value as well as an invented one |
143
+ | `PrivilegeSelfSelection` | a role in the registration body does not reach the client's token — the role is server-pinned |
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 |
142
145
  | `SpentResourceReuse` | a consumed resource cannot be re-activated |
143
146
  | `PayForOtherUseSelf` | B paying for A's resource does not let B use it |
144
147
  | `TokenTampering` | a JWT with a flipped claim and the original signature is 401 |
145
- | `RegistrationWithoutPow` | a missing or bad proof is rejected when the origin charges a toll |
146
- | `MandatePrincipalSwap` | B signing a mandate that carries A's identity is rejected |
147
- | `MandateReplay` | A's signed mandate JWS re-submitted under B's token is rejected |
148
+ | `StolenToken` | a real access token without its key is 401: as a bearer token, and with a DPoP proof that another key signs |
149
+ | `RegistrationWithoutPow` | a missing or bad proof is rejected when the origin asks a toll |
150
+ | `MandatePrincipalSwap` | B paying, with its own key, the checkout the operator signed for A is rejected |
151
+ | `MandateReplay` | A's signed mandates re-submitted under B's token are rejected |
148
152
  | `UnpaidGatedAction` | the gated action without a prior settled payment is denied |
149
- | `WrongCurrencyCart` | a chain-consistent cart denominated in a currency the operator does not price in is refused at capture |
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` |
150
155
  | `MissingKyc` | the gated action after payment but without an attestation is denied |
151
156
  | `ExpiredKyc` | an attestation whose `exp` has passed is rejected |
152
157
  | `ForgedKyc` | an attestation with a wrong issuer or a bad signature is rejected |
@@ -154,22 +159,22 @@ scenarios share:
154
159
  Beside them the gem ships `Profile`, `Scenario`, `Verdict`, `Runner`,
155
160
  `Battery` and `LeakScan`, which decides whether a refusal leaked the runtime's
156
161
  own vocabulary, discounting needles the attack itself supplied. A scenario
157
- receives a `Kiosk::TestHelpers::Assistant` — register, query, run, pay with
158
- signed mandates, kyc, and the device-authorization request — and its
159
- `events(principal)` is the assistant's side of `<endpoint>/events`.
162
+ receives a `Kiosk::TestHelpers::Assistant` — register, token, query, run, pay
163
+ with closed AP2 mandates, kyc, and the device-authorization request — and its
164
+ `events(principal)`, for one registered assistant, is the assistant's side of `/kiosk/events`.
160
165
 
161
166
  ## Your own beats, in the same battery
162
167
 
163
- 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
164
169
  Kiosk origin has to survive; the interesting half is always the attacks on
165
- *your* verbs — your enum filters, your price arithmetic, your ownership joins.
170
+ *your* operations — your enum filters, your price arithmetic, your ownership joins.
166
171
  Two classes carry that half, and they are the reason a hand-written beat and a
167
172
  library scenario can sit in one run.
168
173
 
169
- `Kiosk::TestHelpers::Wire` is the raw wire: an arbitrary method at an arbitrary path with arbitrary
170
- headers, which is what an attack on the REQUEST rather than on the principal
171
- needs — a forged or absent `Authorization`, a verb nobody registered, the wrong
172
- 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
173
178
  body that is not JSON reads as `{}` and a connection error reads as status `0`,
174
179
  so a hostile answer is asserted on instead of crashing the run; the bytes stay
175
180
  available on `raw_body` for a `LeakScan`.
@@ -182,8 +187,8 @@ wire = Kiosk::TestHelpers::Wire.new(base_url: SERVER)
182
187
  client = Kiosk::TestHelpers::Assistant.new(base_url: SERVER)
183
188
  battery = Kiosk::Redteam::Battery.new
184
189
 
185
- # your own beat, against your own verb
186
- status, rows = wire.get_json("/kiosk/my_listings", {}, wire.bearer(bob.token))
190
+ # your own beat, against your own operation
191
+ status, rows = wire.get_json("/kiosk/my_listings", {}, wire.dpop(bob.token, bob.key))
187
192
  battery.record("CrossTenantRead", status == 200 && !ids(rows).include?(alice_row),
188
193
  "Bob's rows #{ids(rows).inspect} exclude Alice's #{alice_row}")
189
194
 
@@ -206,7 +211,7 @@ scenario, and that must not pass as a clean run.
206
211
 
207
212
  Pass `on_skip: :breach` for a scenario whose surface this origin definitely
208
213
  has: there, a skip is a defect of the harness rather than a property of the
209
- 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.
210
215
 
211
216
  Pass `untested: true` to `record` when a setup step of your beat failed. The
212
217
  attack did not reach its gate, so the beat is UNTESTED and the run fails with
@@ -218,23 +223,22 @@ Subclass `Scenario`, name what you are attacking, and return a `Verdict` that
218
223
  says which gate you demanded:
219
224
 
220
225
  ```ruby
221
- class UnknownVerbIs404 < Kiosk::Redteam::Scenario
226
+ class UnknownOperationIs404 < Kiosk::Redteam::Scenario
222
227
  def initialize
223
- super(name: "UnknownVerbIs404")
228
+ super(name: "UnknownOperationIs404")
224
229
  end
225
230
 
226
231
  def call(client, profile)
227
232
  principal = client.register!
228
- verdict_from(client.query(principal, name: "no_such_verb"), expect: 404)
233
+ verdict_from(client.query(principal, name: "no_such_operation"), expect: 404)
229
234
  end
230
235
  end
231
236
  ```
232
237
 
233
238
  ## Status
234
239
 
235
- Pre-v1.0 alpha. The `Scenario` / `Profile` / `Verdict` surface is stable across
236
- pre-v1.0 minor bumps; the scenario library grows as gates are added
237
- (`CHANGELOG.md` tracks).
240
+ Pre-v1.0 alpha: the `Scenario` / `Profile` / `Verdict` surface may change
241
+ between releases (`CHANGELOG.md` tracks each change).
238
242
 
239
243
  ## License
240
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)
@@ -5,23 +5,26 @@ module Kiosk
5
5
  # What an origin tells the generic scenarios about itself. A nil field skips
6
6
  # the scenarios that need that surface.
7
7
  #
8
- # pow_difficulty >0 when /register is gated by a PoW toll; 0 skips RegistrationWithoutPow
8
+ # pow_difficulty >0 when oauth/register is gated by a PoW toll; 0 skips RegistrationWithoutPow
9
9
  # declared_roles the roles the origin declares; DeviceGrantRoleSelfSelection needs a real one
10
10
  # requires_kyc whether the gated action needs a KYC attestation
11
- # currency the ISO 4217 code the origin prices in, lower case (WrongCurrencyCart)
11
+ # currency the ISO 4217 code the origin prices in, lower case (WrongCurrencyPayment)
12
12
  # per_user_query query returning the caller's own rows (CrossTenantRead)
13
13
  # row_id_key key of a row's id in query results
14
14
  # result_id_key key of the new resource's id in forge_action's result
15
- # create_owned (client, principal) -> Hash with at least :id
15
+ # create_owned (client, principal) -> Hash with at least :id, and :checkout_jwt where it is paid for
16
16
  # forge_action action whose caller-supplied user_id the server must ignore
17
17
  # forge_args (client, principal_a, principal_b) -> Hash, without user_id
18
18
  # gated_action action gated behind payment (and KYC when requires_kyc)
19
19
  # gated_action_consumes false when calling gated_action twice is correct (skips SpentResourceReuse)
20
20
  # gated_args (owned_ref) -> Hash
21
- # pay_for (client, principal, owned_ref) -> { intent:, cart: }
21
+ # pay_for (client, principal, owned_ref) -> the checkout_jwt that pays for owned_ref
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)
@@ -25,6 +25,11 @@ module Kiosk
25
25
 
26
26
  private
27
27
 
28
+ # The client a 201 registration answer names, with the key it registered. No token yet.
29
+ def registered_principal(resp, key)
30
+ Kiosk::TestHelpers::Assistant::Principal.new(agent_id: resp.body['client_id'], user_id: nil, token: nil, key: key)
31
+ end
32
+
28
33
  # Changes a payload claim and keeps the original signature.
29
34
  def tamper_token(token)
30
35
  TokenClaims.tamper(token)
@@ -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
@@ -5,10 +5,12 @@ require 'openssl'
5
5
  module Kiosk
6
6
  module Redteam
7
7
  module Scenarios
8
- # The unauthenticated device_authorization request must refuse a
9
- # client-chosen role or scope. Probed with roles the origin actually
10
- # declares, since a vulnerable origin refuses an undeclared one too; the
11
- # role-less request must still open the ceremony.
8
+ # The device_authorization request, which a registered client signs with
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.
12
14
  class DeviceGrantRoleSelfSelection < Scenario
13
15
  # Refused by a vulnerable origin too; probed only to show both filters in the detail.
14
16
  UNDECLARED_ROLE = 'master'
@@ -21,28 +23,30 @@ module Kiosk
21
23
  end
22
24
 
23
25
  def call(client, profile)
24
- wire_role, setup = wire_declared_role(client)
26
+ principal, setup = registered_client(client)
27
+ setup || attack(client, principal, profile)
28
+ end
29
+
30
+ private
31
+
32
+ def attack(client, principal, profile)
33
+ wire_role, setup = wire_declared_role(client, principal)
25
34
  return setup if setup
26
35
 
27
36
  declared = (profile.declared_roles + [wire_role]).compact.uniq
28
37
  return skip_verdict(no_declared_role_reason) if declared.empty?
29
38
 
30
- probes = probe(client, declared)
31
- control_ok, control_detail = control(client)
39
+ probes = probe(client, principal, declared)
40
+ control_ok, control_detail = control(client, principal)
32
41
  refused = probes.all?(&:first)
33
42
  Verdict.new(blocked: refused && control_ok, skipped: false, status: refused ? 400 : 200,
34
43
  detail: summary(probes, control_detail, declared, wire_role))
35
44
  end
36
45
 
37
- private
38
-
39
- # [refused?, detail] for each role or scope the request names.
40
- def probe(client, declared)
41
- pem = OpenSSL::PKey::RSA.generate(2048).public_key.to_pem
46
+ # [refused?, detail] for each role the request names.
47
+ def probe(client, principal, declared)
42
48
  probe_labels(declared).map do |label, param, value|
43
- resp = client.device_authorization(
44
- client_id: 'redteam-device-grant-role', public_key: pem, param => value
45
- )
49
+ resp = client.device_authorization(principal, param => value)
46
50
  [resp.status == 400 && body_field(resp, 'error') == 'invalid_request',
47
51
  "#{label} -> HTTP #{resp.status} error=#{body_field(resp, 'error').inspect}"]
48
52
  end
@@ -51,8 +55,8 @@ module Kiosk
51
55
  def summary(probes, control_detail, declared, wire_role)
52
56
  "#{probes.map(&:last).join('; ')}; #{control_detail} " \
53
57
  "[declared roles probed: #{declared.inspect} " \
54
- "(#{wire_role.inspect} read off this origin's own registration token); " \
55
- 'want every role/scope refused 400 invalid_request AND the role-less ' \
58
+ "(#{wire_role.inspect} read off this origin's own client_credentials token); " \
59
+ 'want every role refused 400 invalid_request AND the role-less ' \
56
60
  'ceremony still opening]'
57
61
  end
58
62
 
@@ -61,48 +65,46 @@ module Kiosk
61
65
  end
62
66
 
63
67
  def probe_labels(declared)
64
- declared.flat_map do |role|
65
- %i[role scope].map do |param|
66
- ["#{param}=#{role} (DECLARED by this origin — the escalation itself)", param, role]
67
- end
68
- end + %i[role scope].map do |param|
69
- ["#{param}=#{UNDECLARED_ROLE} (undeclared; refused by the vulnerable code too, " \
70
- 'so it proves nothing alone)', param, UNDECLARED_ROLE]
71
- 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]]
72
71
  end
73
72
 
74
- def control(client)
75
- key = OpenSSL::PKey::RSA.generate(2048)
76
- resp = client.device_authorization(
77
- client_id: 'redteam-device-grant-role', public_key: key.public_key.to_pem
78
- )
73
+ def control(client, principal)
74
+ resp = client.device_authorization(principal)
79
75
  code = resp.body.is_a?(Hash) ? resp.body['user_code'].to_s : ''
80
76
  [resp.status == 200 && code.match?(USER_CODE),
81
77
  "CONTROL role-less request -> HTTP #{resp.status} user_code=#{code.inspect}"]
82
78
  end
83
79
 
84
- # The `role` claim of a token this origin mints at registration.
85
- def wire_declared_role(client)
86
- resp = client.register_raw
87
- failure = (registration_failure(resp) unless resp.status == 201)
88
- return [nil, failure] if failure
80
+ # The client that signs every request of this scenario, or the verdict of a failed registration.
81
+ def registered_client(client)
82
+ key = OpenSSL::PKey.generate_key('ED25519')
83
+ resp = client.register_raw(key:)
84
+ return [registered_principal(resp, key), nil] if resp.status == 201
89
85
 
90
- [token_role(body_field(resp, 'access_token')), nil]
86
+ [nil, untested_verdict(resp.status, 'SETUP FAILED: the registration of the client that signs the probes ' \
87
+ "returned HTTP #{resp.status} #{resp.body.inspect}.")]
91
88
  end
92
89
 
93
- def registration_failure(resp)
94
- setup_failure(
90
+ # The `role` claim of the first token this origin mints for the client.
91
+ def wire_declared_role(client, principal)
92
+ resp = client.token(principal)
93
+ failure = setup_failure(
95
94
  resp,
96
- step: 'the CONTROL registration this scenario reads a declared role from',
95
+ step: 'the CONTROL token request this scenario reads a declared role from',
97
96
  because: 'without a role the origin actually declares, the only probe left is an ' \
98
97
  'invented one — which even a vulnerable origin refuses, so the battery ' \
99
98
  'would print BLOCKED without testing anything.'
100
99
  )
100
+ return [nil, failure] if failure
101
+
102
+ [token_role(body_field(resp, 'access_token')), nil]
101
103
  end
102
104
 
103
105
  def no_declared_role_reason
104
106
  'this origin declares no role — `declared_roles` is empty in the profile AND the ' \
105
- 'token it minted at registration carries no `role` claim, so a client-chosen ' \
107
+ 'first token it minted carries no `role` claim, so a client-chosen ' \
106
108
  'DECLARED role has nothing to name here'
107
109
  end
108
110
 
@@ -3,7 +3,7 @@
3
3
  module Kiosk
4
4
  module Redteam
5
5
  module Scenarios
6
- # B pays, under its own token and key, mandates claiming A's identity: must be refused.
6
+ # B pays, under its own token and key, the checkout the operator signed for A: must be refused.
7
7
  class MandatePrincipalSwap < Scenario
8
8
  def initialize
9
9
  super(name: 'MandatePrincipalSwap')
@@ -19,12 +19,11 @@ module Kiosk
19
19
  def attack(client, profile)
20
20
  a = client.register!
21
21
  b = client.register!
22
- mandates = profile.pay_for.call(client, a, profile.create_owned.call(client, a))
23
- resp = client.pay(b, intent: mandates[:intent], cart: mandates[:cart])
22
+ resp = client.pay(b, profile.pay_for.call(client, a, profile.create_owned.call(client, a)))
24
23
 
25
24
  # Only 403: a 402 or 401 means the swap was never examined.
26
25
  verdict_from(resp, expect: 403, expect_code: %w[forbidden rls_denied],
27
- detail: "principal-swap mandate accepted (HTTP #{resp.status})")
26
+ detail: "B paid the checkout signed for A (HTTP #{resp.status})")
28
27
  end
29
28
  end
30
29
  end
@@ -3,7 +3,7 @@
3
3
  module Kiosk
4
4
  module Redteam
5
5
  module Scenarios
6
- # B re-submits A's already-used mandate JWS under B's token: must be refused.
6
+ # B re-submits A's already-used mandates, signed by A's key, under B's token: must be refused.
7
7
  class MandateReplay < Scenario
8
8
  def initialize
9
9
  super(name: 'MandateReplay')
@@ -19,23 +19,14 @@ module Kiosk
19
19
  def attack(client, profile)
20
20
  a = client.register!
21
21
  b = client.register!
22
- mandates = profile.pay_for.call(client, a, profile.create_owned.call(client, a))
23
- signed = signed_mandates(client, a, mandates)
24
- client.pay(a, intent: mandates[:intent], cart: mandates[:cart])
22
+ signed = Kiosk::TestHelpers::Mandate.pay(a.key, profile.pay_for.call(client, a, profile.create_owned.call(client, a)))
23
+ client.pay_raw(a, **signed)
25
24
  resp = client.pay_raw(b, **signed)
26
25
 
27
26
  # Only 403: a 402 decline would mean the replay was never verified.
28
27
  verdict_from(resp, expect: 403, expect_code: %w[forbidden rls_denied],
29
28
  detail: "mandate replay accepted under B's token (HTTP #{resp.status})")
30
29
  end
31
-
32
- def signed_mandates(client, principal, mandates)
33
- {
34
- intent_jws: client.sign_mandate(principal, mandates[:intent]),
35
- cart_jws: client.sign_mandate(principal, mandates[:cart]),
36
- payment_jws: client.sign_mandate(principal, client.payment_mandate(principal, cart: mandates[:cart]))
37
- }
38
- end
39
30
  end
40
31
  end
41
32
  end
@@ -3,8 +3,8 @@
3
3
  module Kiosk
4
4
  module Redteam
5
5
  module Scenarios
6
- # B pays a mandate that references A's resource, then invokes the gated
7
- # action on it: the ownership gate must refuse at use time, not only at pay time.
6
+ # B pays the checkout of A's resource, then invokes the gated action on
7
+ # it: the ownership gate must refuse at use time, not only at pay time.
8
8
  class PayForOtherUseSelf < Scenario
9
9
  KYC_BECAUSE = 'B would otherwise be refused for want of KYC, and this scenario would ' \
10
10
  'credit that refusal to the ownership gate it exists to prove.'
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'openssl'
4
+
3
5
  module Kiosk
4
6
  module Redteam
5
7
  module Scenarios
6
- # A role injected into /auth/register must not reach the issued token.
7
- # A refusal counts only if the same registration without the role succeeds.
8
+ # A role injected into the registration body must not reach the token
9
+ # that the client then gets. A refusal counts only if the same
10
+ # registration without the role succeeds.
8
11
  class PrivilegeSelfSelection < Scenario
9
12
  ESCALATED_ROLE = 'master'
10
13
 
@@ -13,15 +16,24 @@ module Kiosk
13
16
  end
14
17
 
15
18
  def call(client, _profile)
16
- resp = client.register_raw(wire_role: ESCALATED_ROLE)
19
+ key = OpenSSL::PKey.generate_key('ED25519')
20
+ resp = client.register_raw(wire_role: ESCALATED_ROLE, key:)
17
21
  return refusal_verdict(client, resp) unless resp.status == 201
18
- return blocked_verdict(201) unless TokenClaims.claims(access_token(resp))&.fetch('role', nil) == ESCALATED_ROLE
19
22
 
20
- breach_verdict(201, "issued token carries the self-selected role #{ESCALATED_ROLE.inspect}")
23
+ issued = client.token(registered_principal(resp, key))
24
+ setup_failure(issued, step: 'the token request after the registration with the injected role',
25
+ because: 'without a token there is no role to read.') || role_verdict(issued)
21
26
  end
22
27
 
23
28
  private
24
29
 
30
+ def role_verdict(issued)
31
+ role = TokenClaims.claims(issued.body['access_token'])&.fetch('role', nil)
32
+ return blocked_verdict(201) unless [role, issued.body['scope']].include?(ESCALATED_ROLE)
33
+
34
+ breach_verdict(issued.status, "issued token carries the self-selected role #{ESCALATED_ROLE.inspect}")
35
+ end
36
+
25
37
  def refusal_verdict(client, resp)
26
38
  if resp.status >= 500 || resp.status.zero?
27
39
  return breach_verdict(resp.status,
@@ -33,18 +45,14 @@ module Kiosk
33
45
  end
34
46
 
35
47
  def control_failure(control, resp)
36
- return nil if control.status == 201 && access_token(control)
48
+ return nil if control.status == 201 && control.body.is_a?(Hash) && control.body['client_id']
37
49
 
38
50
  breach_verdict(control.status,
39
- 'CONTROL FAILED: an honest registration must return 201 with an ' \
40
- "access_token — got HTTP #{control.status} #{control.body.inspect}. " \
51
+ 'CONTROL FAILED: an honest registration must return 201 with a ' \
52
+ "client_id — got HTTP #{control.status} #{control.body.inspect}. " \
41
53
  "The injected registration's HTTP #{resp.status} refusal therefore " \
42
54
  'says nothing about whether the role is pinned server-side.')
43
55
  end
44
-
45
- def access_token(resp)
46
- resp.body.is_a?(Hash) ? resp.body['access_token'] : nil
47
- end
48
56
  end
49
57
  end
50
58
  end
@@ -3,15 +3,15 @@
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
7
- # (not a 201, no token, not a crash), while a solved control registration succeeds.
6
+ # With a registration toll, registration with no proof or a wrong one must be refused
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
10
10
  super(name: 'RegistrationWithoutPow')
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
@@ -38,14 +38,14 @@ module Kiosk
38
38
  end
39
39
 
40
40
  def honest_registration?(control)
41
- control.status == 201 && token_of(control)
41
+ control.status == 201 && client_id_of(control)
42
42
  end
43
43
 
44
44
  def control_problem(control)
45
45
  'CONTROL FAILED: a properly solved registration must return 201 with ' \
46
- "an access_token — got HTTP #{control.status} #{control.body.inspect}. " \
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.
@@ -55,14 +55,14 @@ module Kiosk
55
55
  return "#{label} crashed (HTTP #{resp.status}: #{resp.body.inspect}) — " \
56
56
  'a crash is not a gate'
57
57
  end
58
- return nil unless token_of(resp)
58
+ return nil unless client_id_of(resp)
59
59
 
60
- "#{label} returned an access_token on HTTP #{resp.status}"
60
+ "#{label} returned a client_id on HTTP #{resp.status}"
61
61
  end
62
62
 
63
- def token_of(resp)
63
+ def client_id_of(resp)
64
64
  body = resp.body
65
- body.is_a?(Hash) ? body['access_token'] : nil
65
+ body.is_a?(Hash) ? body['client_id'] : nil
66
66
  end
67
67
  end
68
68
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl'
4
+
5
+ module Kiosk
6
+ module Redteam
7
+ module Scenarios
8
+ # A copied access token without its private key buys no request (RFC 9449):
9
+ # sent as a bearer token, or with a DPoP proof that another key signs, it
10
+ # must be refused 401. The token with its own key is the control.
11
+ class StolenToken < Scenario
12
+ def initialize
13
+ super(name: 'StolenToken')
14
+ end
15
+
16
+ def call(client, profile)
17
+ verb = profile.per_user_query
18
+ return skipped if verb.nil?
19
+
20
+ victim = client.register!
21
+ control = client.query(victim, name: verb)
22
+ return vacuous(control) unless control.status == 200
23
+
24
+ accepted(attacks(client, victim, verb))
25
+ end
26
+
27
+ private
28
+
29
+ def skipped = Verdict.new(blocked: false, skipped: true, status: 0, detail: TokenTampering::NO_ROUTED_VERB)
30
+
31
+ # Blocked when every attack was refused 401; else the first accepted one.
32
+ def accepted(attacks)
33
+ label, resp = attacks.find { |_, answer| !verdict_from(answer, expect: 401).blocked }
34
+ return blocked_verdict(401) unless resp
35
+
36
+ breach_verdict(resp.status, "a stolen token was accepted #{label} (HTTP #{resp.status})")
37
+ end
38
+
39
+ def vacuous(control)
40
+ breach_verdict(control.status, "the token with its own key was refused (HTTP #{control.status}): the refusals prove nothing")
41
+ end
42
+
43
+ def attacks(client, victim, verb)
44
+ path = "/kiosk/#{verb}"
45
+ { 'as a bearer token' => client.wire.get(path, {}, 'Authorization' => "Bearer #{victim.token}"),
46
+ "with the thief's own key" => client.query(victim.with(key: OpenSSL::PKey.generate_key('ED25519')), name: verb) }
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -31,7 +31,7 @@ module Kiosk
31
31
  agent_id: principal.agent_id,
32
32
  user_id: principal.user_id,
33
33
  token: tamper_token(principal.token),
34
- rsa_key: principal.rsa_key
34
+ key: principal.key
35
35
  )
36
36
  end
37
37
  end
@@ -3,13 +3,13 @@
3
3
  module Kiosk
4
4
  module Redteam
5
5
  module Scenarios
6
- # A consistent mandate pair in a currency the operator does not price in
7
- # must be refused by the operator at capture.
8
- class WrongCurrencyCart < Scenario
6
+ # A payment mandate in a currency other than the checkout's, with the
7
+ # same amount, must be refused before any capture.
8
+ class WrongCurrencyPayment < Scenario
9
9
  ALTERNATIVES = %w[usd eur gbp jpy].freeze
10
10
 
11
11
  def initialize
12
- super(name: 'WrongCurrencyCart')
12
+ super(name: 'WrongCurrencyPayment')
13
13
  end
14
14
 
15
15
  def call(client, profile)
@@ -25,12 +25,12 @@ module Kiosk
25
25
  def attack(client, profile, native)
26
26
  foreign = ALTERNATIVES.find { |c| c != native }
27
27
  a = client.register!
28
- mandates = profile.pay_for.call(client, a, profile.create_owned.call(client, a))
29
- resp = client.pay(a, intent: mandates[:intent].merge(currency: foreign),
30
- cart: mandates[:cart].merge(currency: foreign))
31
- # A 401 would mean the cart never reached the operator's capture check.
28
+ checkout_jwt = profile.pay_for.call(client, a, profile.create_owned.call(client, a))
29
+ amount = JWT.decode(checkout_jwt, nil, false).first['total_amount_cents']
30
+ resp = client.pay_raw(a, **mandates_with_payment(a, checkout_jwt, payment_amount: { amount:, currency: foreign }))
31
+ # A 401 would mean the payment never reached the mandate check.
32
32
  verdict_from(resp, expect: 403,
33
- detail: "a #{foreign} cart settled at a #{native.upcase} operator " \
33
+ detail: "a #{foreign} payment of a #{native.upcase} checkout settled " \
34
34
  "(HTTP #{resp.status})")
35
35
  end
36
36
  end
@@ -20,8 +20,30 @@ module Kiosk
20
20
 
21
21
  # Pays for +owned_ref+ as +payer+ and answers the pay response.
22
22
  def pay_for_owned(client, payer, profile, owned_ref)
23
- mandates = profile.pay_for.call(client, payer, owned_ref)
24
- client.pay(payer, intent: mandates[:intent], cart: mandates[:cart])
23
+ client.pay(payer, profile.pay_for.call(client, payer, owned_ref))
24
+ end
25
+
26
+ # The claims of +checkout_jwt+ with +changes+, signed again by a key the operator never held.
27
+ def tampered_checkout(checkout_jwt, **changes)
28
+ claims, header = JWT.decode(checkout_jwt, nil, false)
29
+ JWT.encode(claims.merge(changes.transform_keys(&:to_s)), OpenSSL::PKey.generate_key('ED25519'), 'EdDSA',
30
+ header.slice('kid', 'typ'))
31
+ end
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
+
42
+ # The two mandates for +checkout_jwt+, with the payment mandate's fields changed and signed again.
43
+ def mandates_with_payment(principal, checkout_jwt, **changes)
44
+ mandates = Kiosk::TestHelpers::Mandate.pay(principal.key, checkout_jwt)
45
+ payment = Kiosk::TestHelpers::Mandate.content(mandates[:payment]).merge(changes.transform_keys(&:to_s))
46
+ mandates.merge(payment: Kiosk::TestHelpers::Mandate.sign(principal.key, payment))
25
47
  end
26
48
 
27
49
  # Pays for +owned_ref+ before a gated action. Answers a setup-failure verdict or nil.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kiosk
4
4
  module Redteam
5
- VERSION = '0.5.20'
5
+ VERSION = '0.6.28'
6
6
  end
7
7
  end
data/lib/kiosk/redteam.rb CHANGED
@@ -14,6 +14,7 @@ require 'kiosk/redteam/scenarios/forged_user_id'
14
14
  require 'kiosk/redteam/scenarios/mandate_principal_swap'
15
15
  require 'kiosk/redteam/scenarios/mandate_replay'
16
16
  require 'kiosk/redteam/scenarios/token_tampering'
17
+ require 'kiosk/redteam/scenarios/stolen_token'
17
18
  require 'kiosk/redteam/scenarios/registration_without_pow'
18
19
  require 'kiosk/redteam/scenarios/privilege_self_selection'
19
20
  require 'kiosk/redteam/scenarios/device_grant_role_self_selection'
@@ -23,7 +24,8 @@ require 'kiosk/redteam/scenarios/expired_kyc'
23
24
  require 'kiosk/redteam/scenarios/forged_kyc'
24
25
  require 'kiosk/redteam/scenarios/spent_resource_reuse'
25
26
  require 'kiosk/redteam/scenarios/pay_for_other_use_self'
26
- require 'kiosk/redteam/scenarios/wrong_currency_cart'
27
+ require 'kiosk/redteam/scenarios/wrong_currency_payment'
28
+ require 'kiosk/redteam/scenarios/call_toll'
27
29
 
28
30
  module Kiosk
29
31
  # Adversarial regression harness: drives hostile HTTP scenarios against a
@@ -36,8 +38,8 @@ module Kiosk
36
38
  PAYMENT_REQUIRED_CODES = {
37
39
  'pow_required' =>
38
40
  'a toll was DEMANDED, not a refusal — the request was deferred until a proof is ' \
39
- 'supplied. This harness PAYS that toll on every verb, so seeing this code here ' \
40
- '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 ' \
41
43
  'solve); either way the attack itself was never evaluated',
42
44
  'payment_setup_required' =>
43
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.5.20
4
+ version: 0.6.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Pirozhkov
@@ -29,25 +29,26 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.5.0
32
+ version: 0.6.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.5.0
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
@@ -76,9 +78,10 @@ files:
76
78
  - lib/kiosk/redteam/scenarios/privilege_self_selection.rb
77
79
  - lib/kiosk/redteam/scenarios/registration_without_pow.rb
78
80
  - lib/kiosk/redteam/scenarios/spent_resource_reuse.rb
81
+ - lib/kiosk/redteam/scenarios/stolen_token.rb
79
82
  - lib/kiosk/redteam/scenarios/token_tampering.rb
80
83
  - lib/kiosk/redteam/scenarios/unpaid_gated_action.rb
81
- - lib/kiosk/redteam/scenarios/wrong_currency_cart.rb
84
+ - lib/kiosk/redteam/scenarios/wrong_currency_payment.rb
82
85
  - lib/kiosk/redteam/staging.rb
83
86
  - lib/kiosk/redteam/token_claims.rb
84
87
  - lib/kiosk/redteam/verdict.rb
@@ -109,5 +112,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
112
  requirements: []
110
113
  rubygems_version: 4.0.3
111
114
  specification_version: 4
112
- summary: Adversarial regression harness for Kiosk providers
115
+ summary: Adversarial regression harness for Kiosk operators
113
116
  test_files: []