Skip to content
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

WIP: Bypass URI as path only if absolute for OPTIONS #74

Merged
merged 4 commits into from
Oct 14, 2019

Conversation

webknjaz
Copy link
Member

@webknjaz webknjaz commented Jan 26, 2018

I'm not sure whether it's right from the RFC point of view, but this allows to put path w/o query-string into PATH_INFO in case of origin-form.

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Bug fix (possibly)

  • What is the related issue number (starting with #)
    cherrypy/cherrypy#1662

  • What is the current behavior? (You can also link to an open issue here)
    PATH_INFO in WSGI env is assigned URI as is if proxy is enabled.

  • What is the new behavior (if this is a feature change)?
    PATH_INFO is assigned to path part if URI is not absolute.


This change is Reviewable

@webknjaz webknjaz requested review from jaraco, a team and josephtate January 26, 2018 23:29
@webknjaz
Copy link
Member Author

@bertjwregeer @josephtate @jaraco Could you please share your opinion regarding RFC compliance?

@codecov
Copy link

codecov bot commented Jan 26, 2018

Codecov Report

Merging #74 into master will decrease coverage by 0.51%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master      #74      +/-   ##
==========================================
- Coverage   76.87%   76.35%   -0.52%     
==========================================
  Files          24       24              
  Lines        3770     3769       -1     
==========================================
- Hits         2898     2878      -20     
- Misses        872      891      +19

@digitalresistor
Copy link

That change looks fine to me from a RFC perspective.

@webknjaz
Copy link
Member Author

@bertjwregeer thanks.
What about proxy_mode? Maybe it's better to raise an error when there's no absolute path present?

@webknjaz
Copy link
Member Author

Here's what I think:

  • If we expect it to act like proxy, there's not enough info if only origin-form is present in Request-Line. absolute-form is needed for proxy to know where to connect to. So in case of enabled proxy mode I'd raise an error if absolute-form validation fails.
  • It should be okay to set PATH_INFO to absolute-path in case of disabled proxy mode, but
    • RFC encourages to accept absolute-form for all queries and instructs servers implementing Virtual Hosts to override Host header with a host from absolute-form. It looks like this should be handled on another level, but WSGI requires to have just absolute-path part there.
  • Based on that, I'd just turn off proxy mode in cherrypy adapter.

@jaraco
Copy link
Member

jaraco commented Feb 4, 2018

I'm okay with this change. Will be good to stabilize the behavior reported in the ticket.

@webknjaz
Copy link
Member Author

webknjaz commented Feb 4, 2018

Actually, I'm not okay with it now:) But haven't had time to put a new patch together

@webknjaz webknjaz changed the title Bypass URI as path only if absolute for OPTIONS WIP: Bypass URI as path only if absolute for OPTIONS Feb 4, 2018
@stale

This comment has been minimized.

@stale stale bot added the stale This thing has been ignored for too long label Apr 5, 2018
@danlamanna
Copy link

danlamanna commented Apr 6, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thlank you for your contributions.

I would be sad to see this issue/PR fall off the radar since it's caused us to pin CherryPy to an older version in our downstream project (https://github.com/girder/girder/).

Seeing as how the related issue has broken long lived expectations of CherryPy's handling of OPTIONS requests, is it possible to get this patched in the meantime?

@stale stale bot removed the stale This thing has been ignored for too long label Apr 6, 2018
@webknjaz
Copy link
Member Author

webknjaz commented Apr 9, 2018

@danlamanna I need to re-do this patch in order to have it merged. I just didn't have time for this. I wish there were more maintainers who could help.

@stale

This comment has been minimized.

@stale stale bot added the stale This thing has been ignored for too long label Jul 5, 2018
@digitalresistor
Copy link

Stale bot... go away. This is still an issue.

@stale stale bot removed the stale This thing has been ignored for too long label Jul 6, 2018
@webknjaz webknjaz added the bug Something is broken label Jul 16, 2018
@webknjaz
Copy link
Member Author

Now bot won't close it with actual bug label.

@webknjaz
Copy link
Member Author

webknjaz commented Sep 6, 2018

@jaraco should we think of deferring HTTP parsing to https://github.com/python-hyper/h11?

@fviard
Copy link

fviard commented Jan 17, 2019

Hi, today I encountered this issue also using cherrypy and just trying to use query params...
That would be nice if that could be fixed soon... And also if there was a "hack" that can be used with existing versions.
FYI, applying the fix proposed here solve my issue.
thanks

@ian-otto
Copy link
Contributor

@fviard You're going to end up using a version of cheroot that is not RFC compliant, so you might have some user agents that misbehave and/or introduce yourself to various vulnerabilities.

if self.method == b'OPTIONS':
# TODO: cover this branch with tests
path = (
uri
# https://tools.ietf.org/html/rfc7230#section-5.3.4
if self.proxy_mode or uri == ASTERISK
if (self.proxy_mode and uri_is_absolute_form)
or uri == ASTERISK
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this line can be eliminated as urllib.parse.urlsplit('*').path == '*' anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in dc9592b.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaraco where did you see urllib.parse.urlsplit('*').path == '*'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I don't see any code checking for ASTERISK now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this change is wrong. And the problem with this PR was this hack: https://github.com/cherrypy/cherrypy/blob/535605c/cherrypy/_cpwsgi_server.py#L31

It was temporary until this PR's figured out (cherrypy/cherrypy@c87bc9f). We should revert it to proxy_mode=False now and see if it's ok.

@jaraco jaraco merged commit 02f7a17 into master Oct 14, 2019
@jaraco jaraco deleted the bugfix/options-path-processing branch October 14, 2019 22:27
@webknjaz
Copy link
Member Author

FTR I recall there have been some corner cases there in conjunction with CherryPy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants