glib-web 5.1.2 → 5.1.4

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: 8e7848fb02064447620d8fca19a5f94b27c135b5e6c40dcd3c16974d19bb84e7
4
- data.tar.gz: e187535507305543f7c5c9a5734393d60c89fd1167bf488489963b304dd92f44
3
+ metadata.gz: d834dc054cfc079edbcf57609a2d05b4ad8837a8abfea74f3d75d75d546235a6
4
+ data.tar.gz: 850b0614ff17f7b436c49593bcfc28d2559dcf19505b543093f498f1c255817f
5
5
  SHA512:
6
- metadata.gz: 555954cb635653ad23d9af3da7810db47bf87b4ad6807d029a5294fcb1212eee02cefa64f96a97e819c11d1a5ed3134855329e722e18207df20c0f0153011e8e
7
- data.tar.gz: fde96a7c67e9f8e718d0cb7c8de72dd882e49607965891040fadf6c5b71e20be4ef2f3f69cb810662d585434ad1e650174569c0ddc87959c601fd10cdeadb189
6
+ metadata.gz: 859713dca4f2084b66389beadfcac6468d94b9d93006a1dedc7bf238eb68ce9e98ba1cbe89871e563a2e63c627624291778d811ae29c3f4a263badae8277adaf
7
+ data.tar.gz: 8c25c1f91953477464b2fd238c06c8ee8ddbb0d943ef2848c14b359a6ce137c79e35d7c4591812fe312785664a072cc101be04f6fd14f664a3ab108368a015d8
@@ -101,7 +101,16 @@ module Glib::Auth
101
101
  end
102
102
  end
103
103
 
104
- resource_instance = instance_variable_get("@#{resource_name}") || options[:resource] || policy_name
104
+ resource_instance = instance_variable_get("@#{resource_name}")
105
+ if resource_instance.nil?
106
+ # An explicitly supplied `resource:` is authoritative even when nil (e.g. a scoped
107
+ # `find_by` that resolved nothing). Falling back to the policy-name symbol would hand
108
+ # the policy a truthy placeholder in place of the missing record, so record-bound gates
109
+ # (`record.present?`, `return false unless record`) would pass for exactly the request
110
+ # they exist to refuse -- fail-open. Pass the nil through so they fail closed. The
111
+ # symbol fallback remains for callers that don't supply `resource:` at all.
112
+ resource_instance = options.key?(:resource) ? options[:resource] : policy_name
113
+ end
105
114
 
106
115
  query = "#{action_name}?"
107
116
  policy_instance = policy(resource_instance, policy_name, options.fetch(:context, nil))
@@ -2,6 +2,13 @@ module Glib::Params
2
2
  module Allowlist
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ # Raised when a MUTATING request submits a present-but-unrecognised value:
6
+ # real clients only submit values the UI offered, so a mismatch means a
7
+ # value was forgotten from the allow-list or the client is broken — both
8
+ # must surface (via the consumer's 500/reporting pipeline), not silently
9
+ # degrade into the wrong behavior.
10
+ class UnrecognizedValue < StandardError; end
11
+
5
12
  # Resolve a stringly-typed request param (or any boundary string) to one
6
13
  # symbol drawn from a closed allow-list (+allowed_symbols+), returning
7
14
  # +default+ when the value is missing, blank, or not recognised.
@@ -13,11 +20,32 @@ module Glib::Params
13
20
  # +allowed_symbols+ (or +default+), so attacker input can never create a new
14
21
  # symbol regardless of what is sent.
15
22
  #
16
- # nil / "" fall through to +default+ implicitly (no symbol's string form is
17
- # blank). Use it for any closed-vocabulary boundary input: interval
18
- # selectors, status filters, UTM tags, feature-flag names.
23
+ # Degrade-vs-raise is decided by the REQUEST METHOD:
24
+ # - GET/HEAD: unrecognised values quietly degrade to +default+ — crawlers
25
+ # and bots probe read endpoints with garbage, and a filter page must not
26
+ # 500 on `?mode=garbage`.
27
+ # - Mutating requests (POST/PATCH/PUT/DELETE): a PRESENT-but-unrecognised
28
+ # value raises UnrecognizedValue (see above) — this is how a forgotten
29
+ # allow-list entry announces itself instead of hiding.
30
+ # Blank/missing values fall through to +default+ quietly on EVERY method
31
+ # (forms legitimately post no value; no symbol's string form is blank).
32
+ #
33
+ # +allowed_symbols+ may also contain strings (e.g. a Rails enum's `.keys`)
34
+ # — the matched entry is symbolized on the way out, so the return value is
35
+ # ALWAYS a symbol (or +default+). That `to_sym` runs only on the
36
+ # developer-controlled list entry, never on +value+, so the DoS-safety
37
+ # above is unaffected.
19
38
  def glib_allowlist_symbol_param(value, allowed_symbols, default:)
20
- allowed_symbols.find { |symbol| symbol.to_s == value.to_s } || default
39
+ match = allowed_symbols.find { |symbol| symbol.to_s == value.to_s }&.to_sym
40
+ return match if match
41
+
42
+ if value.present? && !request.get? && !request.head?
43
+ raise UnrecognizedValue,
44
+ "Unrecognised #{request.request_method} param value #{value.to_s.truncate(80).inspect} " \
45
+ "(allowed: #{allowed_symbols.map(&:to_sym).inspect})"
46
+ end
47
+
48
+ default
21
49
  end
22
50
  end
23
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.2
4
+ version: 5.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''