From 8ce71bdd54378c88207aae657db0afa4e7ce37a3 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 21 Feb 2024 08:36:00 +1300 Subject: [PATCH] encode params correctly when doing webfinger --- app/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/utils.py b/app/utils.py index 490a2b45..9f60e946 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,6 +1,7 @@ from __future__ import annotations import random +import urllib from collections import defaultdict from datetime import datetime, timedelta, date from typing import List, Literal, Union @@ -71,8 +72,12 @@ def get_request(uri, params=None, headers=None) -> requests.Response: headers = {'User-Agent': 'PieFed/1.0'} else: headers.update({'User-Agent': 'PieFed/1.0'}) + if params and '/webfinger' in uri: + payload_str = urllib.parse.urlencode(params, safe=':@') + else: + payload_str = urllib.parse.urlencode(params) if params else None try: - response = requests.get(uri, params=params, headers=headers, timeout=5, allow_redirects=True) + response = requests.get(uri, params=payload_str, headers=headers, timeout=5, allow_redirects=True) except requests.exceptions.SSLError as invalid_cert: # Not our problem if the other end doesn't have proper SSL current_app.logger.info(f"{uri} {invalid_cert}")