-
Notifications
You must be signed in to change notification settings - Fork 394
AppSec: Fix undefined method request_method=
#4870
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
👋 Hey @marcotc, please fill "Change log entry" section in the pull request description. If changes need to be present in CHANGELOG.md you can state it this way **Change log entry**
Yes. A brief summary to be placed into the CHANGELOG.md (possible answers Yes/Yep/Yeah) Or you can opt out like that **Change log entry**
None. (possible answers No/Nope/None) Visited at: 2025-08-27 01:37:49 UTC |
|
BenchmarksBenchmark execution time: 2025-08-27 02:07:16 Comparing candidate commit 69b1fa1 in PR branch Found 2 performance improvements and 2 performance regressions! Performance is the same for 40 metrics, 2 unstable metrics. scenario:line instrumentation - targeted
scenario:method instrumentation
scenario:profiling - stack collector (ruby frames - native filenames enabled)
scenario:tracing - Tracing.log_correlation
|
pattern = request.env[RAILS_ROUTES_KEY].router | ||
.recognize(request) { |route, _| break route.path.spec.to_s } | ||
route_set = request.env[RAILS_ROUTES_KEY] | ||
rails_request = route_set.request_class.new(request.env) |
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.
Hey @marcotc, thanks for taking care of that. We don't have grape
contrib, but there was a plan to start supporting it as main API framework.
The init of the router will generate new instance with unprocessed env, could you please explain what is the actual issue here of using stored router?
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.
The main issue is that recognize(request)
expects a wrapped ActionPack request, not a raw Rack request, and it throws the error undefined method request_method=
when running.
Thankfully this is easy to reproduce in tests (which are being added).
Tbh, I only really have to fix the Rails issue today, but I noticed that the Grape and Sinatra paths were not tested in integration tests (which the the only way to trigger the Rails failure today), so I started adding them in this PR as well.
Still WIP though!
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.
🤔 Hmmm, we have tested it with Rails and we decide to scope out Sinatra to system tests, but both working. In which case it do you get that error?
If it happens solely in tests like an old "integration" test we poses, than I would challenge the quality of the test.
We also have a test app where I run it across different Rails app versions.
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.
BTW, here are integrations tests that will use route extraction (but not on all Rails versions)
If you don't mind could you share the error case you are fixing? I would love to help on this.
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.
I think I get the issue now, problem starts not because sampling window, but because the HEAD
request. It will take a path into the router which will assign the method into it to be able to find it across the available routes.
Rails will try to modify the request in order to find it.
As a suggestion, to avoid this expensive path, could we wrap the request only for this specific scenario of HEAD request then?
What does this PR do?
Motivation:
Change log entry
Additional Notes:
How to test the change?