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

ValueError: Can redirect only to http or https #7801

Closed
sentry-for-tribler bot opened this issue Jan 5, 2024 · 6 comments · Fixed by #7810
Closed

ValueError: Can redirect only to http or https #7801

sentry-for-tribler bot opened this issue Jan 5, 2024 · 6 comments · Fixed by #7810

Comments

@sentry-for-tribler
Copy link

sentry-for-tribler bot commented Jan 5, 2024

Sentry Issue: TRIBLER-13Z

ValueError: Can redirect only to http or https
  File "tribler\core\components\restapi\rest\rest_manager.py", line 53, in error_middleware
  File "aiohttp\web_middlewares.py", line 117, in impl
  File "tribler\core\components\libtorrent\restapi\torrentinfo_endpoint.py", line 102, in get_torrent_info
  File "tribler\core\components\libtorrent\restapi\torrentinfo_endpoint.py", line 39, in query_http_uri
  File "aiohttp\client.py", line 624, in _request

Last Seen
3 days ago
in release 7.13.1

First Seen
10 months ago
in release 7.12.1

EVENTS
11

USERS
3

@qstokkink

This comment was marked as duplicate.

@drew2a
Copy link
Contributor

drew2a commented Jan 5, 2024

The following actions are performed:

  1. The user inputs http:https://tinyurl.com/<url>.
  2. This URL is resolved to a magnet link magnet:?xt=urn:sha1:....
  3. The magnet link causes a ValueError in query_http_uri.

@drew2a
Copy link
Contributor

drew2a commented Jan 10, 2024

@qstokkink, what do you think about the safety of allowing redirects in Tribler?

I can either:
a) Allow redirects.
b) Return a human-readable error stating that we do not support redirects.

@qstokkink
Copy link
Contributor

I consider the existence of this issue to be evidence that redirection is a feature that our users want. Based on that, my vote goes to a) allow redirects.

@drew2a
Copy link
Contributor

drew2a commented Jan 10, 2024

aiohttp supports redirection out-of-the-box, but it cannot work with schemes other than "http", "https", "".

The error occurred here:

https://github.com/aio-libs/aiohttp/blob/6529c77551e2a61d6d9df72653df92180d1fed7c/aiohttp/client.py#L609-L611

                        if scheme not in ("http", "https", ""):
                            resp.close()
                            raise ValueError("Can redirect only to http or https")

This is because, in our case, the scheme is magnet.

Refs:

@drew2a
Copy link
Contributor

drew2a commented Jan 11, 2024

I've implemented the desired feature, but it turns out that the magnet link shortened by TinyURL cannot be parsed by our parse_magnetlink. However, the same magnet link is successfully parsed by https://github.com/JohnDoee/magnet2torrent but the extracted hash can not be used with the BitTorrent as it seems to be incompatible (has urn:sha1 and urn:ed2khash but not urn:btih).

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

Successfully merging a pull request may close this issue.

2 participants