machina-auth 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/machina/version.rb +1 -1
- data/lib/machina/webhook_receiver.rb +3 -0
- data/spec/machina/webhook_receiver_spec.rb +17 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ef95dc9a17c0abc2f72fd81cc6bc78ca5baea5a058fb8800087c0ab1753fa8f
|
|
4
|
+
data.tar.gz: 85e89ffab0def4950f3da9ad9513d0cca3475cd222af0cd7fa12f9c56a8e18f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b58c5c91d1ca06f6d5d050f79e200c3c012473d262a2a5231c8cc3b3a2dc0c799b1f163dffb4963e243bfe2c8d5d915e87ac74db516a4f1f493cdb34c55510a4
|
|
7
|
+
data.tar.gz: 2e8113a5ccfef4f7a6c07bba04127e746256da82ba8f0d79d7529625e5cb92acf2ac621beffacf80f552923e1b7858aae65f4de243d67f1d0775dbc01e43710a
|
data/lib/machina/version.rb
CHANGED
|
@@ -18,6 +18,9 @@ module Machina
|
|
|
18
18
|
|
|
19
19
|
def valid?
|
|
20
20
|
return false if signature.blank?
|
|
21
|
+
# Fail closed on a blank service token: SHA256("") is a public constant, so
|
|
22
|
+
# a blank token would make every signature forgeable.
|
|
23
|
+
return false if Machina.config.service_token.blank?
|
|
21
24
|
|
|
22
25
|
signing_key = Digest::SHA256.hexdigest(Machina.config.service_token.to_s)
|
|
23
26
|
expected = OpenSSL::HMAC.hexdigest('SHA256', signing_key, raw_body)
|
|
@@ -28,6 +28,23 @@ RSpec.describe Machina::WebhookReceiver do
|
|
|
28
28
|
expect(receiver.process!).to be(false)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
it 'fails closed when the service token is blank' do
|
|
32
|
+
Machina.config.service_token = ''
|
|
33
|
+
# A blank token makes the signing key SHA256(""), a public constant an
|
|
34
|
+
# attacker can compute — so even a correctly-signed request must be rejected.
|
|
35
|
+
raw_body = JSON.generate({ user_id: '1' })
|
|
36
|
+
forgeable_key = Digest::SHA256.hexdigest('')
|
|
37
|
+
signature = OpenSSL::HMAC.hexdigest('SHA256', forgeable_key, raw_body)
|
|
38
|
+
request = instance_double(
|
|
39
|
+
ActionDispatch::Request,
|
|
40
|
+
body: StringIO.new(raw_body),
|
|
41
|
+
headers: { 'X-Machina-Event' => 'permissions.changed', 'X-Machina-Signature' => signature },
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
receiver = described_class.new(request, cache:)
|
|
45
|
+
expect(receiver.process!).to be(false)
|
|
46
|
+
end
|
|
47
|
+
|
|
31
48
|
describe 'permissions.changed' do
|
|
32
49
|
it 'marks cached sessions as stale' do
|
|
33
50
|
cache.write('machina:session:ps_123', { user_id: '1' })
|