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

fix security concerns #377

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion catalog/common/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import django_rq
import requests
from validators import url as url_validate

from .models import ExternalResource, IdealIdTypes, IdType, Item, SiteName

Expand Down Expand Up @@ -283,7 +284,9 @@ def get_site_cls_by_id_type(typ: str) -> AbstractSite:

@staticmethod
def get_site_by_url(url: str) -> AbstractSite | None:
if not url:
if not url or not url_validate(
url, skip_ipv6_addr=True, skip_ipv4_addr=True, may_have_port=False
):
return None
cls = next(
filter(lambda p: p.validate_url(url), SiteManager.registry.values()), None
Expand Down
6 changes: 3 additions & 3 deletions catalog/sites/goodreads.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Goodreads(AbstractSite):
WIKI_PROPERTY_ID = "P2968"
DEFAULT_MODEL = Edition
URL_PATTERNS = [
r".+goodreads.com/.*book/show/(\d+)",
r".+goodreads.com/.*book/(\d+)",
r".+goodreads\.com/.*book/show/(\d+)",
r".+goodreads\.com/.*book/(\d+)",
]

@classmethod
Expand Down Expand Up @@ -125,7 +125,7 @@ class Goodreads_Work(AbstractSite):
ID_TYPE = IdType.Goodreads_Work
WIKI_PROPERTY_ID = ""
DEFAULT_MODEL = Work
URL_PATTERNS = [r".+goodreads.com/work/editions/(\d+)"]
URL_PATTERNS = [r".+goodreads\.com/work/editions/(\d+)"]

@classmethod
def id_to_url(cls, id_value):
Expand Down
2 changes: 1 addition & 1 deletion catalog/tv/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_miniseries(self):
@use_local_response
def test_tvspecial(self):
url1 = "https://www.themoviedb.org/movie/282758-doctor-who-the-runaway-bride"
url2 = "hhttps://www.imdb.com/title/tt0827573/"
url2 = "https://www.imdb.com/title/tt0827573/"
url3 = "https://movie.douban.com/subject/4296866/"
p1 = SiteManager.get_site_by_url(url1).get_resource_ready()
p2 = SiteManager.get_site_by_url(url2).get_resource_ready()
Expand Down
6 changes: 3 additions & 3 deletions journal/importers/goodreads.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from catalog.models import *
from journal.models import *

re_list = r"^https://www.goodreads.com/list/show/\d+"
re_shelf = r"^https://www.goodreads.com/review/list/\d+[^?]*\?shelf=[^&]+"
re_profile = r"^https://www.goodreads.com/user/show/(\d+)"
re_list = r"^https://www\.goodreads\.com/list/show/\d+"
re_shelf = r"^https://www\.goodreads\.com/review/list/\d+[^?]*\?shelf=[^&]+"
re_profile = r"^https://www\.goodreads\.com/user/show/(\d+)"
gr_rating = {
"did not like it": 2,
"it was ok": 4,
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ setproctitle
tqdm
typesense
urlman
validators