THREESCALE-15318: Update Faraday dependency for enhanced query parameter handling#4330
Conversation
Update Faraday version constraint to allow >= 2.14.3 to address improvements in nested query string handling. The Faraday library has enhanced its query parameter processing in version 2.14.3, providing better safeguards against deeply nested structures. Changes: - Updated Gemfile to require faraday ~> 2.0, >= 2.14.3 - Added test for nested query parameter handling - Included patch for pisoni dependency update Note: This change requires pisoni gem to be updated first. The patch file THREESCALE-15318-pisoni-update.patch contains the necessary changes for pisoni.gemspec. Testing: Added test case for deeply nested parameter handling Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
|
||
| gem 'dalli' | ||
| gem 'faraday', '~> 2.0', '<= 2.9' | ||
| gem 'faraday', '~> 2.0', '>= 2.14.3' |
There was a problem hiding this comment.
Shouldn't we limit range to 2.x?
There was a problem hiding this comment.
The ~> 2.0 constraint already limits to 2.x (it's equivalent to ">= 2.0, < 3.0"). So faraday '~> 2.0', '>= 2.14.3' means any 2.x version starting from 2.14.3.
There was a problem hiding this comment.
This file seems to be totally useless here
There was a problem hiding this comment.
You're right, removed it.
There was a problem hiding this comment.
This is a good test to make sure the updated faraday works as advertised. But maybe no need to add tests for gems in our project
There was a problem hiding this comment.
Good point! I can remove the test if you prefer.
The test serves two purposes:
- Regression prevention: Ensures we don't accidentally downgrade to a vulnerable Faraday version in the future
- Documentation: Shows why we have the >= 2.14.3 constraint (without mentioning CVEs in code)
However, you're right that testing gem behavior isn't really our responsibility - we trust the gem's own tests. Would you prefer I remove it and just rely on the Gemfile constraint?
There was a problem hiding this comment.
yes, remove the test file.
There was a problem hiding this comment.
Done, removed.
|
No Gemfile.lock change? |
- Use string interpolation instead of concatenation - Remove unused block variable - Add parentheses for hash literal clarity
|
The Gemfile.lock is not updated in this PR because the pisoni gem dependency constraint blocks the upgrade. Once pisoni PR #36 (3scale/pisoni#36) is merged and a new pisoni version is released, I'll update the Gemfile.lock to use the new versions of both pisoni and faraday. The current workflow:
Would you prefer I update the Gemfile.lock now to show what it will look like, or wait until pisoni is released? |
The patch is no longer needed since pisoni PR #36 has been created. The dependency update will happen via the pisoni gem release.
|
Also removed the |
|
Hi @akostadinov-bot, are you as annoying as the original @akostadinov? What do you think about the method |
Removed per review feedback - no need to test gem behavior in our project.
|
@jlledom Ha! I'll try to be just the right amount of annoying. As for |
…1.31.0 Update pisoni constraint to ~> 1.31 to pull in v1.31.0 which relaxes the faraday upper bound. This allows faraday to resolve to 2.14.3. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Gemfile.lock is now updated — pisoni 1.31.0 is released, so the lockfile resolves to faraday 2.14.3 and pisoni 1.31.0. Also updated the pisoni constraint from |
The uri gem 1.1.1 (pulled in transitively by net-http) changed DEFAULT_PARSER to RFC3986_Parser which no longer exposes #pattern. Use RFC2396_Parser explicitly since the code relies on RFC2396 pattern keys (QUERY, ABS_PATH, HOSTNAME). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c79e8f3
| validates :error_status_no_match, :error_status_auth_missing, :error_status_auth_failed, :error_status_limits_exceeded, presence: true | ||
|
|
||
| uri_pattern = URI::DEFAULT_PARSER.pattern | ||
| uri_pattern = URI::RFC2396_Parser.new.pattern |
There was a problem hiding this comment.
I faced this same problem in #4325. And this solution doesn't work.
The problem is uri switched the default parser to RFC3986 (ruby/uri#107) at all effects. That means that changing this single line causes an inconsistency because the rest of the gem is still defaulting to RFC3986 for all other operations. For instance, all calls to URI.parse would use a different pattern, where the registry field doesn't exist. All other URI methods will use DEFAULT_PARSER internally...
In my PR, what I did it to remove the reference to the uri gem from the lockfile. It works because ruby 3 already includes uri 0.13.3 builtin, which still uses the old parser and satisfies faraday dependenciy, which is >= 0.11
Another problem is the URI.decode method raises an undefined method error. This was broken when we updated ruby to version 3 in porta.
As you may see, the issue is bigger than expected and deservers its own Jira ticket for investigation and careful testing. For this pr, just don't touch the uri gem.
There was a problem hiding this comment.
Makes sense. But I'd add the dependency with a comment to Gemfile, otherwise the nect bundle install may bring it back as it happened right now.
Also is there any reason not to use the newer RFC parser? We can in general switch the default back too as evident in the issue you linked to
URI.parser = URI::RFC2396_PARSERThere was a problem hiding this comment.
I think it's not gonna be so easy.
URI.parser = URI::RFC2396_PARSER
This wouldn't work if we are mentioning DEFAULT_PARSER somewhere else in the code, like in the problematic call to .pattern in the proxy module. Also we are using the registry field which doesn't exist in the new RFC, and calling the decode metho which is undefined. Maybe changing a couple of lines would fix it, but it would require some time to test and investigate, to ensure we are not breaking anything. I think is not something to do quick and dirty in the middle of an unrelated PR.
There was a problem hiding this comment.
I already said that I agree that a separate JIRA is needed. The question was whether we actually need the old parser or is it just how it worked for a long time so we don't want to fix it as it ain't broken.
The DEFAULT_PARSER call we don't use elsewhere according to grep. Idk why the other two things didn't manifest. But anyway, just capturing existing knowledge for the JIRA.
Bug Fix:
|
The Faraday/pisoni update pulled in connection_pool 3.0.2, which changed
ConnectionPool#with from accepting a positional hash to keyword-only
arguments. redis-client 0.22.2 still calls pool.with({}) causing
ArgumentError: wrong number of arguments (given 1, expected 0) inside
redlock's lock_instances — breaking all Redis-based lock acquisition
including the billing NowaitLockService.
Pin connection_pool to 2.x until redis-client is upgraded to a version
that uses keyword arguments (0.26.3+).
Assisted-By: claude-opus-4-6
| gem '3scale_client', '~> 2.11', require: false | ||
| gem 'analytics-ruby', require: false | ||
|
|
||
| gem 'connection_pool', '~> 2.2', '< 3' |
There was a problem hiding this comment.
What if you just remove this and leave the reference to connection_pool un the lockfile untouched? I don't like the idea of adding dependencies to our Gemfile when they are not our dependencies
There was a problem hiding this comment.
Then the next bundle install may bring it back. I'd rather put a comment unless you give me a better alternative.
| rack | ||
| unicorn | ||
| uniform_notifier (1.17.0) | ||
| uri (1.1.1) |
There was a problem hiding this comment.
You can remove this one and let bundle pick the builtin ruby 3 gem which is 0.13.3, This way you solve the URI parser problem.
uri >= 1.0.0 switched the default parser from RFC2396 to RFC3986 (ruby/uri#107), removed URI::DEFAULT_PARSER, dropped URI.decode, and the RFC3986 parser has no `registry` component. We rely on all of these across models (Proxy, ProxyRule, WebHook, AuthenticationProvider) and controllers. Upgrading requires careful inspection of every call-site and should be deployed/tested separately. Revert the proxy.rb workaround (RFC2396_Parser.new) since the built-in DEFAULT_PARSER works with uri < 1.0.0. Also add explanatory comments to the connection_pool pin, noting that upgrading hiredis-client + redis-client to >= 0.26.3 would allow removing it. Assisted-By: claude-opus-4-6 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
wdyt about this now? does it make more sense? Not ideal I understand but I'm wondering what would be least confusing for our future selves. |
Fine for me. Have you created the issue? Have the link? |
It is just part of generic task to keep our deps up-to-date. Do we need to file formal issues for individual ones? |
I think this one in particular would need a Jira issue to explain the background. |
Summary
This PR updates the Faraday gem dependency constraint to allow version 2.14.3 and above, which includes improvements to nested query parameter handling.
Changes
Gemfileto requirefaraday ~> 2.0, >= 2.14.3test/unit/faraday_nested_params_test.rbDependencies
Important: This change depends on updating the
pisonigem first. The required changes for pisoni are provided in the patch fileTHREESCALE-15318-pisoni-update.patch.The pisoni gem currently constrains Faraday to
<= 2.9. This constraint needs to be updated to>= 2.14.3to allow this change to be applied.Testing
Added test case that verifies handling of deeply nested query parameters without causing stack overflow issues.
Background
Faraday 2.14.3 includes enhancements to query parameter processing that provide better safeguards against deeply nested parameter structures. This update ensures the application benefits from these improvements.
Related: THREESCALE-15318