@radicaltools/cli 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +121 -16
  2. package/dist/hub-catalogue/concern/concern-api-collections.radical +1136 -0
  3. package/dist/hub-catalogue/concern/concern-api-errors.radical +1180 -0
  4. package/dist/hub-catalogue/concern/concern-api-evolution.radical +449 -210
  5. package/dist/hub-catalogue/concern/concern-api-idempotency.radical +1218 -0
  6. package/dist/hub-catalogue/concern/concern-api-resource-design.radical +1102 -0
  7. package/dist/hub-catalogue/concern/concern-api-style-guide.radical +1210 -0
  8. package/dist/hub-catalogue/concern/concern-architecture-style.radical +287 -131
  9. package/dist/hub-catalogue/concern/concern-audit-trail.radical +1096 -0
  10. package/dist/hub-catalogue/concern/concern-authentication.radical +247 -37
  11. package/dist/hub-catalogue/concern/concern-authorization.radical +311 -89
  12. package/dist/hub-catalogue/concern/concern-availability.radical +287 -63
  13. package/dist/hub-catalogue/concern/concern-backend-stack.radical +300 -381
  14. package/dist/hub-catalogue/concern/concern-backup-recovery.radical +385 -129
  15. package/dist/hub-catalogue/concern/concern-caching.radical +1294 -0
  16. package/dist/hub-catalogue/concern/concern-capacity.radical +194 -81
  17. package/dist/hub-catalogue/concern/concern-code-documentation.radical +1397 -0
  18. package/dist/hub-catalogue/concern/concern-code-quality-gate.radical +1409 -0
  19. package/dist/hub-catalogue/concern/concern-code-review-branching.radical +1416 -0
  20. package/dist/hub-catalogue/concern/concern-code-style.radical +1058 -0
  21. package/dist/hub-catalogue/concern/concern-communication-style.radical +473 -167
  22. package/dist/hub-catalogue/concern/concern-data-classification.radical +970 -0
  23. package/dist/hub-catalogue/concern/concern-data-consistency.radical +339 -308
  24. package/dist/hub-catalogue/concern/concern-data-store.radical +480 -158
  25. package/dist/hub-catalogue/concern/concern-decomposition.radical +260 -85
  26. package/dist/hub-catalogue/concern/concern-definition-of-done.radical +1214 -0
  27. package/dist/hub-catalogue/concern/concern-delivery-metrics.radical +966 -0
  28. package/dist/hub-catalogue/concern/concern-dependency-hygiene.radical +1345 -0
  29. package/dist/hub-catalogue/concern/concern-deployment.radical +343 -92
  30. package/dist/hub-catalogue/concern/concern-encryption.radical +339 -76
  31. package/dist/hub-catalogue/concern/concern-error-handling-logging.radical +1197 -0
  32. package/dist/hub-catalogue/concern/concern-eu-dora.radical +1321 -0
  33. package/dist/hub-catalogue/concern/concern-frontend-stack.radical +467 -160
  34. package/dist/hub-catalogue/concern/concern-incident-management.radical +1204 -0
  35. package/dist/hub-catalogue/concern/concern-infrastructure.radical +1300 -268
  36. package/dist/hub-catalogue/concern/concern-integration-resilience.radical +88 -51
  37. package/dist/hub-catalogue/concern/concern-messaging.radical +173 -140
  38. package/dist/hub-catalogue/concern/concern-module-boundaries.radical +162 -159
  39. package/dist/hub-catalogue/concern/concern-observability.radical +224 -275
  40. package/dist/hub-catalogue/concern/concern-operational-readiness.radical +1249 -0
  41. package/dist/hub-catalogue/concern/concern-personal-data.radical +637 -122
  42. package/dist/hub-catalogue/concern/concern-quality-priorities.radical +1091 -0
  43. package/dist/hub-catalogue/concern/concern-rate-limiting.radical +433 -141
  44. package/dist/hub-catalogue/concern/concern-release-versioning.radical +1358 -0
  45. package/dist/hub-catalogue/concern/concern-retention.radical +1399 -0
  46. package/dist/hub-catalogue/concern/concern-secrets.radical +332 -74
  47. package/dist/hub-catalogue/concern/concern-secure-coding.radical +1379 -0
  48. package/dist/hub-catalogue/concern/concern-secure-development.radical +1245 -0
  49. package/dist/hub-catalogue/concern/concern-security-detection.radical +1153 -0
  50. package/dist/hub-catalogue/concern/concern-supply-chain.radical +257 -183
  51. package/dist/hub-catalogue/concern/concern-technical-debt.radical +1450 -0
  52. package/dist/hub-catalogue/concern/concern-technology-lifecycle.radical +1145 -0
  53. package/dist/hub-catalogue/concern/concern-tenant-isolation.radical +271 -137
  54. package/dist/hub-catalogue/concern/concern-test-strategy.radical +243 -224
  55. package/dist/hub-catalogue/concern/concern-threat-modelling.radical +1143 -0
  56. package/dist/index.js +3680 -2074
  57. package/package.json +1 -1
@@ -3,7 +3,7 @@
3
3
  "id": "concern-rate-limiting",
4
4
  "category": "concern",
5
5
  "name": "Rate limiting and abuse",
6
- "description": "Entry points from outside: how much one caller may ask, how it is counted and where, how oversized and automated requests are stopped, and who can reach it at all.",
6
+ "description": "Entry points from outside: how much one caller may ask, how it is counted and where, and how oversized and automated requests are stopped. Whether an element is reachable from outside at all is not decided here (network segmentation is a pack of its own).",
7
7
  "tags": [
8
8
  "security",
9
9
  "rate-limiting",
@@ -25,6 +25,10 @@
25
25
  "title": "OWASP API Security Top 10 2023, API4:2023 Unrestricted Resource Consumption",
26
26
  "url": "https://owasp.org/API-Security/editions/2023/en/0xa4-unrestricted-resource-consumption/"
27
27
  },
28
+ {
29
+ "title": "OWASP API Security Top 10 2023, API6:2023 Unrestricted Access to Sensitive Business Flows",
30
+ "url": "https://owasp.org/API-Security/editions/2023/en/0xa6-unrestricted-access-to-sensitive-business-flows/"
31
+ },
28
32
  {
29
33
  "title": "RFC 6585, Additional HTTP Status Codes (4. 429 Too Many Requests)",
30
34
  "url": "https://www.rfc-editor.org/rfc/rfc6585"
@@ -51,7 +55,7 @@
51
55
  "key": "EXPOSURE",
52
56
  "title": "Exposure",
53
57
  "label": "Who can reach it?",
54
- "hint": "Anything on the internet is probed and scraped within hours of going live; what is not reachable cannot be flooded.",
58
+ "hint": "Anything on the internet is probed and scraped within hours of going live; a partner API has known callers and agreed limits.",
55
59
  "defaultValue": "internet",
56
60
  "options": [
57
61
  {
@@ -62,12 +66,7 @@
62
66
  {
63
67
  "value": "partners",
64
68
  "label": "known partners and our signed-in users",
65
- "description": "Every request carries a partner key or a user's credential, checked at the edge. Pick it for B2B APIs and back offices; limits can be agreed per partner."
66
- },
67
- {
68
- "value": "internal",
69
- "label": "only our own network",
70
- "description": "No public address; only our own systems call it. Pick it when the model shows callers only from inside; limits still stop a runaway internal caller."
69
+ "description": "Every request carries a partner key or a user's credential, checked at the edge, so callers are counted by account or API key, not by address. Pick it for B2B APIs and back offices; limits can be agreed per partner."
71
70
  }
72
71
  ]
73
72
  },
@@ -91,7 +90,7 @@
91
90
  {
92
91
  "value": "ip",
93
92
  "label": "its source address",
94
- "description": "IPv4 per address, IPv6 per /64. Pick it only when callers are anonymous; offices and mobile carriers share addresses, so allow-list the known ones."
93
+ "description": "IPv4 per address, IPv6 per /64. Pick it only when callers are anonymous; offices and mobile carriers share addresses, so allow-list the known ones. Not with known partners, whose every request carries a key to count by."
95
94
  }
96
95
  ]
97
96
  },
@@ -163,7 +162,7 @@
163
162
  {
164
163
  "value": "none",
165
164
  "label": "costly operations only for identified callers",
166
- "description": "No bot product; costly operations sit behind sign-in or a partner key. Pick it for partner and internal APIs, where every caller is known."
165
+ "description": "No bot product; costly operations sit behind sign-in or a partner key. Pick it for partner APIs and back offices, where every caller is known."
167
166
  }
168
167
  ]
169
168
  },
@@ -347,7 +346,7 @@
347
346
  "y": 1170,
348
347
  "ears_type": "state-driven",
349
348
  "precondition": "the element runs on more than one instance",
350
- "action": "keep the counters in one shared store, so that the element as a whole accepts no more than {{LIMIT_PER_MIN}} requests a minute from one caller, within 10 %, and fall back to a per-instance limit rather than none when the store is unreachable",
349
+ "action": "keep the counters in one shared store, so that the element as a whole accepts no more from one caller than one instance would, within 10 %, and fall back to a per-instance limit rather than none when the store is unreachable",
351
350
  "rationale": "A limit counted per instance multiplies with every instance added; failing open would turn a store outage into an open door (OWASP Denial of Service Cheat Sheet).",
352
351
  "hubWhen": {
353
352
  "WHERE": [
@@ -395,7 +394,7 @@
395
394
  "y": 1560,
396
395
  "ears_type": "ubiquitous",
397
396
  "action": "offer {{COSTLY_OPS}} only to callers with a valid account or partner key, so that each can be counted and blocked by who it is",
398
- "rationale": "Without bot protection, the only defence for a costly operation is that nobody anonymous can reach it (OWASP API6:2023 Unrestricted Access to Sensitive Business Flows).",
397
+ "rationale": "Without bot protection, the only defence for a costly operation is that nobody anonymous can reach it (OWASP API6:2023).",
399
398
  "hubWhen": {
400
399
  "BOTS": [
401
400
  "none"
@@ -433,21 +432,6 @@
433
432
  ]
434
433
  }
435
434
  },
436
- {
437
- "id": "req-internal",
438
- "type": "requirement",
439
- "label": "Reachable only inside",
440
- "x": 260,
441
- "y": 1950,
442
- "ears_type": "ubiquitous",
443
- "action": "accept connections only from our own network, with no public address and no route from the internet",
444
- "rationale": "Not reachable is the strongest limit; the decision records it so that exposing the element later is a decision too.",
445
- "hubWhen": {
446
- "EXPOSURE": [
447
- "internal"
448
- ]
449
- }
450
- },
451
435
  {
452
436
  "id": "sc-limit",
453
437
  "type": "scenario",
@@ -455,8 +439,8 @@
455
439
  "x": 520,
456
440
  "y": 0,
457
441
  "given": "one caller and ten others at normal load",
458
- "when": "the one sends {{LIMIT_PER_MIN}} requests and then 100 more within a minute",
459
- "then": "the extra requests get 429 with Retry-After, and the others' 95th percentile stays within 10 % of normal"
442
+ "when": "the one sends ten times {{LIMIT_PER_MIN}} requests a minute for three minutes",
443
+ "then": "at least 99 % of its excess gets 429 with Retry-After, and the others' 95th percentile stays within 10 % of normal"
460
444
  },
461
445
  {
462
446
  "id": "sc-size",
@@ -464,9 +448,9 @@
464
448
  "label": "Large body refused",
465
449
  "x": 520,
466
450
  "y": 130,
467
- "given": "an operation that accepts {{MAX_BODY_KB}} KB at most",
468
- "when": "a 100 MB body is sent",
469
- "then": "it is refused with 413 and the element's memory does not grow by more than the limit"
451
+ "given": "every write operation of the router",
452
+ "when": "a body of 100 times {{MAX_BODY_KB}} KB is sent to each",
453
+ "then": "each is refused with 413"
470
454
  },
471
455
  {
472
456
  "id": "sc-pages",
@@ -474,9 +458,9 @@
474
458
  "label": "Page size capped",
475
459
  "x": 520,
476
460
  "y": 260,
477
- "given": "a list of 10 000 items",
478
- "when": "a caller asks for a page of 10 000",
479
- "then": "the request is refused with 400, and a request without a page size gets at most {{MAX_PAGE_ITEMS}} items"
461
+ "given": "every paginated operation of the router",
462
+ "when": "a caller asks each for a page of 10 000, and then for a page without a size",
463
+ "then": "the first is refused with 400, and the second holds at most {{MAX_PAGE_ITEMS}} items"
480
464
  },
481
465
  {
482
466
  "id": "sc-token-bucket",
@@ -485,8 +469,8 @@
485
469
  "x": 520,
486
470
  "y": 390,
487
471
  "given": "a caller that has sent nothing for a minute",
488
- "when": "it sends {{BURST}} requests at once and then keeps sending at twice its rate",
489
- "then": "the burst is accepted, and afterwards requests above {{LIMIT_PER_MIN}} a minute get 429",
472
+ "when": "it sends {{BURST}} requests at once and then twice its rate for a minute",
473
+ "then": "the burst is accepted, and of the minute's requests no more than {{LIMIT_PER_MIN}} plus 10 % are, the rest getting 429",
490
474
  "hubWhen": {
491
475
  "ALGORITHM": [
492
476
  "token-bucket"
@@ -516,7 +500,7 @@
516
500
  "y": 650,
517
501
  "given": "a caller that has made 10 requests this minute",
518
502
  "when": "it makes another",
519
- "then": "the response says the limit is {{LIMIT_PER_MIN}}, how many remain and when the window resets",
503
+ "then": "the response says the limit is {{LIMIT_PER_MIN}}, that {{LIMIT_PER_MIN}} minus 11 remain, and when the window resets",
520
504
  "hubWhen": {
521
505
  "ALGORITHM": [
522
506
  "fixed-window"
@@ -544,9 +528,9 @@
544
528
  "label": "Invalid key ignored",
545
529
  "x": 520,
546
530
  "y": 910,
547
- "given": "a partner's key with its limit almost used",
548
- "when": "another source sends 1 000 requests naming that key with a wrong secret",
549
- "then": "they are refused with 401, the partner's remaining limit does not change, and the source is limited after {{ANON_LIMIT_PER_MIN}}",
531
+ "given": "a partner's key with one request of its limit left",
532
+ "when": "another source sends {{ANON_LIMIT_PER_MIN}} and 10 more requests naming that key with a wrong secret, and then the partner sends its request",
533
+ "then": "the forged requests are refused with 401, then 429 after {{ANON_LIMIT_PER_MIN}}, and the partner's request is accepted",
550
534
  "hubWhen": {
551
535
  "KEY": [
552
536
  "apikey"
@@ -560,8 +544,8 @@
560
544
  "x": 520,
561
545
  "y": 1040,
562
546
  "given": "a caller over its limit",
563
- "when": "it sends requests with a different X-Forwarded-For value each time, and then from other addresses in its /64",
564
- "then": "they are all counted against the same caller and refused",
547
+ "when": "it sends a request with a forged X-Forwarded-For value, and then from another address in its /64",
548
+ "then": "both are counted against the same caller and refused",
565
549
  "hubWhen": {
566
550
  "KEY": [
567
551
  "ip"
@@ -571,12 +555,12 @@
571
555
  {
572
556
  "id": "sc-shared-counters",
573
557
  "type": "scenario",
574
- "label": "Limit holds on four instances",
558
+ "label": "Limit holds on two instances",
575
559
  "x": 520,
576
560
  "y": 1170,
577
- "given": "four instances behind a load balancer",
578
- "when": "one caller sends twice {{LIMIT_PER_MIN}} requests in a minute spread over all four",
579
- "then": "no more than {{LIMIT_PER_MIN}} plus 10 % are accepted in total",
561
+ "given": "two instances sharing a store",
562
+ "when": "one caller sends twice {{LIMIT_PER_MIN}} requests in a minute spread over both, and again with the store stopped",
563
+ "then": "no more than one instance alone accepts plus 10 % are accepted, and with the store stopped the caller is still refused past one instance's limit",
580
564
  "hubWhen": {
581
565
  "WHERE": [
582
566
  "app"
@@ -590,8 +574,8 @@
590
574
  "x": 520,
591
575
  "y": 1300,
592
576
  "given": "one source",
593
- "when": "it calls the first of {{COSTLY_OPS}} 11 times in 10 minutes",
594
- "then": "the 11th attempt is answered with a challenge, and a new source's first attempt is not",
577
+ "when": "its first attempt at one of {{COSTLY_OPS}} is made, and then 10 more in 10 minutes",
578
+ "then": "the first attempt sees no challenge and the 11th is answered with one",
595
579
  "hubWhen": {
596
580
  "BOTS": [
597
581
  "challenge"
@@ -619,9 +603,9 @@
619
603
  "label": "Anonymous costly call refused",
620
604
  "x": 520,
621
605
  "y": 1560,
622
- "given": "a caller without a credential",
623
- "when": "it calls the first of {{COSTLY_OPS}}",
624
- "then": "it is refused with 401",
606
+ "given": "every route the router marks costly",
607
+ "when": "each is called without a credential",
608
+ "then": "each is refused with 401",
625
609
  "hubWhen": {
626
610
  "BOTS": [
627
611
  "none"
@@ -635,8 +619,8 @@
635
619
  "x": 520,
636
620
  "y": 1690,
637
621
  "given": "the element behind its edge",
638
- "when": "its origin address is called directly from the internet",
639
- "then": "the connection is refused",
622
+ "when": "each of its origin addresses is called directly from the internet",
623
+ "then": "every connection is refused",
640
624
  "hubWhen": {
641
625
  "EXPOSURE": [
642
626
  "internet"
@@ -658,21 +642,6 @@
658
642
  ]
659
643
  }
660
644
  },
661
- {
662
- "id": "sc-internal",
663
- "type": "scenario",
664
- "label": "Closed from outside",
665
- "x": 520,
666
- "y": 1950,
667
- "given": "the element deployed",
668
- "when": "its addresses and ports are scanned from outside the network",
669
- "then": "none answers",
670
- "hubWhen": {
671
- "EXPOSURE": [
672
- "internal"
673
- ]
674
- }
675
- },
676
645
  {
677
646
  "id": "adr-gateway",
678
647
  "type": "adr",
@@ -682,7 +651,7 @@
682
651
  "concern": "rate-limiting",
683
652
  "status": "accepted",
684
653
  "date": "",
685
- "context": "This element takes requests from people or other systems outside it. The forces: one caller, by mistake (a retry loop, a bad deploy) or on purpose, can use up capacity meant for all; bots guess passwords, create accounts, scrape data and run up the bill of costly operations (messages sent, searches, third-party calls); a request or a page can be large enough to exhaust memory before it is refused; limits that are too tight, or keyed on an address shared by an office or a mobile carrier, lock out real users; and a limit counted on one instance of many is no limit at all.",
654
+ "context": "This element takes requests from people or other systems outside it. The forces: one caller, by mistake (a retry loop, a bad deploy) or on purpose, can use up capacity meant for all; bots guess passwords, create accounts, scrape data and run up the bill of costly operations (messages sent, searches, third-party calls); a request or a page can be large enough to exhaust memory before it is refused; limits that are too tight, or keyed on an address shared by an office or a mobile carrier, lock out real users; and a limit counted on one instance of many is no limit at all. Snippets assume the router's table in src/app (routes with method, path, an example and the flags paginated and costly), black-box tests against $BASE_URL of a staging deployment with credentials in TOKEN_* variables, the gateway's decK file under gateway/, and Terraform plans read with terraform show -json.",
686
655
  "decision": "Requests pass an API gateway that limits each caller, counted by {{KEY}}, to {{LIMIT_PER_MIN}} requests a minute using {{ALGORITHM}}, refuses bodies over {{MAX_BODY_KB}} KB, and answers the excess with 429 and Retry-After; counters are shared by all gateway nodes. The element is reachable by {{EXPOSURE}}; bots on costly operations: {{BOTS}}. Choosing the gateway: the one already in the path. Match the algorithm: AWS API Gateway (usage plans) and Envoy's local rate limit are token buckets, NGINX limit_req a leaky bucket with a burst, Kong's open-source rate-limiting plugin fixed windows (sliding windows in Kong Enterprise and Azure API Management's rate-limit-by-key). Judge by whether it can key on the validated token's subject or the API key, share counters across nodes (Redis, a global rate limit service) and set limits per caller.",
687
656
  "consequences": "• One place for every route's limits, applied before the element spends anything.\n• The gateway must see the caller's identity: it validates tokens or keys itself.\n• Limits that depend on business data (plan, tenant) need the gateway to read it, or a second limit in the element.\n• Limits need tuning from real traffic; start in log-only mode for a week.",
688
657
  "alternatives": "1. At the edge WAF: earlier and cheaper, but approximate and keyed mostly on addresses.\n2. In the application: knows the business, but a request has already reached the element.\n3. Rely on autoscaling: pays for abuse instead of stopping it.",
@@ -701,7 +670,7 @@
701
670
  "concern": "rate-limiting",
702
671
  "status": "accepted",
703
672
  "date": "",
704
- "context": "This element takes requests from people or other systems outside it. The forces: one caller, by mistake (a retry loop, a bad deploy) or on purpose, can use up capacity meant for all; bots guess passwords, create accounts, scrape data and run up the bill of costly operations (messages sent, searches, third-party calls); a request or a page can be large enough to exhaust memory before it is refused; limits that are too tight, or keyed on an address shared by an office or a mobile carrier, lock out real users; and a limit counted on one instance of many is no limit at all.",
673
+ "context": "This element takes requests from people or other systems outside it. The forces: one caller, by mistake (a retry loop, a bad deploy) or on purpose, can use up capacity meant for all; bots guess passwords, create accounts, scrape data and run up the bill of costly operations (messages sent, searches, third-party calls); a request or a page can be large enough to exhaust memory before it is refused; limits that are too tight, or keyed on an address shared by an office or a mobile carrier, lock out real users; and a limit counted on one instance of many is no limit at all. Snippets assume the router's table in src/app (routes with method, path, an example and the flags paginated and costly), black-box tests against $BASE_URL of a staging deployment with credentials in TOKEN_* variables, the gateway's decK file under gateway/, and Terraform plans read with terraform show -json.",
705
674
  "decision": "Rate rules at the edge WAF or CDN limit each caller, counted by {{KEY}}, to {{LIMIT_PER_MIN}} requests a minute using {{ALGORITHM}} as closely as the product allows, refuse bodies over {{MAX_BODY_KB}} KB, and answer the excess with 429 and Retry-After; the origin accepts traffic only from the edge. The element is reachable by {{EXPOSURE}}; bots on costly operations: {{BOTS}}. Choosing the product: Cloudflare WAF rate limiting rules, AWS WAF rate-based rules (with CloudFront or an ALB), Azure Front Door WAF rate limit rules or Akamai; judge by the keys it can count on (address, header, cookie, JWT claim), the shortest window it supports, how fast it starts blocking, and its price per million requests.",
706
675
  "consequences": "• Floods are refused before they reach our network or our bill.\n• Counts are approximate and lag by seconds: the limit is a ceiling, not an exact figure.\n• Keys are mostly addresses and headers; per-account limits need the edge to read a token claim or a second limit further in.\n• The edge provider is on every request's path.",
707
676
  "alternatives": "1. At the API gateway: exact, keyed on the validated caller, but after traffic entered our network.\n2. In the application: knows the business, latest of all.",
@@ -720,8 +689,8 @@
720
689
  "concern": "rate-limiting",
721
690
  "status": "accepted",
722
691
  "date": "",
723
- "context": "This element takes requests from people or other systems outside it. The forces: one caller, by mistake (a retry loop, a bad deploy) or on purpose, can use up capacity meant for all; bots guess passwords, create accounts, scrape data and run up the bill of costly operations (messages sent, searches, third-party calls); a request or a page can be large enough to exhaust memory before it is refused; limits that are too tight, or keyed on an address shared by an office or a mobile carrier, lock out real users; and a limit counted on one instance of many is no limit at all.",
724
- "decision": "The element limits each caller, counted by {{KEY}}, to {{LIMIT_PER_MIN}} requests a minute using {{ALGORITHM}}, in middleware that runs before any handler, with counters in a shared Redis; bodies over {{MAX_BODY_KB}} KB are refused by the server's own limit. The excess gets 429 and Retry-After. The element is reachable by {{EXPOSURE}}; bots on costly operations: {{BOTS}}. Choosing the library: the framework's own (ASP.NET Core rate limiting, Spring Cloud Gateway RequestRateLimiter) or a maintained one with a Redis store (Bucket4j for Java, express-rate-limit with rate-limit-redis for Node, django-ratelimit for Python); judge by its algorithms, atomic shared counters and per-route configuration.",
692
+ "context": "This element takes requests from people or other systems outside it. The forces: one caller, by mistake (a retry loop, a bad deploy) or on purpose, can use up capacity meant for all; bots guess passwords, create accounts, scrape data and run up the bill of costly operations (messages sent, searches, third-party calls); a request or a page can be large enough to exhaust memory before it is refused; limits that are too tight, or keyed on an address shared by an office or a mobile carrier, lock out real users; and a limit counted on one instance of many is no limit at all. Snippets assume the router's table in src/app (routes with method, path, an example and the flags paginated and costly), black-box tests against $BASE_URL of a staging deployment with credentials in TOKEN_* variables, the gateway's decK file under gateway/, and Terraform plans read with terraform show -json.",
693
+ "decision": "The element limits each caller, counted by {{KEY}}, to {{LIMIT_PER_MIN}} requests a minute using {{ALGORITHM}}, in middleware that runs before any handler, with counters in a shared Redis; bodies over {{MAX_BODY_KB}} KB are refused by the server's own limit. The excess gets 429 and Retry-After. The element is reachable by {{EXPOSURE}}; bots on costly operations: {{BOTS}}. Choosing the library: the framework's own (ASP.NET Core rate limiting) or a maintained one with a Redis store (Bucket4j with its Spring Boot starter for Java, express-rate-limit with rate-limit-redis for Node, django-ratelimit for Python); judge by its algorithms, atomic shared counters and per-route configuration.",
725
694
  "consequences": "• Limits can follow business data: plan, tenant, operation cost.\n• A request has already reached the element when it is refused: floods still need protection in front.\n• Redis is on the request path; when it is unreachable, the per-instance fallback limits less exactly.",
726
695
  "alternatives": "1. At the API gateway: before the element, but blind to business data.\n2. At the edge WAF: earliest and cheapest, approximate.",
727
696
  "hubWhen": {
@@ -730,34 +699,18 @@
730
699
  ]
731
700
  }
732
701
  },
733
- {
734
- "id": "adr-internal",
735
- "type": "adr",
736
- "label": "Not reachable from outside",
737
- "x": 780,
738
- "y": 390,
739
- "concern": "rate-limiting",
740
- "status": "accepted",
741
- "date": "",
742
- "context": "This element takes requests from people or other systems outside it. The forces: one caller, by mistake (a retry loop, a bad deploy) or on purpose, can use up capacity meant for all; bots guess passwords, create accounts, scrape data and run up the bill of costly operations (messages sent, searches, third-party calls); a request or a page can be large enough to exhaust memory before it is refused; limits that are too tight, or keyed on an address shared by an office or a mobile carrier, lock out real users; and a limit counted on one instance of many is no limit at all.",
743
- "decision": "The element accepts connections only from our own network: no public address, security groups or network policies admit only the internal callers listed in the model. Exposing it later supersedes this decision and brings the edge protection the internet needs.",
744
- "consequences": "• Nothing outside can flood or scrape it.\n• Internal callers are still limited, against retry storms and runaway jobs.\n• Every new caller needs a network rule, which shows up in review.",
745
- "alternatives": "1. Public with limits: needed only if outside callers appear.\n2. Reachable through a VPN for partners: closer to the partners option than to this one.",
746
- "hubWhen": {
747
- "EXPOSURE": [
748
- "internal"
749
- ]
750
- }
751
- },
752
702
  {
753
703
  "id": "ff-noisy",
754
704
  "type": "fitness-fn",
755
705
  "label": "Noisy caller contained",
756
706
  "x": 1040,
757
707
  "y": 0,
758
- "category": "operational",
759
- "threshold": "With one caller at 10 times {{LIMIT_PER_MIN}} requests a minute, other callers' 95th percentile stays within 10 % of the baseline and at least 99 % of the flood's excess gets 429 with Retry-After",
760
- "description": "A load test in the staging environment runs normal traffic from several callers and a flood from one, and compares the others' response times with a baseline run without the flood.\n\nTool: Grafana k6\n\n```js\nimport http from 'k6/http'\nimport { check } from 'k6'\n\nconst LIMIT = {{LIMIT_PER_MIN}}\nconst BASELINE_P95 = Number(__ENV.BASELINE_P95_MS)\n\nexport const options = {\n scenarios: {\n normal: { executor: 'constant-arrival-rate', rate: 20, timeUnit: '1s', duration: '3m', preAllocatedVUs: 50, env: { KEY: 'normal' } },\n flood: { executor: 'constant-arrival-rate', rate: LIMIT * 10, timeUnit: '1m', duration: '3m', preAllocatedVUs: 200, env: { KEY: 'flood' } },\n },\n thresholds: {\n 'http_req_duration{scenario:normal}': [`p(95)<${BASELINE_P95 * 1.1}`],\n 'checks{scenario:flood}': ['rate>0.89'], // 90 % of the flood is excess\n },\n}\n\nexport default function () {\n const res = http.get(`${__ENV.BASE_URL}/orders`, { headers: { Authorization: `Bearer ${__ENV['TOKEN_' + __ENV.KEY]}` } })\n if (__ENV.KEY === 'flood') check(res, { 'limited with Retry-After': (r) => r.status === 429 && !!r.headers['Retry-After'] })\n}\n```"
708
+ "characteristic": "performance-efficiency",
709
+ "scope": "holistic",
710
+ "cadence": "triggered",
711
+ "trigger": "nightly",
712
+ "invocation": "automated",
713
+ "description": "A load test in the staging environment runs normal traffic from several callers and a flood from one, and compares the others' response times with a baseline run without the flood; 90 % of the flood is excess, so 99 % of the excess is 89 % of the flood.\n\nThreshold: With one caller at 10 times {{LIMIT_PER_MIN}} requests a minute, other callers' 95th percentile stays within 10 % of the baseline and at least 99 % of the flood's excess gets 429 with Retry-After\n\nTool: Grafana k6\n\n```js\nimport http from 'k6/http'\nimport { check } from 'k6'\n\nconst LIMIT = {{LIMIT_PER_MIN}}\nconst BASELINE_P95 = Number(__ENV.BASELINE_P95_MS)\n\nexport const options = {\n scenarios: {\n normal: { executor: 'constant-arrival-rate', rate: 20, timeUnit: '1s', duration: '3m', preAllocatedVUs: 50, env: { KEY: 'normal' } },\n flood: { executor: 'constant-arrival-rate', rate: LIMIT * 10, timeUnit: '1m', duration: '3m', preAllocatedVUs: 200, env: { KEY: 'flood' } },\n },\n thresholds: {\n 'http_req_duration{scenario:normal}': [`p(95)<${BASELINE_P95 * 1.1}`],\n 'checks{scenario:flood}': ['rate>0.89'],\n },\n}\n\nexport default function () {\n const res = http.get(`${__ENV.BASE_URL}/orders`, { headers: { Authorization: `Bearer ${__ENV['TOKEN_' + __ENV.KEY]}` } })\n if (__ENV.KEY === 'flood') check(res, { 'limited with Retry-After': (r) => r.status === 429 && !!r.headers['Retry-After'] })\n}\n```"
761
714
  },
762
715
  {
763
716
  "id": "ff-body",
@@ -765,19 +718,146 @@
765
718
  "label": "Oversized bodies refused",
766
719
  "x": 1040,
767
720
  "y": 130,
768
- "category": "structural",
769
- "threshold": "A body of 100 times {{MAX_BODY_KB}} KB is answered with 413 on 100 % of the element's write operations",
770
- "description": "A smoke test after each deployment sends an oversized body to each write operation and expects 413, which fails when a new route or a proxy change drops the size limit.\n\nTool: curl in the deployment pipeline\n\n```bash\nsize_kb=$(( {{MAX_BODY_KB}} * 100 ))\nfor route in $(cat write-routes.txt); do\n code=$(head -c \"${size_kb}K\" /dev/zero | curl -s -o /dev/null -w '%{http_code}' \\\n -X POST -H 'Content-Type: application/json' --data-binary @- \"$BASE_URL$route\")\n [ \"$code\" = 413 ] || { echo \"$route answered $code to an oversized body\"; exit 1; }\ndone\n```"
721
+ "characteristic": "security",
722
+ "scope": "atomic",
723
+ "cadence": "triggered",
724
+ "trigger": "pull-request",
725
+ "invocation": "automated",
726
+ "description": "A test lists the write operations from the router (not from a list kept by hand), sends an oversized body to each and expects 413, which fails when a new route or a proxy change drops the size limit.\n\nThreshold: A body of 100 times {{MAX_BODY_KB}} KB is answered with 413 on 100 % of the router's write operations\n\nTool: Vitest with supertest (or the test runner and HTTP client of your stack)\n\n```ts\nimport request from 'supertest'\nimport { app, routes } from '../src/app' // routes: the router's table\n\nconst oversized = Buffer.alloc({{MAX_BODY_KB}} * 100 * 1024, 'a')\n\ndescribe.each(routes.filter((r) => ['POST', 'PUT', 'PATCH'].includes(r.method)))('%s %s', (route) => {\n it('refuses an oversized body with 413', async () => {\n const res = await request(app)[route.method.toLowerCase()](route.example)\n .set('Content-Type', 'application/octet-stream').send(oversized)\n expect(res.status).toBe(413)\n })\n})\n```"
727
+ },
728
+ {
729
+ "id": "ff-pages",
730
+ "type": "fitness-fn",
731
+ "label": "Pages capped",
732
+ "x": 1040,
733
+ "y": 260,
734
+ "characteristic": "security",
735
+ "scope": "atomic",
736
+ "cadence": "triggered",
737
+ "trigger": "pull-request",
738
+ "invocation": "automated",
739
+ "description": "A test lists the paginated operations from the router (routes flagged paginated), asks each for an oversized page and for a default one, and checks the refusal and the count.\n\nThreshold: Every paginated operation refuses a page size of 10 000 with 400 and returns at most {{MAX_PAGE_ITEMS}} items without a size; 0 exceptions\n\nTool: Vitest with supertest (or the test runner and HTTP client of your stack)\n\n```ts\nimport request from 'supertest'\nimport { app, routes } from '../src/app' // routes flagged paginated name their page-size parameter\n\ndescribe.each(routes.filter((r) => r.paginated))('GET %s', (route) => {\n it('caps the page', async () => {\n await request(app).get(route.example).query({ [route.pageSizeParam]: 10_000 }).set(auth(user)).expect(400)\n const res = await request(app).get(route.example).set(auth(user)).expect(200)\n expect(res.body.items.length).toBeLessThanOrEqual({{MAX_PAGE_ITEMS}})\n })\n})\n```"
740
+ },
741
+ {
742
+ "id": "ff-bucket",
743
+ "type": "fitness-fn",
744
+ "label": "Bucket admits a burst, keeps the rate",
745
+ "x": 1040,
746
+ "y": 390,
747
+ "characteristic": "security",
748
+ "scope": "holistic",
749
+ "cadence": "triggered",
750
+ "trigger": "deploy",
751
+ "invocation": "automated",
752
+ "description": "A black-box test against the staging deployment lets the bucket fill, sends the burst in parallel, then sends at twice the rate for a minute and counts what was accepted.\n\nThreshold: After a minute idle, {{BURST}} requests at once are all accepted; of twice {{LIMIT_PER_MIN}} requests spread over the next minute, at most {{LIMIT_PER_MIN}} plus 10 % are accepted and the rest get 429\n\nTool: Vitest with fetch against $BASE_URL (or the test runner of your stack)\n\n```ts\nconst LIMIT = {{LIMIT_PER_MIN}}\nconst BURST = {{BURST}}\nconst call = () => fetch(`${process.env.BASE_URL}/orders`, { headers: { Authorization: `Bearer ${process.env.TOKEN_BUCKET}` } })\nconst sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))\n\nit('admits a burst, then holds the rate', async () => {\n await sleep(60_000) // a minute idle: the bucket is full\n const burst = await Promise.all(Array.from({ length: BURST }, call))\n expect(burst.map((r) => r.status)).toEqual(Array(BURST).fill(200))\n let accepted = 0\n for (let i = 0; i < LIMIT * 2; i++) { // twice the rate for one minute\n const res = await call()\n if (res.status === 200) accepted++\n else expect(res.status).toBe(429)\n await sleep(30_000 / LIMIT)\n }\n expect(accepted).toBeLessThanOrEqual(LIMIT * 1.1)\n}, 200_000)\n```",
753
+ "hubWhen": {
754
+ "ALGORITHM": [
755
+ "token-bucket"
756
+ ]
757
+ }
758
+ },
759
+ {
760
+ "id": "ff-sliding",
761
+ "type": "fitness-fn",
762
+ "label": "Window edges hold",
763
+ "x": 1040,
764
+ "y": 520,
765
+ "characteristic": "security",
766
+ "scope": "holistic",
767
+ "cadence": "triggered",
768
+ "trigger": "deploy",
769
+ "invocation": "automated",
770
+ "description": "A black-box test against the staging deployment waits for second 59, sends the limit at once, waits two seconds past the minute boundary and sends the limit again.\n\nThreshold: {{LIMIT_PER_MIN}} requests in the last second of a minute are accepted and {{LIMIT_PER_MIN}} in the first second of the next all get 429\n\nTool: Vitest with fetch against $BASE_URL (or the test runner of your stack)\n\n```ts\nconst LIMIT = {{LIMIT_PER_MIN}}\nconst call = () => fetch(`${process.env.BASE_URL}/orders`, { headers: { Authorization: `Bearer ${process.env.TOKEN_WINDOW}` } })\nconst sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))\nconst untilSecond = async (s: number) => { while (new Date().getSeconds() !== s) await sleep(100) }\n\nit('refuses a burst that straddles the minute boundary', async () => {\n await untilSecond(59)\n const first = await Promise.all(Array.from({ length: LIMIT }, call))\n await sleep(2_000)\n const second = await Promise.all(Array.from({ length: LIMIT }, call))\n expect(first.filter((r) => r.status === 200)).toHaveLength(LIMIT)\n expect(second.filter((r) => r.status === 429)).toHaveLength(LIMIT)\n}, 120_000)\n```",
771
+ "hubWhen": {
772
+ "ALGORITHM": [
773
+ "sliding-window"
774
+ ]
775
+ }
776
+ },
777
+ {
778
+ "id": "ff-fixed",
779
+ "type": "fitness-fn",
780
+ "label": "Quota headers present",
781
+ "x": 1040,
782
+ "y": 650,
783
+ "characteristic": "security",
784
+ "scope": "holistic",
785
+ "cadence": "triggered",
786
+ "trigger": "deploy",
787
+ "invocation": "automated",
788
+ "description": "A black-box test against the staging deployment makes eleven requests at the start of a minute and reads the RateLimit header fields of the last answer.\n\nThreshold: After 10 requests in a minute, the 11th answer carries the limit {{LIMIT_PER_MIN}}, {{LIMIT_PER_MIN}} minus 11 remaining and a reset of at most 60 seconds\n\nTool: Vitest with fetch against $BASE_URL (or the test runner of your stack)\n\n```ts\nconst LIMIT = {{LIMIT_PER_MIN}}\nconst call = () => fetch(`${process.env.BASE_URL}/orders`, { headers: { Authorization: `Bearer ${process.env.TOKEN_QUOTA}` } })\nconst sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))\n\nit('shows the quota with every answer', async () => {\n while (new Date().getSeconds() !== 0) await sleep(100) // the start of a calendar minute\n for (let i = 0; i < 10; i++) await call()\n const res = await call()\n // IETF draft-ietf-httpapi-ratelimit-headers up to -07; newer drafts fold the three into one RateLimit field\n expect(Number(res.headers.get('ratelimit-limit'))).toBe(LIMIT)\n expect(Number(res.headers.get('ratelimit-remaining'))).toBe(LIMIT - 11)\n expect(Number(res.headers.get('ratelimit-reset'))).toBeLessThanOrEqual(60)\n}, 120_000)\n```",
789
+ "hubWhen": {
790
+ "ALGORITHM": [
791
+ "fixed-window"
792
+ ]
793
+ }
794
+ },
795
+ {
796
+ "id": "ff-key-account",
797
+ "type": "fitness-fn",
798
+ "label": "Anonymous limit apart",
799
+ "x": 1040,
800
+ "y": 780,
801
+ "characteristic": "security",
802
+ "scope": "holistic",
803
+ "cadence": "triggered",
804
+ "trigger": "deploy",
805
+ "invocation": "automated",
806
+ "description": "A black-box test against the staging deployment floods a public route from one address without a credential, then calls with a user's token from the same address.\n\nThreshold: From one address without a credential, {{ANON_LIMIT_PER_MIN}} requests are accepted and the next 10 get 429; a signed-in user's request from the same address is accepted\n\nTool: Vitest with fetch against $BASE_URL (or the test runner of your stack)\n\n```ts\nconst ANON = {{ANON_LIMIT_PER_MIN}}\nconst anon = () => fetch(`${process.env.BASE_URL}/products`)\nconst user = () => fetch(`${process.env.BASE_URL}/products`, { headers: { Authorization: `Bearer ${process.env.TOKEN_USER}` } })\n\nit('limits anonymous addresses lower and apart from signed-in callers', async () => {\n const statuses: number[] = []\n for (let i = 0; i < ANON + 10; i++) statuses.push((await anon()).status)\n expect(statuses.slice(0, ANON)).toEqual(Array(ANON).fill(200))\n expect(statuses.slice(ANON)).toEqual(Array(10).fill(429))\n expect((await user()).status).toBe(200)\n}, 120_000)\n```",
807
+ "hubWhen": {
808
+ "KEY": [
809
+ "account"
810
+ ]
811
+ }
812
+ },
813
+ {
814
+ "id": "ff-key-apikey",
815
+ "type": "fitness-fn",
816
+ "label": "Invalid keys do not count",
817
+ "x": 1040,
818
+ "y": 910,
819
+ "characteristic": "security",
820
+ "scope": "holistic",
821
+ "cadence": "triggered",
822
+ "trigger": "deploy",
823
+ "invocation": "automated",
824
+ "description": "A black-box test against the staging deployment uses up a partner's limit but one, floods with a forged key from another address, and checks that the partner's last request still passes.\n\nThreshold: With one request of a partner's limit left, {{ANON_LIMIT_PER_MIN}} requests naming its key with a wrong secret get 401 and the next 10 get 429; the partner's request is then accepted\n\nTool: Vitest with fetch against $BASE_URL (or the test runner of your stack)\n\n```ts\nconst LIMIT = {{LIMIT_PER_MIN}}\nconst ANON = {{ANON_LIMIT_PER_MIN}}\nconst url = `${process.env.BASE_URL}/orders`\nconst partner = () => fetch(url, { headers: { 'X-Api-Key': process.env.PARTNER_KEY! } })\nconst forged = () => fetch(url, { headers: { 'X-Api-Key': `${process.env.PARTNER_KEY_ID}.wrong-secret` } })\n\nit('refuses invalid keys before counting, and limits them per address', async () => {\n for (let i = 0; i < LIMIT - 1; i++) expect((await partner()).status).toBe(200) // one request left\n const statuses: number[] = []\n for (let i = 0; i < ANON + 10; i++) statuses.push((await forged()).status)\n expect(statuses.slice(0, ANON)).toEqual(Array(ANON).fill(401))\n expect(statuses.slice(ANON)).toEqual(Array(10).fill(429))\n expect((await partner()).status).toBe(200) // the forged calls did not count\n}, 300_000)\n```",
825
+ "hubWhen": {
826
+ "KEY": [
827
+ "apikey"
828
+ ]
829
+ }
830
+ },
831
+ {
832
+ "id": "ff-key-ip",
833
+ "type": "fitness-fn",
834
+ "label": "Addresses counted fairly",
835
+ "x": 1040,
836
+ "y": 1040,
837
+ "characteristic": "security",
838
+ "scope": "holistic",
839
+ "cadence": "triggered",
840
+ "trigger": "deploy",
841
+ "invocation": "automated",
842
+ "description": "A black-box test against the staging deployment floods from the runner's address and then forges the header; a second test, from a runner on the trusted-proxy list, presents addresses as the proxy would and checks the /64 grouping.\n\nThreshold: A forged X-Forwarded-For from outside does not reset a caller's count; two addresses in one IPv6 /64 share one count; an address in another /64 has its own\n\nTool: Vitest with fetch against $BASE_URL and, for the proxy path, from a runner on the trusted-proxy list (or the test runner of your stack)\n\n```ts\nconst LIMIT = {{LIMIT_PER_MIN}}\nconst direct = (headers = {}) => fetch(`${process.env.BASE_URL}/products`, { headers })\nconst viaProxy = (ip: string) => fetch(`${process.env.INTERNAL_URL}/products`, { headers: { 'X-Forwarded-For': ip } }) // this runner is a trusted proxy in staging\n\nit('ignores a forged X-Forwarded-For from outside', async () => {\n for (let i = 0; i < LIMIT; i++) await direct()\n expect((await direct({ 'X-Forwarded-For': '203.0.113.9' })).status).toBe(429)\n}, 120_000)\n\nit('counts an IPv6 /64 as one caller', async () => {\n for (let i = 0; i < LIMIT; i++) await viaProxy('2001:db8:1:2::1')\n expect((await viaProxy('2001:db8:1:2::ffff')).status).toBe(429)\n expect((await viaProxy('2001:db8:1:3::1')).status).toBe(200)\n}, 120_000)\n```",
843
+ "hubWhen": {
844
+ "KEY": [
845
+ "ip"
846
+ ]
847
+ }
771
848
  },
772
849
  {
773
850
  "id": "ff-gateway",
774
851
  "type": "fitness-fn",
775
852
  "label": "Every route limited",
776
853
  "x": 1040,
777
- "y": 260,
778
- "category": "structural",
779
- "threshold": "0 gateway services without a rate-limiting plugin; 0 limits above {{LIMIT_PER_MIN}} a minute without an exception recorded",
780
- "description": "A Conftest policy over the gateway's declarative configuration (Kong decK file) fails the pull request when a service has no rate limit, or one higher than agreed.\n\nTool: Conftest (Open Policy Agent) over the Kong decK configuration\n\n```rego\npackage main\n\nimport rego.v1\n\nlimited(s) if { some p in s.plugins; p.name in {\"rate-limiting\", \"rate-limiting-advanced\"} }\nglobal if { some p in input.plugins; p.name in {\"rate-limiting\", \"rate-limiting-advanced\"} }\n\ndeny contains msg if {\n not global\n some s in input.services\n not limited(s)\n msg := sprintf(\"service %s has no rate limit\", [s.name])\n}\n\ndeny contains msg if {\n some s in input.services\n some p in s.plugins\n p.name == \"rate-limiting\"\n p.config.minute > {{LIMIT_PER_MIN}}\n msg := sprintf(\"service %s allows %d a minute\", [s.name, p.config.minute])\n}\n```",
854
+ "y": 1170,
855
+ "characteristic": "security",
856
+ "scope": "atomic",
857
+ "cadence": "triggered",
858
+ "trigger": "pull-request",
859
+ "invocation": "automated",
860
+ "description": "A Conftest policy over the gateway's declarative configuration (Kong decK file) fails the pull request when a service has no rate limit at any level, or one higher than agreed that carries no limit-exception tag; both rate-limiting (config.minute) and rate-limiting-advanced (the limit for the 60-second window) are read.\n\nThreshold: 0 gateway services without a rate-limiting plugin on the service, one of its routes, or globally; 0 per-minute limits above {{LIMIT_PER_MIN}} without an exception tag naming its ticket\n\nTool: Conftest (Open Policy Agent) over the Kong decK configuration\n\n```rego\npackage main\n\nimport rego.v1\n\nlimit_plugins := {\"rate-limiting\", \"rate-limiting-advanced\"}\n\nplugins_of(s) := array.concat(object.get(s, \"plugins\", []), [p | some r in object.get(s, \"routes\", []); some p in object.get(r, \"plugins\", [])])\n\nlimited(s) if { some p in plugins_of(s); p.name in limit_plugins }\nglobal if { some p in object.get(input, \"plugins\", []); p.name in limit_plugins }\n\n# an agreed exception carries a tag with its ticket: limit-exception:ARCH-123\nexcepted(p) if { some t in object.get(p, \"tags\", []); startswith(t, \"limit-exception:\") }\n\nper_minute(p) := p.config.minute if p.name == \"rate-limiting\"\nper_minute(p) := p.config.limit[i] if { p.name == \"rate-limiting-advanced\"; some i; p.config.window_size[i] == 60 }\n\ndeny contains msg if {\n not global\n some s in input.services\n not limited(s)\n msg := sprintf(\"service %s has no rate limit on it or its routes\", [s.name])\n}\n\ndeny contains msg if {\n some s in input.services\n some p in plugins_of(s)\n p.name in limit_plugins\n not excepted(p)\n per_minute(p) > {{LIMIT_PER_MIN}}\n msg := sprintf(\"service %s allows %v a minute without an exception tag\", [s.name, per_minute(p)])\n}\n```",
781
861
  "hubWhen": {
782
862
  "WHERE": [
783
863
  "gateway"
@@ -789,10 +869,13 @@
789
869
  "type": "fitness-fn",
790
870
  "label": "Edge rate rule present",
791
871
  "x": 1040,
792
- "y": 390,
793
- "category": "structural",
794
- "threshold": "Every web ACL in front of the element holds a rate-based rule in blocking mode; 0 plan changes that remove it",
795
- "description": "A Conftest policy over the Terraform plan fails when a WAF web ACL has no rate-based rule that blocks, so the edge limit cannot disappear in a refactoring.\n\nTool: Conftest (Open Policy Agent) over terraform show -json\n\n```rego\npackage main\n\nimport rego.v1\n\nrate_rule(acl) if {\n some r in acl.rule\n some s in r.statement\n count(s.rate_based_statement) > 0\n some a in r.action\n count(a.block) > 0\n}\n\ndeny contains msg if {\n some rc in input.resource_changes\n rc.type == \"aws_wafv2_web_acl\"\n not rate_rule(rc.change.after)\n msg := sprintf(\"%s has no blocking rate-based rule\", [rc.address])\n}\n```",
872
+ "y": 1300,
873
+ "characteristic": "security",
874
+ "scope": "atomic",
875
+ "cadence": "triggered",
876
+ "trigger": "pull-request",
877
+ "invocation": "automated",
878
+ "description": "A Conftest policy over the Terraform plan fails when a WAF web ACL has no rate-based rule that blocks, so the edge limit cannot disappear in a refactoring.\n\nThreshold: Every web ACL in front of the element holds a rate-based rule in blocking mode; 0 plan changes that remove it\n\nTool: Conftest (Open Policy Agent) over terraform show -json (AWS WAF; for Cloudflare: the cloudflare_ruleset resource with phase http_ratelimit, checked the same way)\n\n```rego\npackage main\n\nimport rego.v1\n\nrate_rule(acl) if {\n some r in acl.rule\n some s in r.statement\n count(s.rate_based_statement) > 0\n some a in r.action\n count(a.block) > 0\n}\n\ndeny contains msg if {\n some rc in input.resource_changes\n rc.type == \"aws_wafv2_web_acl\"\n not rate_rule(rc.change.after)\n msg := sprintf(\"%s has no blocking rate-based rule\", [rc.address])\n}\n```",
796
879
  "hubWhen": {
797
880
  "WHERE": [
798
881
  "waf"
@@ -804,10 +887,13 @@
804
887
  "type": "fitness-fn",
805
888
  "label": "Limit holds across instances",
806
889
  "x": 1040,
807
- "y": 520,
808
- "category": "structural",
809
- "threshold": "Against two instances sharing Redis, request {{LIMIT_PER_MIN}} + 1 within a minute gets 429 with Retry-After; another caller's request still succeeds",
810
- "description": "An integration test starts two instances of the element with a Redis container, spreads one caller's requests over both, and expects the limit to hold for the pair.\n\nTool: Vitest with supertest and Testcontainers (Redis)\n\n```ts\nit('limits one caller across instances', async () => {\n const [a, b] = await startInstances(2, { redisUrl: redis.getConnectionUrl() })\n for (let i = 0; i < {{LIMIT_PER_MIN}}; i++) await request(i % 2 ? a : b).get('/orders').set(auth(caller)).expect(200)\n const res = await request(a).get('/orders').set(auth(caller))\n expect(res.status).toBe(429)\n expect(Number(res.headers['retry-after'])).toBeGreaterThan(0)\n await request(b).get('/orders').set(auth(otherCaller)).expect(200)\n})\n```",
890
+ "y": 1430,
891
+ "characteristic": "security",
892
+ "scope": "atomic",
893
+ "cadence": "triggered",
894
+ "trigger": "pull-request",
895
+ "invocation": "automated",
896
+ "description": "An integration test starts two instances of the element with a Redis container, measures what one instance alone accepts from a flood (the single-instance allowance, whatever the algorithm), then spreads the same flood over both and compares; a last run stops Redis and expects the per-instance fallback to refuse.\n\nThreshold: Two instances sharing Redis accept no more from one caller in a minute than one instance alone plus 10 %, and no more than {{LIMIT_PER_MIN}} + {{BURST}}; another caller is still accepted; with Redis stopped, one instance still refuses past its own limit\n\nTool: Vitest with supertest and Testcontainers (Redis) (or the test runner of your stack)\n\n```ts\nconst LIMIT = {{LIMIT_PER_MIN}}\nconst BURST = {{BURST}}\nconst sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))\nconst flood = async (targets: Instance[], n: number) => {\n let accepted = 0\n for (let i = 0; i < n; i++) if ((await request(targets[i % targets.length]).get('/orders').set(auth(caller))).status === 200) accepted++\n return accepted\n}\n\nit('accepts no more across two instances than one instance does', async () => {\n const [a, b] = await startInstances(2, { redisUrl: redis.getConnectionUrl() })\n const alone = await flood([a], LIMIT * 2) // the single-instance allowance\n await sleep(60_000)\n const pair = await flood([a, b], LIMIT * 2)\n expect(pair).toBeLessThanOrEqual(alone * 1.1)\n expect(pair).toBeLessThanOrEqual(LIMIT + BURST)\n await request(b).get('/orders').set(auth(otherCaller)).expect(200)\n}, 300_000)\n\nit('still limits per instance when Redis is unreachable', async () => {\n const [a] = await startInstances(1, { redisUrl: redis.getConnectionUrl() })\n await redis.stop()\n expect(await flood([a], LIMIT * 2)).toBeLessThan(LIMIT * 2)\n}, 300_000)\n```",
811
897
  "hubWhen": {
812
898
  "WHERE": [
813
899
  "app"
@@ -817,12 +903,15 @@
817
903
  {
818
904
  "id": "ff-bots-challenge",
819
905
  "type": "fitness-fn",
820
- "label": "Repeated sign-in challenged",
906
+ "label": "Repeated costly calls challenged",
821
907
  "x": 1040,
822
- "y": 650,
823
- "category": "structural",
824
- "threshold": "The 11th attempt at a costly operation from one source within 10 minutes shows a challenge; the 1st attempt from a new source never does",
825
- "description": "An end-to-end test repeats the first costly operation from one browser context and expects the challenge widget on the 11th attempt, and none in a fresh context.\n\nTool: Playwright\n\n```ts\ntest('repeated sign-in is challenged', async ({ page, browser }) => {\n for (let i = 0; i < 11; i++) {\n await page.goto('/sign-in')\n await page.getByLabel('Email').fill('someone@example.com')\n await page.getByLabel('Password').fill(`wrong-${i}`)\n await page.getByRole('button', { name: 'Sign in' }).click()\n }\n await expect(page.locator('iframe[src*=\"challenges.cloudflare.com\"]')).toBeVisible()\n const fresh = await (await browser.newContext()).newPage()\n await fresh.goto('/sign-in')\n await expect(fresh.locator('iframe[src*=\"challenges.cloudflare.com\"]')).toHaveCount(0)\n})\n```",
908
+ "y": 1560,
909
+ "characteristic": "security",
910
+ "scope": "holistic",
911
+ "cadence": "triggered",
912
+ "trigger": "pull-request",
913
+ "invocation": "automated",
914
+ "description": "An end-to-end test uses the password reset (one of the costly operations, with no lockout of its own) from one browser context: the first attempt must show no challenge widget, the eleventh must; the locator covers Turnstile, hCaptcha and reCAPTCHA.\n\nThreshold: The 1st attempt at a costly operation from a fresh source shows no challenge; the 11th within 10 minutes shows one\n\nTool: Playwright\n\n```ts\nconst CHALLENGE = 'iframe[src*=\"challenges.cloudflare.com\"], iframe[src*=\"hcaptcha.com\"], iframe[src*=\"google.com/recaptcha\"]'\n\nconst resetOnce = async (page: Page) => {\n await page.goto('/password-reset')\n await page.getByLabel('Email').fill('someone@example.com')\n await page.getByRole('button', { name: 'Send reset link' }).click()\n}\n\ntest('a repeated costly operation is challenged, a first attempt never', async ({ page }) => {\n await resetOnce(page)\n await expect(page.locator(CHALLENGE)).toHaveCount(0)\n for (let i = 0; i < 10; i++) await resetOnce(page)\n await expect(page.locator(CHALLENGE)).toBeVisible()\n})\n```",
826
915
  "hubWhen": {
827
916
  "BOTS": [
828
917
  "challenge"
@@ -834,10 +923,13 @@
834
923
  "type": "fitness-fn",
835
924
  "label": "Bot control enabled",
836
925
  "x": 1040,
837
- "y": 780,
838
- "category": "structural",
839
- "threshold": "The web ACL in front of the element holds the managed bot rule group, not in count-only mode",
840
- "description": "A Conftest policy over the Terraform plan fails when the edge's managed bot rule group is missing or overridden to count, which would let bots through silently.\n\nTool: Conftest (Open Policy Agent) over terraform show -json, for AWS WAF Bot Control\n\n```rego\npackage main\n\nimport rego.v1\n\nbot_control(acl) if {\n some r in acl.rule\n some s in r.statement\n some m in s.managed_rule_group_statement\n m.name == \"AWSManagedRulesBotControlRuleSet\"\n some o in r.override_action\n count(o.none) > 0\n}\n\ndeny contains msg if {\n some rc in input.resource_changes\n rc.type == \"aws_wafv2_web_acl\"\n not bot_control(rc.change.after)\n msg := sprintf(\"%s does not enforce AWS WAF Bot Control\", [rc.address])\n}\n```",
926
+ "y": 1690,
927
+ "characteristic": "security",
928
+ "scope": "atomic",
929
+ "cadence": "triggered",
930
+ "trigger": "pull-request",
931
+ "invocation": "automated",
932
+ "description": "A Conftest policy over the Terraform plan fails when the edge's managed bot rule group is missing or overridden to count, which would let bots through silently.\n\nThreshold: The web ACL in front of the element holds the managed bot rule group, not in count-only mode\n\nTool: Conftest (Open Policy Agent) over terraform show -json, for AWS WAF Bot Control (for Cloudflare: the cloudflare_bot_management resource; for Akamai: the akamai_botman_* resources; each checked the same way for presence and a blocking action)\n\n```rego\npackage main\n\nimport rego.v1\n\nbot_control(acl) if {\n some r in acl.rule\n some s in r.statement\n some m in s.managed_rule_group_statement\n m.name == \"AWSManagedRulesBotControlRuleSet\"\n some o in r.override_action\n count(o.none) > 0\n}\n\ndeny contains msg if {\n some rc in input.resource_changes\n rc.type == \"aws_wafv2_web_acl\"\n not bot_control(rc.change.after)\n msg := sprintf(\"%s does not enforce AWS WAF Bot Control\", [rc.address])\n}\n```",
841
933
  "hubWhen": {
842
934
  "BOTS": [
843
935
  "managed"
@@ -845,17 +937,55 @@
845
937
  }
846
938
  },
847
939
  {
848
- "id": "ff-closed",
940
+ "id": "ff-bots-none",
849
941
  "type": "fitness-fn",
850
- "label": "Closed from outside",
942
+ "label": "Costly operations behind identity",
851
943
  "x": 1040,
852
- "y": 910,
853
- "category": "operational",
854
- "threshold": "0 ports of the element answer from outside the network",
855
- "description": "A scheduled scan from a runner outside the network tries every port of the element's addresses and fails on any that answers.\n\nTool: Nmap\n\n```bash\nnmap -Pn -p- --open -oG scan.txt $ELEMENT_ADDRESSES\nif grep -q '/open/' scan.txt; then\n echo \"reachable from outside:\"; grep '/open/' scan.txt; exit 1\nfi\n```",
944
+ "y": 1820,
945
+ "characteristic": "security",
946
+ "scope": "atomic",
947
+ "cadence": "triggered",
948
+ "trigger": "pull-request",
949
+ "invocation": "automated",
950
+ "description": "A test lists the routes flagged costly from the router (not from a list kept by hand) and calls each without a credential, expecting 401; a new costly route fails the test until it is protected or flagged.\n\nThreshold: Every route the router marks costly answers 401 without a credential; 0 exceptions\n\nTool: Vitest with supertest (or the test runner and HTTP client of your stack)\n\n```ts\nimport request from 'supertest'\nimport { app, routes } from '../src/app' // routes flagged costly: the operations listed in the decision\n\ndescribe.each(routes.filter((r) => r.costly))('%s %s', (route) => {\n it('refuses a call without a credential', async () => {\n await request(app)[route.method.toLowerCase()](route.example).expect(401)\n })\n})\n```",
951
+ "hubWhen": {
952
+ "BOTS": [
953
+ "none"
954
+ ]
955
+ }
956
+ },
957
+ {
958
+ "id": "ff-origin",
959
+ "type": "fitness-fn",
960
+ "label": "Origin closed to the internet",
961
+ "x": 1040,
962
+ "y": 1950,
963
+ "characteristic": "security",
964
+ "scope": "atomic",
965
+ "cadence": "triggered",
966
+ "trigger": "nightly",
967
+ "invocation": "automated",
968
+ "description": "A scheduled job on a runner outside the provider's network tries each origin address directly over HTTPS and fails when any answers, which would mean the edge and its limits can be bypassed.\n\nThreshold: 0 of the origin addresses answer a connection from the internet; every one is refused or times out\n\nTool: curl in a scheduled job on a runner outside the edge\n\n```bash\n#!/usr/bin/env bash\n# ORIGIN_ADDRESSES: the origin's addresses or host names as the edge sees them, space separated\nset -uo pipefail\nfail=0\nfor origin in $ORIGIN_ADDRESSES; do\n if curl -sk --max-time 10 -o /dev/null \"https://$origin/\"; then echo \"$origin answers directly, bypassing the edge\"; fail=1; fi\ndone\nexit $fail\n```",
969
+ "hubWhen": {
970
+ "EXPOSURE": [
971
+ "internet"
972
+ ]
973
+ }
974
+ },
975
+ {
976
+ "id": "ff-partner-alert",
977
+ "type": "fitness-fn",
978
+ "label": "Partner near its limit",
979
+ "x": 1040,
980
+ "y": 2080,
981
+ "characteristic": "security",
982
+ "scope": "atomic",
983
+ "cadence": "continual",
984
+ "invocation": "automated",
985
+ "description": "A Prometheus rule over the gateway's per-consumer request counter alerts the partner's owner; a partner whose limit was raised by agreement gets a rule of its own with its figure.\n\nThreshold: An alert names every partner whose request rate has been above 80 % of its limit for 15 minutes\n\nTool: Prometheus alerting rules over Kong's prometheus plugin (per_consumer and status_code_metrics on; for the application: its own http_requests_total by caller)\n\n```yaml\ngroups:\n- name: partner-limits\n rules:\n - alert: PartnerNearLimit\n expr: sum by (consumer) (rate(kong_http_requests_total[15m])) * 60 > 0.8 * {{LIMIT_PER_MIN}}\n for: 15m\n labels: { severity: ticket }\n annotations: { summary: \"{{ $labels.consumer }} has run above 80 % of its limit for 15 minutes\" }\n # a partner with a raised limit, agreed and recorded: its own rule with its figure\n - alert: PartnerNearLimitAcme\n expr: sum(rate(kong_http_requests_total{consumer=\"acme\"}[15m])) * 60 > 0.8 * 3000\n for: 15m\n labels: { severity: ticket }\n```",
856
986
  "hubWhen": {
857
987
  "EXPOSURE": [
858
- "internal"
988
+ "partners"
859
989
  ]
860
990
  }
861
991
  }
@@ -951,12 +1081,6 @@
951
1081
  "targetId": "need",
952
1082
  "relationType": "derives"
953
1083
  },
954
- {
955
- "id": "req-internal--derives--need",
956
- "sourceId": "req-internal",
957
- "targetId": "need",
958
- "relationType": "derives"
959
- },
960
1084
  {
961
1085
  "id": "sc-limit--verifies--req-limit",
962
1086
  "sourceId": "sc-limit",
@@ -1047,12 +1171,6 @@
1047
1171
  "targetId": "req-partners",
1048
1172
  "relationType": "verifies"
1049
1173
  },
1050
- {
1051
- "id": "sc-internal--verifies--req-internal",
1052
- "sourceId": "sc-internal",
1053
- "targetId": "req-internal",
1054
- "relationType": "verifies"
1055
- },
1056
1174
  {
1057
1175
  "id": "ff-noisy--implements--adr-gateway",
1058
1176
  "sourceId": "ff-noisy",
@@ -1089,6 +1207,132 @@
1089
1207
  "targetId": "adr-app",
1090
1208
  "relationType": "implements"
1091
1209
  },
1210
+ {
1211
+ "id": "ff-pages--implements--adr-gateway",
1212
+ "sourceId": "ff-pages",
1213
+ "targetId": "adr-gateway",
1214
+ "relationType": "implements"
1215
+ },
1216
+ {
1217
+ "id": "ff-pages--implements--adr-waf",
1218
+ "sourceId": "ff-pages",
1219
+ "targetId": "adr-waf",
1220
+ "relationType": "implements"
1221
+ },
1222
+ {
1223
+ "id": "ff-pages--implements--adr-app",
1224
+ "sourceId": "ff-pages",
1225
+ "targetId": "adr-app",
1226
+ "relationType": "implements"
1227
+ },
1228
+ {
1229
+ "id": "ff-bucket--implements--adr-gateway",
1230
+ "sourceId": "ff-bucket",
1231
+ "targetId": "adr-gateway",
1232
+ "relationType": "implements"
1233
+ },
1234
+ {
1235
+ "id": "ff-bucket--implements--adr-waf",
1236
+ "sourceId": "ff-bucket",
1237
+ "targetId": "adr-waf",
1238
+ "relationType": "implements"
1239
+ },
1240
+ {
1241
+ "id": "ff-bucket--implements--adr-app",
1242
+ "sourceId": "ff-bucket",
1243
+ "targetId": "adr-app",
1244
+ "relationType": "implements"
1245
+ },
1246
+ {
1247
+ "id": "ff-sliding--implements--adr-gateway",
1248
+ "sourceId": "ff-sliding",
1249
+ "targetId": "adr-gateway",
1250
+ "relationType": "implements"
1251
+ },
1252
+ {
1253
+ "id": "ff-sliding--implements--adr-waf",
1254
+ "sourceId": "ff-sliding",
1255
+ "targetId": "adr-waf",
1256
+ "relationType": "implements"
1257
+ },
1258
+ {
1259
+ "id": "ff-sliding--implements--adr-app",
1260
+ "sourceId": "ff-sliding",
1261
+ "targetId": "adr-app",
1262
+ "relationType": "implements"
1263
+ },
1264
+ {
1265
+ "id": "ff-fixed--implements--adr-gateway",
1266
+ "sourceId": "ff-fixed",
1267
+ "targetId": "adr-gateway",
1268
+ "relationType": "implements"
1269
+ },
1270
+ {
1271
+ "id": "ff-fixed--implements--adr-waf",
1272
+ "sourceId": "ff-fixed",
1273
+ "targetId": "adr-waf",
1274
+ "relationType": "implements"
1275
+ },
1276
+ {
1277
+ "id": "ff-fixed--implements--adr-app",
1278
+ "sourceId": "ff-fixed",
1279
+ "targetId": "adr-app",
1280
+ "relationType": "implements"
1281
+ },
1282
+ {
1283
+ "id": "ff-key-account--implements--adr-gateway",
1284
+ "sourceId": "ff-key-account",
1285
+ "targetId": "adr-gateway",
1286
+ "relationType": "implements"
1287
+ },
1288
+ {
1289
+ "id": "ff-key-account--implements--adr-waf",
1290
+ "sourceId": "ff-key-account",
1291
+ "targetId": "adr-waf",
1292
+ "relationType": "implements"
1293
+ },
1294
+ {
1295
+ "id": "ff-key-account--implements--adr-app",
1296
+ "sourceId": "ff-key-account",
1297
+ "targetId": "adr-app",
1298
+ "relationType": "implements"
1299
+ },
1300
+ {
1301
+ "id": "ff-key-apikey--implements--adr-gateway",
1302
+ "sourceId": "ff-key-apikey",
1303
+ "targetId": "adr-gateway",
1304
+ "relationType": "implements"
1305
+ },
1306
+ {
1307
+ "id": "ff-key-apikey--implements--adr-waf",
1308
+ "sourceId": "ff-key-apikey",
1309
+ "targetId": "adr-waf",
1310
+ "relationType": "implements"
1311
+ },
1312
+ {
1313
+ "id": "ff-key-apikey--implements--adr-app",
1314
+ "sourceId": "ff-key-apikey",
1315
+ "targetId": "adr-app",
1316
+ "relationType": "implements"
1317
+ },
1318
+ {
1319
+ "id": "ff-key-ip--implements--adr-gateway",
1320
+ "sourceId": "ff-key-ip",
1321
+ "targetId": "adr-gateway",
1322
+ "relationType": "implements"
1323
+ },
1324
+ {
1325
+ "id": "ff-key-ip--implements--adr-waf",
1326
+ "sourceId": "ff-key-ip",
1327
+ "targetId": "adr-waf",
1328
+ "relationType": "implements"
1329
+ },
1330
+ {
1331
+ "id": "ff-key-ip--implements--adr-app",
1332
+ "sourceId": "ff-key-ip",
1333
+ "targetId": "adr-app",
1334
+ "relationType": "implements"
1335
+ },
1092
1336
  {
1093
1337
  "id": "ff-gateway--implements--adr-gateway",
1094
1338
  "sourceId": "ff-gateway",
@@ -1144,9 +1388,57 @@
1144
1388
  "relationType": "implements"
1145
1389
  },
1146
1390
  {
1147
- "id": "ff-closed--implements--adr-internal",
1148
- "sourceId": "ff-closed",
1149
- "targetId": "adr-internal",
1391
+ "id": "ff-bots-none--implements--adr-gateway",
1392
+ "sourceId": "ff-bots-none",
1393
+ "targetId": "adr-gateway",
1394
+ "relationType": "implements"
1395
+ },
1396
+ {
1397
+ "id": "ff-bots-none--implements--adr-waf",
1398
+ "sourceId": "ff-bots-none",
1399
+ "targetId": "adr-waf",
1400
+ "relationType": "implements"
1401
+ },
1402
+ {
1403
+ "id": "ff-bots-none--implements--adr-app",
1404
+ "sourceId": "ff-bots-none",
1405
+ "targetId": "adr-app",
1406
+ "relationType": "implements"
1407
+ },
1408
+ {
1409
+ "id": "ff-origin--implements--adr-gateway",
1410
+ "sourceId": "ff-origin",
1411
+ "targetId": "adr-gateway",
1412
+ "relationType": "implements"
1413
+ },
1414
+ {
1415
+ "id": "ff-origin--implements--adr-waf",
1416
+ "sourceId": "ff-origin",
1417
+ "targetId": "adr-waf",
1418
+ "relationType": "implements"
1419
+ },
1420
+ {
1421
+ "id": "ff-origin--implements--adr-app",
1422
+ "sourceId": "ff-origin",
1423
+ "targetId": "adr-app",
1424
+ "relationType": "implements"
1425
+ },
1426
+ {
1427
+ "id": "ff-partner-alert--implements--adr-gateway",
1428
+ "sourceId": "ff-partner-alert",
1429
+ "targetId": "adr-gateway",
1430
+ "relationType": "implements"
1431
+ },
1432
+ {
1433
+ "id": "ff-partner-alert--implements--adr-waf",
1434
+ "sourceId": "ff-partner-alert",
1435
+ "targetId": "adr-waf",
1436
+ "relationType": "implements"
1437
+ },
1438
+ {
1439
+ "id": "ff-partner-alert--implements--adr-app",
1440
+ "sourceId": "ff-partner-alert",
1441
+ "targetId": "adr-app",
1150
1442
  "relationType": "implements"
1151
1443
  }
1152
1444
  ]