Skip to content

Conversation

@jesslilly
Copy link

Hi Alexej,

I think I did the pull request correctly this time. The fix you merged in from doeringp does not pass the unit tests I made. We must still call UrlDecode so that "new Uri" will work correctly. I did use doeringp's good idea to use a dummy.com host since it just makes the URI parsing easier and uses less code. Does not rely on parsing for a question mark.

Also I like having these tests. I the other tests in the solution do not cover this issue.

image

When I add decode back, the new tests pass.

image

Also, there should be a comment why we use a dummy URL.

Thank you. I hope this PR is merged. 😄

[Fact]
public void GetSignInRequestMessage_parses_url_query_correctly()
{
var encodedUrl = "%2Fwsfederation%3Fwtrealm%3Drealm%26wa%3Dwsignin1.0%26wreply%3Dhttps%253A%252F%252Flocalhost%253A44310%252Fsignin-wsfed%26wctx%3DCfDJ8N3n";
Copy link
Owner

Choose a reason for hiding this comment

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

Your tests did not pass because the URL you pass in your tests is not like it would be passed when you would use the library. It would be rather like this "/WsFederation?wtrealm=urn%3Aaspnetcorerp&wa=wsignin1.0&wreply=http%3A%2F%2Flocalhost%3A10314%2F&wctx=CfDJ8H09lVj2W7VEs5pRor8gYi8GmcbmE1K-5wiTeL1pozxPOJ3rkb-SeD5X-YzLYNtr1UrkAAHIkMyZaGNDJ2B_OVdO9KixFMcmiY2UGm7JXMbYM47UBM2-XgZFoSsEJGPO8eXVPGxiNBINF1fC2qjJ9MI9oYmHcLY79wz3lG0XcVFq5lR8CNiX6BAIRBWRZC7Wj3Ur1YmsH3DZXvtcRzxRKQN6_QytWYwRGA9_BEc7ezHjVae05RN4NdA165pd8IzYeg". You can try it yourself when you run the samples and step in with a debugger.

Copy link
Author

Choose a reason for hiding this comment

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

The strange thing is that I got the values directly from my debugger. I did "copy value".

Copy link
Owner

Choose a reason for hiding this comment

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

I think your IDE somehow URL encode the value, that's why it is wrong. If you think about it the "/WsFederation" is the path for the server to interpret, why should it be URL encoded?

{
public static WsFederationMessage GetSignInRequestMessage(string encodedUrl)
{
var decodedUrl = WebUtility.UrlDecode(encodedUrl);
Copy link
Owner

Choose a reason for hiding this comment

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

this is not necessary WsFederationMessage.FromUri() takes care of things that need to be decoded.

public static WsFederationMessage GetSignInRequestMessage(string encodedUrl)
{
var decodedUrl = WebUtility.UrlDecode(encodedUrl);
// Fix: Add dummy.com host so Uri can properly parse out the query string.
Copy link
Owner

Choose a reason for hiding this comment

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

agree on that 👍

@616b2f
Copy link
Owner

616b2f commented Mar 1, 2021

Thank you for your PR, I think your tests could be a good addition to our unit tests, here are really not much of them at the moment and I would be happy to merge if you resolve my concerns in comments.

@jesslilly
Copy link
Author

No problem Alexej. I will try again.

@jesslilly
Copy link
Author

Haha. Hi again @616b2f . For some reason I thought we were speaking different languages, but now I figured out why I get encoded URLs. It is because my IdentityServer implementation never decodes the URL before it is passed to IsValidReturnUrl. (I did not implement IdentityServer myself. I have inherited this project.)

In this picture you can see the encoded URL and it is passed as encoded all the way down the call stack.

image

I am surprised because the code for WebUtility.UrlDecode was in the source code before. So it must have been needed.

WsFederationMessage.FromUri does not decode by itself as seen in the implementation here:

https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/bbf721fedca5dabc0d77e22828a5948be0d3fa86/src/Microsoft.IdentityModel.Protocols.WsFederation/WsFederationMessage.cs#L84

Also I added a throw new NotImplementedException(); as the first line in GetSignInRequestMessage. I cannot get the tests in WsFederationInterfaceTests to exercise that code. They still pass.

I'm not sure what to do now. I am finishing my day, so I will sleep on it.

Cordially,
Jess

@616b2f
Copy link
Owner

616b2f commented Feb 9, 2022

@jesslilly if you could remove the "WebUtility.UrlDecode" and change the URL in the test. I would love to merge your PR.

@jesslilly
Copy link
Author

jesslilly commented Feb 9, 2022 via email

@616b2f
Copy link
Owner

616b2f commented Feb 9, 2022

@jesslilly me too so don't worry :)

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.

2 participants