getmango / Mango

Mango is a self-hosted manga server and web reader
https://getmango.app
MIT License
1.69k stars 120 forks source link

[Bug Report] Tachiyomi extension ignores specified port #268

Closed NaruZosa closed 2 years ago

NaruZosa commented 2 years ago

Describe the bug Received an error in Tachiyomi stating credentials are incorrect, when they were correct. This occurs when trying to connect locally, but not when routed via cloudflare

To Reproduce Steps to reproduce the behavior:

  1. Create a docker container with Mango, with default port 9000
  2. In the Mango Tachiyomi extension, try to connect to this using the local address, e.g.:
  1. Restart Tachiyomi

Expected behavior Login is successful

Environment (please complete the following information):

Docker Default values, other than:

Additional context I then added Mango to my 'SWAG' to access it via a reverse proxy, using Cloudflare. When I changed to using this url (https://manga.domain.com), login succeeded. This was unusual, as I kept port 9000, when it should now be 443 due to the reverse proxy settings, as 9000 is not a valid port via the reverse proxy. I changed the Server Port Number in Mango to 1111, and it still succeeded. It appears the specified port is being ignored. Unintended consequence of https://github.com/tachiyomiorg/tachiyomi-extensions/pull/9019 perhaps?

NaruZosa commented 2 years ago

Extra info: It looks like it's only looking at port 80. As a different program (Unraid itself) is running on port 80, login fails.

I re-created the situation on another machine with the following:

docker-compose.yml:

---
version: "3.8"
services:
  Mango:
    image: hkalexling/mango
    container_name: Mango
    restart: unless-stopped
    ports:
      - 9000:9000

(Volume mappings not required)

When attempting to connect to this in Tachiyomi (Address http://192.168.1.69 Port 9000) it has an endless loading icon. When the port is changed to 80:9000 logging in is successful (shows no results, as it's an empty library) Changing the port in Tachiyomi, e.g. to 9001 makes no difference, it still looks at port 80.

Edit: Just set the port to the string "Irrelevant" and it still works, so the port setting is definitely being ignored.

hkalexling commented 2 years ago

Just a sanity check - without Swag, can you access http://192.168.1.151:9000 from your phone?

NaruZosa commented 2 years ago

I cannot. I only added 'SWAG' and CloudFlare routing after being unable to access it via the local address.

The 192.168.1.69 address doesn't have SWAG running at all, and experienced the same issue.

hkalexling commented 2 years ago

Hmm if you can't access it from your phone browser then surely Tachiyomi won't be able to connect either? Or am I missing something?

NaruZosa commented 2 years ago

Apologies, I didn't realise you meant from my phone browser.

It can be accessed from my phone browser. Additionally, when Tachiyomi fails to connect and shows the screen with "Login Failed. Check Address and Credentials" it has the options to 'Retry' or 'Open in WebView'. Open in WebView opens the specified address, but port 80.

In addition to this, if you enter an incorrect address (in this case http://192.168.1.150 as I have no such device), it says "Failed to connect to /[address]:80" regardless of what the specified port is.

image image

I forgot to mention earlier, I'm using TachiyomiJ2K, although I don't think this should affect things.

hkalexling commented 2 years ago

Ah I think I know what the issue was. In the address field you are supposed to put down the full address including the port number. Try http://192.168.1.150:9000 and it should work.

hkalexling commented 2 years ago

DeepinScreenshot_select-area_20220125184357

It is mentioned on the settings page of the extension.

NaruZosa commented 2 years ago

Ah, okay. Glad it was just user error.

If it takes the port from the address field, what does the Server Port Number field do?

hkalexling commented 2 years ago

Mango uses cookies and the cookies name contains the port number. We need it to identify the correct cookies to use.

We can't simply parse the address field and get the port number because some users might have a reverse proxy setup. In this case the port to access the service might not be the port that Mango is running on.

NaruZosa commented 2 years ago

Thank you for the clarification.

When I set the port to a different value to see if it made any difference, Tachiyomi still loaded the library successfully. What cookies are set with the port number, and what is the potential impact of having an incorrect port set?

hkalexling commented 2 years ago

The cookie is mango-sessid-{port number}, and it contains the internal session ID to identify an existing user session. If it's not set correctly the extension will have to re-authorize the user every time it calls an API endpoint. I didn't test this but if you inspect the log you should see a bunch of calls to POST {base url}/login, which can be avoided by correctly setting the port number.