ChangemakerStudios / Papercut-SMTP

Papercut SMTP -- The Simple Desktop Email Server
2.84k stars 267 forks source link

Clicking on a link creates 2 requests #234

Open orjandh opened 1 year ago

orjandh commented 1 year ago

Describe the bug Clicking on a html anchor link in the "Message" view of a message sends 2 requests to the server.

To Reproduce Steps to reproduce the behavior:

  1. Set up a HTTP server or use https://webhook.site/ to inspect incoming requests.
  2. Receive a message with the following text: <a href="{{link}}">{{link}}</a>
  3. Open the message in the "Message" viewer.
  4. Click the anchor to open link.
  5. Verify on server that 2 requests was sent.

Expected behavior I expect there to only be 1 request when clicking a link.

Desktop (please complete the following information):

Additional context Maybe the issue is that the request is already sent when the NavigationStarting event is fired, so cancelling this event only has effects on the UI. https://github.com/ChangemakerStudios/Papercut-SMTP/blob/a1727a60f9b6fe274bc2178b1dc5f2a76aa35276/src/Papercut.UI/ViewModels/MessageDetailHtmlViewModel.cs#L193

As a side note, this does not happen if opening the link by pressing ctrl and clicking the link on the "Raw" or "Body" views in PaperCut.

Jaben commented 1 year ago

I can't reproduce... Can you provide a screen shot of where you're seeing the multiple requests "on the server"?

Thanks.

orjandh commented 1 year ago

I have updated the issue with more detailed instructions. This is an screenshot from the webhook.site service. (I discovered the problem using my own server, but using a third party now to verify). Also notice the same timestamp.

screenshot

RickKukiela commented 1 year ago

So this "bug" just cost me like 3 hours of dev time on a project because it was messing with my requests. The phantom first link was executing the action and then the 2nd real request would fail (rightfully) because the first "phantom" request already did the action the link that was "emailed" to me was supposed to do.

The trick to the bug and why some may not be able to reproduce it, it seems is a default browser configuration issue. If you use EDGE as your default browser, then it's likely that you cannot reproduce this bug.

My default browser is Chrome. When I click a link that was "emailed" to my papercut receptacle, I see two requests almost simulaniously on my server with two different user agents:

The first (phantom) request I get: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.42

The 2nd request which I see open in my chrome: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36

It seems like somehow papercut is trying to open the request in Edge, but my system knows chrome is my default browser so then it passes the "Job" to open the link to chrome, but never stops the Edge api from making the web request. It never actually creates an Edge window though, so you would never know this request was happening unless its messing with the secondary request being fulfilled by chrome by performing the action first breaking the action attempt for the chrome request.

I was only able to finally figure this out by putting a request logger directly in my app entry point...

At least I'm aware of this so I wont waste more time on this but this is a real gnarly bug.