katalyst-basic-auth 1.0.0 → 1.0.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: 6986b0c9b3f2e9731aaead2c1b74db0008be2ab82ee91e377b772caad2a9397d
4
- data.tar.gz: 87daff02ae81a92bcb90d3d24be50e7109e70fcf865521fc5edb8bcf861dfde5
3
+ metadata.gz: e0690a58df78d87a4b6ec2a4399953e9e42a3a6cad751dd80e7583881cc9a620
4
+ data.tar.gz: 56c1bd702be0b16cabc4b66291724ee344ec6ae6130011bb50aa71aad04d31ac
5
5
  SHA512:
6
- metadata.gz: 7936209ed48a5403081c7a89f5842af9fd9bb5828cb15a6c82a57fa0a8ae2708aa25dd797acbd6b92bd675174853365fd2b8a01fc30d2de356235d151b5f7ad5
7
- data.tar.gz: 1371ef21dd3f0a059d929e2e4e095567873b440002a449fd2e35a622cc85753e9679dd368ea432d8595465db03c4cc3ebc238215af64d6849d2f0a1a46d3e915
6
+ metadata.gz: 7475af04fa7c36c0dd6a09bc7713880807c64678d480a13184bad2db6ae1fc2867c26e92a3bbfbbd337a9161d2be94642f8c6a68716731bda81450557efa7b1b
7
+ data.tar.gz: aaea9752360f625d4aaaaac20fa29358553098f08e03ed7a85ae7a75b1b3e80a7f561d69aa1d8fc5b90c79afa8949f259a1ac651685c206efad5fe4206fb1d9b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [1.0.1] - 2026-11-26
2
+
3
+ - Fix: normalise repeated slashes before matching paths, e.g. `//admin` is matched as `/admin`
4
+ - Fix: match configured paths on segment boundaries, e.g. excluding `/up` no longer excludes `/uploads`
5
+
6
+ ## [1.0.0] - 2025-08-04
7
+
8
+ - Drop support for old ruby versions
9
+
1
10
  ## [0.5.0] - 2024-04-26
2
11
 
3
12
  - Add `/up` as a default allowed path (Rails 7.1+ health check)
data/README.md CHANGED
@@ -29,7 +29,7 @@ The following environment variables can optionally be defined to configure the g
29
29
 
30
30
  | Environment Variable | Description |
31
31
  | ------ | ----- |
32
- | KATALYST_BASIC_AUTH_ENABLED | If "yes" or "true", the middleware will be enabled. By default, the middleware is enabled on staging and uat Rails environments |
32
+ | KATALYST_BASIC_AUTH_ENABLED | If "yes" or "true", the middleware will be enabled. By default, the middleware is enabled on staging and uat Rails environments. To disable basic auth in these environments, you must explicitly set this to a non-true value. |
33
33
  | KATALYST_BASIC_AUTH_USER | The username for basic authentication. Default is the Rails application name in lowercase. |
34
34
  | KATALYST_BASIC_AUTH_PASS | The password for basic authentication. A password will be generated if not set. |
35
35
  | KATALYST_BASIC_AUTH_IP_ALLOWLIST | Comma or space separated list of IP addresses or CIDR ranges to allow without basic auth |
@@ -17,10 +17,17 @@ module Katalyst
17
17
  # @param path [String] Request path
18
18
  # @return [Config] The config for the given path
19
19
  def for_path(path)
20
- path ||= ROOT_PATH
20
+ path = normalize_path(path)
21
21
  all.sort_by(&:path)
22
22
  .reverse
23
- .detect { |i| path.match(/^#{i.path}/) } || global
23
+ .detect { |i| i.match?(path) } || global
24
+ end
25
+
26
+ # Compare paths the way the Rails router will see them, e.g. "//admin" routes to "/admin"
27
+ # @param path [String, nil] Request path
28
+ # @return [String] Path with repeated slashes collapsed
29
+ def normalize_path(path)
30
+ "/#{path}".squeeze("/")
24
31
  end
25
32
 
26
33
  # @return [Config] The global configuration
@@ -126,6 +133,14 @@ module Katalyst
126
133
  path == ROOT_PATH
127
134
  end
128
135
 
136
+ # Matches the configured path and anything below it, on path segment boundaries,
137
+ # e.g. "/up" matches "/up" and "/up/db" but not "/uploads"
138
+ # @param request_path [String] Normalized request path
139
+ def match?(request_path)
140
+ prefix = path.chomp("/")
141
+ request_path == prefix || request_path.start_with?("#{prefix}/")
142
+ end
143
+
129
144
  def allow_ip?(env)
130
145
  request = ::Rack::Request.new(env)
131
146
  return false unless request.ip
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-basic-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
- rubygems_version: 3.6.9
51
+ rubygems_version: 4.0.20
52
52
  specification_version: 4
53
53
  summary: Gem to add basic auth on staging websites
54
54
  test_files: []