-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add escaping to the static 404 page. #1645
Conversation
I can't reproduce, can you show code or add a test?
|
Hi @dentarg. Apologies for not including detailed enough reproduction steps. I didn't realize WEBrick would not allow a URI with angle brackets in (probably a sensible decision on their part). I was using Unicorn in my testing, which does allow this URL. With your example above, if I add $ echo "gem \"unicorn\"" >> Gemfile
$ bundle install
...
$ export RACK_ENV=production # To enable the production error pages rather than the development one which already fixed in #883.
$ bundle exec unicorn --port 9292
... Then the Curl commands should return the expected results. $ curl "http://localhost:9292/a<script>"
GET /a<script>
$ curl "http://localhost:9292/a<script>"
GET /a<script> I attempted to include a test, but unfortunately the testing framework also considers the URL invalid which makes it a bit tricky to test.
Thanks for your quick reply! :) |
Thanks, this looks like a good update to me. @namusyaka what do you think? |
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.
Looks reasonable.
In that case the content-type will be text/plain but we should not depend on browsers respecting the content-type header for the security.
However, please try to test this behavior. You'll be able to reproduce the case by the following:
env = Rack::MockRequest.env_for("/dummy").tap { |env| env['PATH_INFO'] ='/<script>' }
Thanks @namusyaka, that's a neat trick. I don't think the content type is
|
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.
Thanks!
Interesting that while you were fixing this you didn't realize that including #1566 was not a good idea in the first place... |
This change escapes exception messages on error pages for "not found" and "bad request" errors when serving static content. In particular the message for 404 errors contains the request method and path which are user controlled and should probably be escaped.
This isn't really that exploitable because the path will be URL encoded when being requested by any sane browser, but it seems better to be safe and escape it anyway.
Example error page before the change:
Example after: