foil-server 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +154 -0
  4. data/lib/foil/server/client.rb +472 -0
  5. data/lib/foil/server/crypto_support.rb +49 -0
  6. data/lib/foil/server/errors.rb +21 -0
  7. data/lib/foil/server/gate_delivery.rb +325 -0
  8. data/lib/foil/server/sealed_token.rb +78 -0
  9. data/lib/foil/server/types.rb +5 -0
  10. data/lib/foil/server/version.rb +5 -0
  11. data/lib/foil/server.rb +31 -0
  12. data/spec/LICENSE +21 -0
  13. data/spec/README.md +160 -0
  14. data/spec/fixtures/api/fingerprints/detail.json +70 -0
  15. data/spec/fixtures/api/fingerprints/list.json +37 -0
  16. data/spec/fixtures/api/gate/agent-token-revoke.json +3 -0
  17. data/spec/fixtures/api/gate/agent-token-verify.json +12 -0
  18. data/spec/fixtures/api/gate/login-session-consume.json +10 -0
  19. data/spec/fixtures/api/gate/login-session-create.json +12 -0
  20. data/spec/fixtures/api/gate/registry-detail.json +45 -0
  21. data/spec/fixtures/api/gate/registry-list.json +47 -0
  22. data/spec/fixtures/api/gate/service-create.json +49 -0
  23. data/spec/fixtures/api/gate/service-detail.json +49 -0
  24. data/spec/fixtures/api/gate/service-disable.json +49 -0
  25. data/spec/fixtures/api/gate/service-update.json +49 -0
  26. data/spec/fixtures/api/gate/services-list.json +51 -0
  27. data/spec/fixtures/api/gate/session-ack.json +10 -0
  28. data/spec/fixtures/api/gate/session-create.json +13 -0
  29. data/spec/fixtures/api/gate/session-poll.json +36 -0
  30. data/spec/fixtures/api/organizations/api-key-create.json +27 -0
  31. data/spec/fixtures/api/organizations/api-key-list.json +31 -0
  32. data/spec/fixtures/api/organizations/api-key-revoke.json +25 -0
  33. data/spec/fixtures/api/organizations/api-key-rotate.json +27 -0
  34. data/spec/fixtures/api/organizations/api-key-update.json +29 -0
  35. data/spec/fixtures/api/organizations/organization-create.json +14 -0
  36. data/spec/fixtures/api/organizations/organization-update.json +14 -0
  37. data/spec/fixtures/api/organizations/organization.json +14 -0
  38. data/spec/fixtures/api/sessions/detail.json +434 -0
  39. data/spec/fixtures/api/sessions/list.json +36 -0
  40. data/spec/fixtures/errors/invalid-api-key.json +10 -0
  41. data/spec/fixtures/errors/missing-api-key.json +10 -0
  42. data/spec/fixtures/errors/not-found.json +10 -0
  43. data/spec/fixtures/errors/validation-error.json +20 -0
  44. data/spec/fixtures/gate-delivery/approved-webhook-payload.valid.json +19 -0
  45. data/spec/fixtures/gate-delivery/delivery-request.json +9 -0
  46. data/spec/fixtures/gate-delivery/env-policy.json +40 -0
  47. data/spec/fixtures/gate-delivery/vector.v1.json +28 -0
  48. data/spec/fixtures/gate-delivery/webhook-signature.json +9 -0
  49. data/spec/fixtures/manifest.json +185 -0
  50. data/spec/fixtures/sealed-token/invalid.json +4 -0
  51. data/spec/fixtures/sealed-token/vector.v1.json +54 -0
  52. data/spec/openapi.json +20482 -0
  53. data/spec/sealed-token.md +114 -0
  54. metadata +96 -0
@@ -0,0 +1,114 @@
1
+ # Sealed Token Specification
2
+
3
+ Foil sealed tokens are encrypted server handoff payloads returned by `Foil.getSession()`.
4
+
5
+ This document is the language-agnostic contract for verifying those tokens in public server SDKs.
6
+
7
+ ## Overview
8
+
9
+ - Input: a base64-encoded sealed token string
10
+ - Output: a JSON payload describing the verified Foil session decision for the current action
11
+ - Confidentiality and integrity: AES-256-GCM
12
+ - Compression: zlib deflate/inflate
13
+
14
+ ## Payload format
15
+
16
+ After base64 decoding, the byte layout is:
17
+
18
+ - `version` - 1 byte
19
+ - `nonce` - 12 bytes
20
+ - `ciphertext` - variable length
21
+ - `tag` - 16 bytes
22
+
23
+ Current version:
24
+
25
+ - `0x01`
26
+
27
+ Reject any token whose version byte is not `0x01`.
28
+
29
+ ## Secret normalization
30
+
31
+ The verifier accepts either:
32
+
33
+ - a plaintext Foil secret key, such as `sk_live_...`
34
+ - or the corresponding lowercase SHA-256 hex digest
35
+
36
+ Normalization rules:
37
+
38
+ - If the supplied secret matches `/^[0-9a-f]{64}$/i`, treat it as the secret hash and lowercase it
39
+ - Otherwise compute the SHA-256 hex digest of the supplied secret key
40
+
41
+ ## Key derivation
42
+
43
+ Derive the AES key as:
44
+
45
+ - `sha256(normalized_secret + "\0sealed-results")`
46
+
47
+ Use the raw 32-byte digest as the AES-256-GCM key.
48
+
49
+ ## Verification steps
50
+
51
+ 1. Base64 decode the token
52
+ 2. Parse the version byte, nonce, ciphertext, and tag
53
+ 3. Normalize the caller's secret material
54
+ 4. Derive the AES-256-GCM key
55
+ 5. Decrypt using:
56
+ - algorithm: `aes-256-gcm`
57
+ - nonce: parsed 12-byte nonce
58
+ - tag: parsed 16-byte authentication tag
59
+ 6. Inflate the decrypted bytes with zlib
60
+ 7. Parse the inflated UTF-8 JSON payload
61
+
62
+ Any failure in decoding, parsing, authentication, decompression, or JSON parsing must be treated as verification failure.
63
+
64
+ ## Payload shape
65
+
66
+ The decrypted JSON payload currently includes:
67
+
68
+ - `object`
69
+ - `session_id`
70
+ - `decision`
71
+ - `request`
72
+ - `visitor_fingerprint`
73
+ - `signals`
74
+ - `score_breakdown`
75
+ - `attribution`
76
+ - `embed`
77
+
78
+ The payload is aligned to the same public vocabulary as the Sessions API:
79
+
80
+ - `decision`
81
+ - `event_id`
82
+ - `verdict`
83
+ - `risk_score`
84
+ - `phase`
85
+ - `is_provisional`
86
+ - `manipulation`
87
+ - `evaluation_duration_ms`
88
+ - `evaluated_at`
89
+ - `request`
90
+ - `url`
91
+ - `user_agent`
92
+ - `ip_address`
93
+ - `screen_size`
94
+ - `is_touch_capable`
95
+ - `visitor_fingerprint`
96
+ - `object`
97
+ - `id`
98
+ - `confidence`
99
+ - `identified_at`
100
+ - `score_breakdown`
101
+ - `categories`
102
+ - `attribution`
103
+ - `bot`
104
+
105
+ Public SDKs should treat the payload as forward-compatible:
106
+
107
+ - preserve unknown fields
108
+ - do not require fields beyond the documented stable surface
109
+
110
+ ## Fixtures
111
+
112
+ Golden vectors live under `fixtures/sealed-token/`.
113
+
114
+ Every language SDK must verify the shared vectors successfully and reject the invalid vectors it ships with.
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foil-server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ platform: ruby
6
+ authors:
7
+ - ABXY Labs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-05-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Customer-facing Ruby SDK for Foil Sessions, Fingerprints, Organizations,
14
+ and sealed token verification.
15
+ email:
16
+ - support@usefoil.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - lib/foil/server.rb
24
+ - lib/foil/server/client.rb
25
+ - lib/foil/server/crypto_support.rb
26
+ - lib/foil/server/errors.rb
27
+ - lib/foil/server/gate_delivery.rb
28
+ - lib/foil/server/sealed_token.rb
29
+ - lib/foil/server/types.rb
30
+ - lib/foil/server/version.rb
31
+ - spec/LICENSE
32
+ - spec/README.md
33
+ - spec/fixtures/api/fingerprints/detail.json
34
+ - spec/fixtures/api/fingerprints/list.json
35
+ - spec/fixtures/api/gate/agent-token-revoke.json
36
+ - spec/fixtures/api/gate/agent-token-verify.json
37
+ - spec/fixtures/api/gate/login-session-consume.json
38
+ - spec/fixtures/api/gate/login-session-create.json
39
+ - spec/fixtures/api/gate/registry-detail.json
40
+ - spec/fixtures/api/gate/registry-list.json
41
+ - spec/fixtures/api/gate/service-create.json
42
+ - spec/fixtures/api/gate/service-detail.json
43
+ - spec/fixtures/api/gate/service-disable.json
44
+ - spec/fixtures/api/gate/service-update.json
45
+ - spec/fixtures/api/gate/services-list.json
46
+ - spec/fixtures/api/gate/session-ack.json
47
+ - spec/fixtures/api/gate/session-create.json
48
+ - spec/fixtures/api/gate/session-poll.json
49
+ - spec/fixtures/api/organizations/api-key-create.json
50
+ - spec/fixtures/api/organizations/api-key-list.json
51
+ - spec/fixtures/api/organizations/api-key-revoke.json
52
+ - spec/fixtures/api/organizations/api-key-rotate.json
53
+ - spec/fixtures/api/organizations/api-key-update.json
54
+ - spec/fixtures/api/organizations/organization-create.json
55
+ - spec/fixtures/api/organizations/organization-update.json
56
+ - spec/fixtures/api/organizations/organization.json
57
+ - spec/fixtures/api/sessions/detail.json
58
+ - spec/fixtures/api/sessions/list.json
59
+ - spec/fixtures/errors/invalid-api-key.json
60
+ - spec/fixtures/errors/missing-api-key.json
61
+ - spec/fixtures/errors/not-found.json
62
+ - spec/fixtures/errors/validation-error.json
63
+ - spec/fixtures/gate-delivery/approved-webhook-payload.valid.json
64
+ - spec/fixtures/gate-delivery/delivery-request.json
65
+ - spec/fixtures/gate-delivery/env-policy.json
66
+ - spec/fixtures/gate-delivery/vector.v1.json
67
+ - spec/fixtures/gate-delivery/webhook-signature.json
68
+ - spec/fixtures/manifest.json
69
+ - spec/fixtures/sealed-token/invalid.json
70
+ - spec/fixtures/sealed-token/vector.v1.json
71
+ - spec/openapi.json
72
+ - spec/sealed-token.md
73
+ homepage: https://github.com/abxy-labs/foil-server-ruby
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 3.3.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.5.22
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Official Foil Ruby server SDK
96
+ test_files: []