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

Fixed exception when DangerousDisablePathAndQueryCanonicalization = true #3393

Merged
merged 3 commits into from
May 28, 2024

Conversation

jamescrosswell
Copy link
Collaborator

Resolves #3387

{
// This is a safe way to get the HttpRequestUrl, even when DisablePathAndQueryCanonicalization is true
// See https://github.com/getsentry/sentry-dotnet/issues/3387
return new UriBuilder(uri).Uri.GetComponents(UriComponents.HttpRequestUrl, UriFormat.Unescaped);
Copy link
Contributor

@bitsandfoxes bitsandfoxes May 27, 2024

Choose a reason for hiding this comment

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

I thought calling .GetComponents() is the reason for this issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, because it's wrapped in the UriBuilder.

Copy link
Contributor

@bitsandfoxes bitsandfoxes left a comment

Choose a reason for hiding this comment

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

There is no way to do this conditionally? So we don't always have to create a new builder object?

@jamescrosswell
Copy link
Collaborator Author

There is no way to do this conditionally? So we don't always have to create a new builder object?

Unfortunately not. The flags and properties indicating DangerousDisablePathAndQueryCanonicalization == true are all private or internal.

The only other option is a try/catch... which would be cheaper if/when this error does not occur but would be very expensive when this error does occur. We could do that - it would avoid allocation of a UriBuilder for most folks.

@bitsandfoxes bitsandfoxes merged commit 914c92d into main May 28, 2024
@bitsandfoxes bitsandfoxes deleted the dangerous-path branch May 28, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants