gapic-common 1.4.0 → 1.4.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: 6dbc3fc8f2b53d01d228f377851d21d941cedd307a9528e7ba732c5e8d2565e2
4
- data.tar.gz: d6ded505cf91783149b49373f2efb2ef105860705a22f2940c27f6b27d83be39
3
+ metadata.gz: 11f04f82fc6e98e5ca24d814d6162d68681999b6a7f2305cc32c77c597db2a88
4
+ data.tar.gz: a36c758ffd65878ac9809c0ecfc515e2c6e0e817f5ad679e8574e5dbeb8a03f6
5
5
  SHA512:
6
- metadata.gz: e7533c44cae4643cec30b87e96fc61750ca2ba2a3458c711788d51987436b25ca3248f6c8d011cf06a00992eec4458e3403ac0b64850a43d153368cd3a6c0203
7
- data.tar.gz: cd51bd91e418f8d5c71c3f6e484b29f4c420121b14baca686309f074928162f97c0259555bd32d28cb6e747a397c99c0e3d5aeb6cd99085d309ed61482af7cfa
6
+ metadata.gz: 8fb7d4c578dc4b44383ac18e33159fd824465e63df13b10ed2d2fe142c4a9743876d7a3a41cd00680dc3e44cab88f6d3d6185198a8b74a85ace1ff30ee6d9e4e
7
+ data.tar.gz: 3d508937a578e43a1fe8022557d08a7c01be477b9141a1d055c0d6a1df8e739eca0a9e2f14d178aa90c4b121d44dd12e437d73242250009916645948238af388
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 1.4.1 (2026-09-28)
4
+
5
+ #### Bug Fixes
6
+
7
+ * validate path parameters and prevent traversal/injection in REST transcoder ([#67](https://github.com/googleapis/ruby-core-libraries/issues/67))
8
+
3
9
  ### 1.4.0 (2026-09-23)
4
10
 
5
11
  #### Features
@@ -14,6 +14,6 @@
14
14
 
15
15
  module Gapic
16
16
  module Common
17
- VERSION = "1.4.0".freeze
17
+ VERSION = "1.4.1".freeze
18
18
  end
19
19
  end
@@ -111,12 +111,14 @@ module Gapic
111
111
  # @return [Hash{String, String}]
112
112
  # Name to value hash of the variables for the uri template expansion.
113
113
  # The values are percent-escaped with slashes potentially preserved.
114
+ # @raise [Gapic::Common::Error] If any parameter value fails path traversal or injection validation.
114
115
  def bind_uri_values! http_binding, request_hash
115
116
  http_binding.field_bindings.to_h do |field_binding|
116
117
  field_path_camel = field_binding.field_path.split(".").map { |part| camel_name_for part }.join(".")
117
118
  field_value = extract_scalar_value! request_hash, field_path_camel, field_binding.regex
118
119
 
119
120
  if field_value
121
+ validate_field_binding! field_binding, field_value
120
122
  field_value = field_value.split("/").map { |segment| percent_escape segment }.join("/")
121
123
  end
122
124
 
@@ -124,6 +126,43 @@ module Gapic
124
126
  end
125
127
  end
126
128
 
129
+ # Validates a user-supplied parameter value bound to a standard (*) or path (**) URI template variable
130
+ # to prevent directory traversal exploits.
131
+ #
132
+ # @param field_binding [HttpBinding::FieldBinding] The field binding template metadata.
133
+ # @param field_value [String] The parameter value to validate.
134
+ # @raise [Gapic::Common::Error] If validation fails.
135
+ def validate_field_binding! field_binding, field_value
136
+ validate_path_binding! field_binding, field_value
137
+ end
138
+
139
+ # Validates standard (*) and path (**) parameters by ensuring that no segment in the parameter
140
+ # value is a directory traversal segment (. or ..).
141
+ #
142
+ # Validation Mechanism:
143
+ # 1. Splits the parameter value by slash (`/`) using `-1` limit to preserve all segments.
144
+ # 2. Checks each segment. If any segment matches `.` or `..`, it immediately raises
145
+ # a `Gapic::Common::Error`, aborting the request.
146
+ # 3. Empty segments (e.g. duplicate slashes `//` or trailing slashes `/`) are allowed
147
+ # by this validator and passed to the server, which handles normalization or returns 400.
148
+ #
149
+ # @param field_binding [HttpBinding::FieldBinding] The field binding template metadata.
150
+ # @param field_value [String] The parameter value to validate.
151
+ # @raise [Gapic::Common::Error] If validation fails.
152
+ def validate_path_binding! field_binding, field_value
153
+ segments = field_value.split("/", -1)
154
+ segments.each do |segment|
155
+ next unless [".", ".."].include? segment
156
+ if field_binding.preserve_slashes
157
+ raise ::Gapic::Common::Error,
158
+ "Value for #{field_binding.field_path} must not contain segments that are exactly '#{segment}'."
159
+ else
160
+ raise ::Gapic::Common::Error,
161
+ "Invalid value for #{field_binding.field_path} '#{segment}'."
162
+ end
163
+ end
164
+ end
165
+
127
166
  # Percent-escapes a string.
128
167
  # @param str [String] String to escape.
129
168
  # @return [String] Escaped string.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gapic-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google API Authors