machina-auth 1.0.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64cd50975d04d89620d0ad73d6be045f93256efc4d34c57a563782167e659dc2
4
- data.tar.gz: 3a962c88b3b58a015fb267de869acc17575cf7377df37b1bfe4439c0bbc66eba
3
+ metadata.gz: 0ef95dc9a17c0abc2f72fd81cc6bc78ca5baea5a058fb8800087c0ab1753fa8f
4
+ data.tar.gz: 85e89ffab0def4950f3da9ad9513d0cca3475cd222af0cd7fa12f9c56a8e18f7
5
5
  SHA512:
6
- metadata.gz: b8962c63372568bacb6c6afa2ea47a0530999c0299a39117cbeefee5cec676f81fa25eba413aa3f093e26201878446412a4c9a5fac7f5df7604a13f6078876cf
7
- data.tar.gz: 5cc1964cc2c24e6f4d3ddd9e45334bd2dec68a59fdeb73c85ccfc604cd4d19c49094ab6decec799c2d71862f88bd37e8310c1e1801d4d0c5d85cbb383f4ef956
6
+ metadata.gz: b58c5c91d1ca06f6d5d050f79e200c3c012473d262a2a5231c8cc3b3a2dc0c799b1f163dffb4963e243bfe2c8d5d915e87ac74db516a4f1f493cdb34c55510a4
7
+ data.tar.gz: 2e8113a5ccfef4f7a6c07bba04127e746256da82ba8f0d79d7529625e5cb92acf2ac621beffacf80f552923e1b7858aae65f4de243d67f1d0775dbc01e43710a
@@ -39,11 +39,12 @@ module Machina
39
39
  }
40
40
  end
41
41
 
42
- # Relative paths only an absolute or protocol-relative return_to is an
43
- # open redirect on a credential-bearing request.
42
+ # Relative paths only. Reject a leading // or /\ browsers treat both as
43
+ # protocol-relative, so either is an open redirect on a credential-bearing
44
+ # request (a backslash also trips Rails' UnsafeRedirectError as a 500).
44
45
  def safe_return_to
45
46
  value = params[:return_to].to_s
46
- return value if value.start_with?('/') && !value.start_with?('//')
47
+ return value if value.start_with?('/') && !value.match?(%r{\A/[/\\]})
47
48
 
48
49
  '/'
49
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Machina
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.2'
5
5
  end
@@ -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' })
@@ -68,6 +68,12 @@ RSpec.describe Machina::CallbacksController, type: :controller do
68
68
 
69
69
  expect(response).to redirect_to('/')
70
70
  end
71
+
72
+ it 'rejects a backslash protocol-relative return_to' do
73
+ get :show, params: { token:, state:, return_to: '/\\evil.example.com' }
74
+
75
+ expect(response).to redirect_to('/')
76
+ end
71
77
  end
72
78
 
73
79
  describe 'with an invalid state' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machina-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZAR