-
Notifications
You must be signed in to change notification settings - Fork 1.7k
#2346 Fix problem with downstream URLs where query parameter names get messed up if they contain a placeholder that has a non-empty value #2351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Right! It was my fault when releasing the Ocelot 23.4.3 patch. Sometimes, when you solve a big problem, there’s a chance you might introduce a small, unexpected one 👶 My idea to use the IQueryCollection query = context.Request.Query;
bool exists = query.ContainsKey(name) && query.TryGetValue(name, out var pvalue) && pvalue == nAndV.Value;
if (!exists) // !downstreamRequest.Query.Contains(parameter)
{
continue;
}To do that, we just need an additional
|
raman-m
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this solution should fix the bug, it looks like we still need more thorough unit testing with different URLs. Additionally, the lack of acceptance tests is preventing me from approving this version of the bugfix.
Let’s work on finding the optimal solution, as this is a critical middleware for the routing feature. I recommend spending more time refining the approach.
src/Ocelot/DownstreamUrlCreator/DownstreamUrlCreatorMiddleware.cs
Outdated
Show resolved
Hide resolved
test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs
Outdated
Show resolved
Hide resolved
…eBeenUsedInTemplate Logic
src/Ocelot/DownstreamUrlCreator/DownstreamUrlCreatorMiddleware.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yahoo! The rodeo goes on! 🤠
Did you notice the CI build failed? No rush, though I'm planning to revert the last commit 21661a4.
You're a talented vibe-coder, and the new algorithm seems solid and will handle query strings properly, but instead of the old 10 lines, we now have 30 lines of code proposed by the AI coding agent. This version will heavily consume RAM due to two new collections in the algorithm. Honestly, I prefer the previous Regex-based version since it's better to use more CPU cycles than to increase RAM usage. Have you seen how expensive RAM modules are these days? 😉
I had tried out #2351 (comment) suggestion but after applying other testcases are getting failed. I have refactored code and added more test Cases.
You've added new unit tests generated by the AI coding agent but wrote no acceptance tests. And you didn't run the tests locally, so now the old Routing acceptance tests are failing 👇

Sorry, the last commit will be reverted because the old Regex version is more suitable.
src/Ocelot/DownstreamUrlCreator/DownstreamUrlCreatorMiddleware.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/DownstreamUrlCreator/DownstreamUrlCreatorMiddleware.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/DownstreamUrlCreator/DownstreamUrlCreatorMiddleware.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/DownstreamUrlCreator/DownstreamUrlCreatorMiddleware.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/DownstreamUrlCreator/DownstreamUrlCreatorMiddleware.cs
Outdated
Show resolved
Hide resolved
|
@raman-m I have refactored the code based on your suggestions and also made a few additional changes to address the failing test cases that appeared after applying them. |
|
It is great if the unit tests and old acceptance tests are now passing. |
|
@raman-m Added new acceptance tests |
Ready for code review ✔️ |
raman-m
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready for delivery ✅
- Code review ✔️
- Unit testing ✔️ ✔️
- Acceptance testing ✔️ ✔️
Fixes #2346
Background
After upgrading to Ocelot 23.4.3, query parameters whose names contain the substring
id(e.g.,customer_id) are incorrectly rewritten or corrupted if another route exists with a{id}path parameter. See #2346 for details and repro steps.Problem
When Ocelot tries to remove consumed query string parameters from the downstream request, it was using a simple string
Containscheck. This caused substring matches (like theidincustomer_id) to be incorrectly interpreted as route tokens—resulting in corruption (e.g.,customer_id=5172980becomingcustomer5172980).Solution
Changed logic in
RemoveQueryStringParametersThatHaveBeenUsedInTemplateto use a Regex match instead of stringContains.This ensures only exact parameter matches are identified and removed, and substrings like
idincustomer_idare preserved correctly.How to Reproduce
See steps in #2346:
/finance/v1/payment-methods/{id}/finance/v1/payment-methods/finance/v1/payment-methods?customer_id=5172980Testing
customer_id=5172980are now correctly forwarded downstream without corruption.dotnet test).Checklist
develop