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

Option to redirect to exact service url #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

pradtke
Copy link
Collaborator

@pradtke pradtke commented Aug 29, 2019

Some clients will encode query parameters in their service url incorrectly.
If SSP/php's query builder utils are used then the service url is parsed,
and reconstructed differently then what is stored in the ticket. Sometimes
badly encoded parameters are lost.

Example: should space in a query param be encoded as '+' or '%20'

@pradtke pradtke requested a review from tvdijen August 29, 2019 16:16
@tvdijen
Copy link
Member

tvdijen commented Aug 29, 2019

Code-wise I have no remarks, but not sure if we should jump through flaming hoops to facilitate bad client-behaviour...

@pradtke
Copy link
Collaborator Author

pradtke commented Aug 29, 2019

Thanks for the read through. As to whether the module should support this... we ( Cirrus ) need to have more parity between this module and the behavior of Shib CAS and Jasig CAS since we've transitioned customers from both of those to SSP, and this is one area where we've encountered issues. Also seems like other people have addressed it with their own local patches (https://groups.google.com/forum/#!searchin/simplesamlphp/cas|sort:date/simplesamlphp/2J7BxXsVfkk/zzRttynxBAAJ).

@tvdijen
Copy link
Member

tvdijen commented Aug 29, 2019

Is there a way we can detect this case and automate the fix, instead of adding a config flag?
If not, then let's merge it as is..

@pradtke
Copy link
Collaborator Author

pradtke commented Aug 29, 2019

I guess one could argue, why are we (in the HTTP utils) even parsing and re-encoding the provided url rather than just redirect back to it? For example if the client provided a valid query string with param=abc%20efg then our default behavior is to change that to param=abc+efg. Which is valid? Well, depends which RFC you're reading. It's ambiguous.
I originally thought this could be fixed during validation, by doing the same re encoding of the urls before comparison (much like the code removes the jsessionid path param). That would work fine for the above case, since the information is preserved. There is another case where the query parameter in the service url contains a '?', and the query parser in HTTP utils is not smart enough, and part of the query is dropped when we respond resulting in a url on the service that is missing a value. That can't be fixed at the serviceValidate time.

I suspect we will make this flag 'on' for all our deployments (eventually).

@pradtke
Copy link
Collaborator Author

pradtke commented Aug 29, 2019 via email

@tvdijen
Copy link
Member

tvdijen commented Aug 30, 2019

Well, we could consider adding an enc_type to the http_build_query call in HTTP::addURLParameters? Would that solve your problem? Perhaps @jaimeperez has a suggestion...

One thing I overlooked last night is that you're changing the default behaviour here by defaulting the new option to false.. We shouldn't do that..

@jaimeperez
Copy link
Member

I share your pain @pradtke, but at the same time it makes me slightly nervous to introduce complexity just to deal with entities not working properly...

@pradtke pradtke force-pushed the bug/re-encode-workaround branch from fa13ceb to d64485f Compare August 30, 2019 16:45
@pradtke
Copy link
Collaborator Author

pradtke commented Aug 30, 2019

I think my describing this as buggy client was a bad idea.... buggy client is not the only cause.
It also can be caused by bugs in HTTP::addURLParameters()
For example:

  1. If a valid client request contains a query parameters a=val1&a=val2 with multiple values for a key, then HTTP::addURLParameters() only preserves one of those values.
  2. If a client submits a request with a service url containing a fragment (#), then HTTP::addURLParameters() adds the ticket to the fragment and not to the query parameters which come before the fragment seems to remove the fragment.
  3. the ambiguous ways a ' ' can be encoded, as described earlier

@tvdijen
Copy link
Member

tvdijen commented Aug 30, 2019

1 & 2 we should be able to fix..
3rd is depending on the RFC you follow.. We could add an extra parameter to HTTP::addURLParameters to make it a bit more flexible in this matter.. However, we would have to detect what RFC was used on the received URL..

@pradtke
Copy link
Collaborator Author

pradtke commented Sep 16, 2019

We've been analyzing our CAS service urls the last two weeks and there is one more case where there is ambiguity in re-encoding, specifically if percent encodings are case sensitive. Some .net based clients use lowercase percent encodings, while if php re-encodes the query parameter it uses upper case, resulting in a mismatch.

@tvdijen tvdijen force-pushed the master branch 2 times, most recently from 656286c to c53489f Compare November 16, 2019 21:42
Some clients will encode query parameters in their service url incorrectly.
If SSP/php's query builder utils are used then the service url is parsed,
and reconstructed differently then what is stored in the ticket. Sometimes
badly encoded parameters are lost.

Example: should space in a query param be encoded as '+' or '%20'
@pradtke pradtke force-pushed the bug/re-encode-workaround branch from d64485f to 3a818c2 Compare January 16, 2020 04:04
There are too many cases where SSP's redirect changes the service url in ways
that make future exact matches fail. As such change is to always user the alternate
method.
@pradtke
Copy link
Collaborator Author

pradtke commented Jan 16, 2020

I've rebased changes on master, adjusted some of the test and comments to reflect encoding issues with lower case hexadecimal and multiple query params with the same name (not just badly encoded urls). I also removed the option to use the old behavior (have SSP re-encode the url) since that encodes problematically in about 1% of our traffic (about 500,000 cas logins across ~10 schools since the PR was created). The newer way (similar to Jasig's CAS server's way) handle the traffic without issue. @tvdijen If your feelings on having this merged in have changed since the summer, let me know and I'll do a squash and merge. If you still think it shouldn't be merged then I'll leave it here as a PR so that anyone else encountering similar issues can download and apply as a patch. thanks

@tvdijen
Copy link
Member

tvdijen commented Jan 16, 2020

I'd like to know what @jaimeperez feels about solving 1 & 2 in SSP..

@tvdijen tvdijen force-pushed the master branch 8 times, most recently from 8ea49c8 to aa07206 Compare February 19, 2020 22:20
@tvdijen
Copy link
Member

tvdijen commented Dec 2, 2021

How relevant is this in 2021? Not sure why the tests fail either

@pradtke
Copy link
Collaborator Author

pradtke commented Dec 13, 2021

I reviewed our traffic from today and both Banner and Kuali still send CAS service urls that are "weird" in some way, and require the workaround. I'm unsure if this is because those apps still run the same version as in 2019, or an updated version with the same bugs.

We run all our customers with this patch (or some variation of it) enabled.

I can look at the cause of the PR checks failure, but probably won't have the time till January.

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

Successfully merging this pull request may close these issues.

3 participants