verikloak-rails 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d258ce7b00c8aed380623cc36b26669d86cf80c3c06e748bc677c4f8af93a4f1
4
- data.tar.gz: 874e2f3c8ed2eb372d7fd4238639f4fc16e9cdd0ee6a3de7dadc57e24bbcf629
3
+ metadata.gz: 7d7d44a12b8963c944bc63c16ed0890ce63df67f5f6226f1db61aac701dbbc00
4
+ data.tar.gz: ff24126d34ee02f4eaa220c97db88e7f379657c9a26ece23f868be6ad46ecb9b
5
5
  SHA512:
6
- metadata.gz: 3e035ee3bfa25ad7c9e9eb36d1279f2ea265445c60270aa2d8a8d3fcce1757cad6003892715a1faaec22cb62148bda295522ba6c12cc3bfa7858f3d2100182eb
7
- data.tar.gz: c94c073924c9ed1530978aadd7abd84855e7478350572ab70338b9e8cc0a8dd7b739865517dd488b347d87a23739580b09beee206bc8aeeda4afd40d0e5ab13e
6
+ metadata.gz: 968b2516670f1d4dd17dc3a4c2ddbb398b26ed0bc93007612ec4ee35c84d2066b3458e3d790f4e6211183d76daffa605464d9cf645da3050ad2e34af0468f4a0
7
+ data.tar.gz: dc05a2a815b3be7d9d67921bcc2bc2ddcbd9afdd71264de0f421e1b666906e862cc0963f64fef883a89ac66025c27abd10de967f77ff8d32665d81e895b28c57
data/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ---
9
9
 
10
+ ## [0.1.1] - 2025-09-13
11
+
12
+ ### Fixed
13
+ - ForwardedAccessToken: fix `ensure_bearer` accepting malformed values (e.g., `BearerXYZ`).
14
+
15
+ ### Changed
16
+ - Strengthen Bearer scheme normalization to always produce `Bearer <token>`.
17
+ - Detect scheme case-insensitively.
18
+ - Collapse tabs/multiple spaces after the scheme to a single space.
19
+ - Normalize missing-space form `BearerXYZ` to `Bearer XYZ`.
20
+ - Add/update middleware specs to cover the above normalization.
21
+
10
22
  ## [0.1.0] - 2025-09-07
11
23
 
12
24
  ### Added
@@ -12,6 +12,8 @@ module Verikloak
12
12
  # - Never overwrites an existing `Authorization` header
13
13
  # - Can derive the token from a prioritized list of headers
14
14
  class ForwardedAccessToken
15
+ BEARER_SCHEME = 'Bearer'
16
+ BEARER_SCHEME_LENGTH = BEARER_SCHEME.length
15
17
  # Initialize the middleware.
16
18
  #
17
19
  # @param app [#call] next Rack app
@@ -76,11 +78,28 @@ module Verikloak
76
78
  env['HTTP_AUTHORIZATION'] ||= ensure_bearer(token)
77
79
  end
78
80
 
79
- # Ensure the token string is prefixed with 'Bearer '.
81
+ # Normalize to a proper 'Bearer <token>' header value.
82
+ # - Detects scheme case-insensitively
83
+ # - Inserts a missing space (e.g., 'BearerXYZ' => 'Bearer XYZ')
84
+ # - Collapses multiple spaces/tabs after the scheme to a single space
80
85
  # @param token [String]
81
86
  # @return [String]
82
87
  def ensure_bearer(token)
83
- token.start_with?('Bearer') ? token : "Bearer #{token}"
88
+ s = token.to_s.strip
89
+ # Case-insensitive 'Bearer' with spaces/tabs after
90
+ if s =~ /\A#{BEARER_SCHEME}[ \t]+/i
91
+ rest = s.sub(/\A#{BEARER_SCHEME}[ \t]+/i, '')
92
+ return "#{BEARER_SCHEME} #{rest}"
93
+ end
94
+
95
+ # Case-insensitive 'Bearer' with no separator (e.g., 'BearerXYZ')
96
+ if s =~ /\A#{BEARER_SCHEME}(?![ \t])/i
97
+ rest = s[BEARER_SCHEME_LENGTH..] || ''
98
+ return "#{BEARER_SCHEME} #{rest}"
99
+ end
100
+
101
+ # No scheme present; add it
102
+ "#{BEARER_SCHEME} #{s}"
84
103
  end
85
104
 
86
105
  # Whether the request originates from a trusted proxy subnet.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Verikloak
4
4
  module Rails
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verikloak-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - taiyaky
@@ -74,7 +74,7 @@ metadata:
74
74
  source_code_uri: https://github.com/taiyaky/verikloak-rails
75
75
  changelog_uri: https://github.com/taiyaky/verikloak-rails/blob/main/CHANGELOG.md
76
76
  bug_tracker_uri: https://github.com/taiyaky/verikloak-rails/issues
77
- documentation_uri: https://rubydoc.info/gems/verikloak-rails/0.1.0
77
+ documentation_uri: https://rubydoc.info/gems/verikloak-rails/0.1.1
78
78
  rubygems_mfa_required: 'true'
79
79
  rdoc_options: []
80
80
  require_paths: