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

Ensure redirect URLs are strings #798

Merged
merged 1 commit into from
Apr 1, 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
7 changes: 3 additions & 4 deletions app/utils/meta.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from pathlib import Path
from urllib.parse import unquote

import aiohttp
from aiocache import cached
from sanic.log import logger
from sanic.request import Request

from .. import settings
from . import http
from . import http, urls


def version() -> str:
Expand Down Expand Up @@ -79,7 +78,7 @@ async def custom_watermarks_allowed(request: Request) -> bool:
token = request.args.get("token")
if token:
logger.info(f"Authenticating with token: {token}")
_url, updated = await tokenize(request, request.url)
_url, updated = await tokenize(request, urls.clean(request.url))
return not updated

return False
Expand Down Expand Up @@ -121,7 +120,7 @@ async def track(request: Request, lines: list[str]):
return

async with aiohttp.ClientSession() as session:
params = dict(text=text, referer=referer, result=unquote(request.url))
params = dict(text=text, referer=referer, result=urls.clean(request.url))
logger.info(f"Tracking request: {params}")
headers = {"X-API-KEY": _get_api_key(request) or ""}
status, message = await http.fetch(api, params=params, headers=headers)
Expand Down
4 changes: 4 additions & 0 deletions app/utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ def clean(url: str) -> str:
while "/_." in url:
url = url.replace("/_.", ".")

# TODO: Fix Sanic bug?
# https://github.com/jacebrowning/memegen/issues/799
url = url.replace("::", ":")

return url
2 changes: 1 addition & 1 deletion app/views/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ async def detail_text(request, template_id, text_filepath):
)
return response.redirect(utils.urls.clean(url), status=301)

url, updated = await utils.meta.tokenize(request, request.url)
url, updated = await utils.meta.tokenize(request, utils.urls.clean(request.url))
if updated:
return response.redirect(url, status=302)

Expand Down