Skip to content

Commit 17610e2

Browse files
committed
fix: disable redirects when fetching feeds
1 parent 15c5e11 commit 17610e2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

backend/app/models/feed.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,16 @@ class UpstreamError(Exception):
157157

158158
async def parse_feed(feed_url: HttpUrl) -> Feed:
159159
"""Register a new feed."""
160+
if feed_url.host and re.match(
161+
r"^(25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b", feed_url.host
162+
):
163+
raise RuntimeError("Invalid URL")
160164
async with ClientSession() as aiohttp_session:
161165
try:
162166
async with aiohttp_session.get(
163-
str(feed_url), headers={"User-agent": "Mozilla/5.0"}
167+
str(feed_url),
168+
headers={"User-agent": "Mozilla/5.0"},
169+
allow_redirects=False,
164170
) as response:
165171
response.raise_for_status()
166172
feed_response = await response.text()

0 commit comments

Comments
 (0)